gpio_led_control
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| gpio_led_control [2016/08/09 17:22] – walkeradmin | gpio_led_control [2017/10/22 15:40] (current) – walkeradmin | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | **Please be aware, the GPIO pins are 3.3v Logic, and are restricted to 16mA** | + | **Please be aware, the GPIO pins are 3.3v Logic, and are restricted to 16mA - exceeding 16 mA will damage your Pi** |
| \\ | \\ | ||
| \\ | \\ | ||
| Line 29: | Line 29: | ||
| \\ | \\ | ||
| sudo nano LED.py (starts the nano editor with a new file called LED.py) | sudo nano LED.py (starts the nano editor with a new file called LED.py) | ||
| + | \\ | ||
| + | Now enter this code: (you can copy and paste by the way) | ||
| + | \\ | ||
| + | #import modules | ||
| + | import RPi.GPIO as GPIO # This imports the GPIO libarary that allows the use of the GPIO pins, | ||
| + | import time # This imports the time libarary (for delays among other things) | ||
| + | # These libraries are built in to Raspbian. | ||
| + | | ||
| + | | ||
| + | GPIO.setmode (GPIO.BOARD) | ||
| + | # so we can reference it by using BOARD as pin 12. However there is | ||
| + | # another option (BCM) where we can reference a pin by it's name, pin | ||
| + | # 12 is called GPIO18 (a reference to its place on the chip). | ||
| + | | ||
| + | GPIO.setup(12, | ||
| + | # read in a voltage (but only in terms of a 0 or a 1)) | ||
| + | | ||
| + | GPIO.output(12, | ||
| + | | ||
| + | time.sleep(1) | ||
| + | | ||
| + | GPIO.output(12, | ||
| + | | ||
| + | time.sleep(3) | ||
| + | | ||
| + | GPIO.cleanup() | ||
| + | \\ | ||
| + | \\ | ||
| + | Because we are accessing the GPIO, we need to run our Python program as the sudo user: | ||
| + | \\ | ||
| + | sudo python LED.py | ||
| + | \\ | ||
| + | The LED should come on for 3 seconds, then go off. The program will then end. | ||
| + | \\ | ||
| + | \\ | ||
| + | You can see it in operation Here: {{: | ||
| + | \\ | ||
| + | **Remember: | ||
| + | |||
| + | Pins are 3.3v | ||
| + | \\ | ||
| + | 16mA MAX | ||
| + | \\ | ||
| + | \\ | ||
| + | This guide is comprised of information from a youtube video by **Gaven MacDonald**. Thanks Gaven. | ||
| + | \\ | ||
| \\ | \\ | ||
gpio_led_control.1470763350.txt.gz · Last modified: (external edit)
