Is there someone that knows how to simply turn on or off a gpio pin? I don't understand why rpi have to make it so hard. I hope someone gives me an answer, ask me if you don't understand the question. I have tried for a long time to find info online and ended up on this page.
-
In which programming language?– CoderMikeCommented Jun 25, 2023 at 17:20
-
i'm new and don't understand much but i think in python.– newguyCommented Jun 25, 2023 at 17:25
-
There are about 20 different ways in multiple languages. Try some research. Start at raspberrypi.com which has extensive documentation or read MagPi.– MilliwaysCommented Jun 25, 2023 at 23:00
-
if what you want to do is simple enough, use a shell script simonprickett.dev/…– Jaromanda XCommented Jun 26, 2023 at 4:32
Add a comment
|
1 Answer
Here is an example of turning GPIO pin 23 on/off using the RPi.GPIO library:
import RPi.GPIO as GPIO
import time
gpioPin = 23
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(gpioPin, GPIO.OUT)
while True:
print('on')
GPIO.output(gpioPin, GPIO.HIGH)
time.sleep(1)
print('off')
GPIO.output(gpioPin, GPIO.LOW)
time.sleep(1)