To control the Raspberry Pi's GPIO pins from Python, you will first need to install the RPi.GPIO library. You can do this by opening a terminal and running the following command:
main.py26 chars2 lines
Once you have the library installed, you can start using it in your Python programs. Here's an example program that blinks an LED connected to GPIO pin 17:
main.py195 chars12 lines
This code sets up pin 17 as an output pin, then enters an infinite loop that turns the pin on for one second and off for one second, creating a blinking effect.
Note that you will need to run this program with superuser privileges (i.e. using sudo python yourprogram.py
). Also, make sure to properly connect any external components to the GPIO pins to avoid damaging your Raspberry Pi.
gistlibby LogSnag