-2

I want to control a gpio pin on the pi (4B 8Gb ram) with gpiozero. I can't find how to simply control a pin... without the library thinking that it is a LED. Coming from Arduino, there you can just use digitalWrite, does this library have anything similar to this? In the documentation I was able to find this: https://gpiozero.readthedocs.io/en/stable/api_output.html#digitaloutputdevice But can't get it to work...

Stil not sure which library is the best... (rpi.gpio doesn't support I2C or SPI so not using that) But for now I just want to control a pin but rather not like this:

from gpiozero import LED
pin = LED(5)
pin.on()

Thanks

Edit:

I did this for multiple pins.

import gpiozero
DigitalOutputDevice(5, True)

gpiozero is correctly installed (tested it with a led) and I had no errors wtih this lines...

IDV
  • 1
  • 3
  • Are you getting any errors? If not maybe you are giving wrong gpio number? I recommend [this](https://pinout.xyz/) website for checking it. – loloToster May 13 '21 at 11:13
  • `DigitalOutputDevice` is the correct class to use. Perhaps you should show us what you did and why it didn't work. – Kemp May 13 '21 at 11:18
  • idk if it would affect this code but in the background i am running another script... but i added an & at the end of the command so that it would be in the background (I don't know if i am saying it correctly, am new to the PI) – IDV May 13 '21 at 11:32

1 Answers1

0

You can start with a very simple snippet like this.

import RPi.GPIO as GPIO
import time

led_pin = 12
led_interval = 5
GPIO.setwarnings(False) 
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_pin, GPIO.OUT, initial=GPIO.LOW) 

GPIO.output(led_pin, GPIO.HIGH)
time.sleep(led_interval)       
GPIO.output(led_pin, GPIO.LOW)
rok
  • 2,574
  • 3
  • 23
  • 44