How to control a GPIO pin on the raspberry pi (general use) (python script)

451 views Asked by At

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...

1

There are 1 answers

1
rok On

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)