-2

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.

4
  • In which programming language?
    – CoderMike
    Commented Jun 25, 2023 at 17:20
  • i'm new and don't understand much but i think in python.
    – newguy
    Commented 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.
    – Milliways
    Commented Jun 25, 2023 at 23:00
  • if what you want to do is simple enough, use a shell script simonprickett.dev/… Commented Jun 26, 2023 at 4:32

1 Answer 1

0

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)

https://pinout.xyz/pinout/pin16_gpio23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.