User Tools

Site Tools


gpio_led_control

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
gpio_led_control [2016/08/09 18:16] walkeradmingpio_led_control [2023/03/09 22:35] (current) – external edit 127.0.0.1
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 23: Line 23:
 \\  \\ 
 \\  \\ 
-If you are using your Raspberry Pi via SSH or a Remote Desktop session, you need to enable remote access of the GPIO Pins, to do this from the command line, do the following:+If you are using your Raspberry Pi via SSH or a Remote Desktop session, you need to enable remote access of the GPIO Pins, instructions for this are [[enable_remote_access_to_gpio_pins|here]]:
 \\  \\ 
- 
-    sudo raspi-config 
 \\  \\ 
-    ┌──────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├───────────────────┐ +Once you have connected the circuit, we can create the Python programme, in this example we will be doing it from the command line using the editor nano: 
-    │                                                                                                │ +\\  
-    │    1 Expand Filesystem                       Ensures that all of the SD card storage is        │ +    sudo nano LED.py (starts the nano editor with a new file called LED.py) 
-    │    2 Change User Password                    Change password for the default user (pi        │ +\\  
-    │    3 Boot Options                            Choose whether to boot into a desktop envi        │ +Now enter this code: (you can copy and paste by the way
-    │    4 Wait for Network at Boot                Choose whether to wait for network connect        │ +\\  
-    │    5 Internationalisation Options            Set up language and regional settings to m        │ +    #import modules 
-    │    6 Enable Camera                           Enable this Pi to work with the Raspberry         │ +    import RPi.GPIO as GPIO    # This imports the GPIO libarary that allows the use of the GPIO pins, 
-    │    7 Add to Rastrack                         Add this Pi to the online Raspberry Pi Map        │ +    import time                # This imports the time libarary (for delays among other things) 
-    │    8 Overclock                               Configure overclocking for your Pi                │ +                               # These libraries are built in to Raspbian.
-    │    9 Advanced Options                        Configure advanced settings                       │ +
-    │    0 About raspi-config                      Information about this configuration tool         │ +
-    │                                                                                                │ +
-    │                                                                                                │ +
-    │                           <Select>                           <Finish>                          │ +
-    │                                                                                                │ +
-    └────────────────────────────────────────────────────────────────────────────────────────────────┘+
          
-    Advanced Options: 
          
-    ┌──────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config├───────────────────┐ +    GPIO.setmode (GPIO.BOARD # This sets the GPIO pin numbering. Our LED is connected to Pin 12, 
-    │                                                                                                │ +                               # so we can reference it by using BOARD as pin 12. However there is 
-    │    A1 Overscan                               You may need to configure overscan if blac  ↑     │ +                               # another option (BCM) where we can reference a pin by it'name, pin 
-    │    A2 Hostname                               Set the visible name for this Pi on netw  ▮     │ +                               # 12 is called GPIO18 (reference to its place on the chip). 
-    │    A3 Memory Split                           Change the amount of memory made available  ▒     │ +     
-    │    A4 SSH                                    Enable/Disable remote command line access   ▒     │ +    GPIO.setup(12, GPIO.OUT)   # Sets the GPIO pin as output. (as opposed to input, which would 
-    │    A5 SPI                                    Enable/Disable automatic loading of SPI ke  ▒     │ +                               # read in a voltage (but only in terms of a 0 or a 1)) 
-    │    A6 I2C                                    Enable/Disable automatic loading of I2C ke  ▒     │ +     
-    │    A7 Serial                                 Enable/Disable shell and kernel messages o  ▒     │ +    GPIO.output(12, 0)         # sets the GPIO Pin 12 to low (so 0v) 
-    │    A8 Audio                                  Force audio out through HDMI or 3.5mm jack  ▒     │ +     
-    │    A9 1-Wire                                 Enable/Disable one-wire interface           ▒     │ +    time.sleep(1)              # waits one second (settling time) 
-    │    AA GPIO Server                            Enable/Disable remote access to GPIO pins   ↓     │ +     
-    │                                                                                                │ +    GPIO.output(12, 1)         # sets the GPIO Pin 12 to high (so 3.3v) LED will turn on 
-    │                                                                                                │ +     
-    │                           <Select>                           <Back>                            │ +    time.sleep(3)              # waits 3 seconds, so LED will be on for 3 seconds 
-    │                                                                                                │ +     
-    └────────────────────────────────────────────────────────────────────────────────────────────────┘+    GPIO.cleanup()             # Resets all the GPIO pins to their default state (LED will go off) 
 +\\  
 +\\  
 +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: {{:led_video.mp4|950x574|autoplay,loop}} 
 +\\  
 +**Remember:**
  
-    Select GPIO Server +Pins are 3.3v
- +
-                       ┌──────────────────────────────────────────────────────────┐ +
-                       │                                                          │ +
-                       │ Would you like the GPIO server to be accessible over the │ +
-                       │ network?                                                 │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │                                                          │ +
-                       │               <Yes>                  <No>                │ +
-                       │                                                          │ +
-                       └──────────────────────────────────────────────────────────┘ +
- +
-    You will get a confirmation that the GPIO Server is available. +
- +
-    ┌──────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├───────────────────┐ +
-    │                                                                                                │ +
-    │    1 Expand Filesystem                       Ensures that all of the SD card storage is        │ +
-    │    2 Change User Password                    Change password for the default user (pi)         │ +
-    │    Boot Options                            Choose whether to boot into a desktop envi        │ +
-    │    4 Wait for Network at Boot                Choose whether to wait for network connect        │ +
-    │    5 Internationalisation Options            Set up language and regional settings to m        │ +
-    │    6 Enable Camera                           Enable this Pi to work with the Raspberry         │ +
-    │    7 Add to Rastrack                         Add this Pi to the online Raspberry Pi Map        │ +
-    │    8 Overclock                               Configure overclocking for your Pi                │ +
-    │    9 Advanced Options                        Configure advanced settings                       │ +
-    │    0 About raspi-config                      Information about this configuration tool         │ +
-    │                                                                                                │ +
-    │                                                                                                │ +
-    │                           <Select>                           <Finish>                          │ +
-    │                                                                                                │ +
-    └────────────────────────────────────────────────────────────────────────────────────────────────┘ +
- +
-    Now Select Finish - You will be back at the command prompt (you may need to reboot)+
 \\  \\ 
 +16mA MAX
 \\  \\ 
 +\\ 
 +This guide is comprised of information from a youtube video by **Gaven MacDonald**. Thanks Gaven.
 +\\ 
 +\\ 
 +
gpio_led_control.1470762998.txt.gz · Last modified: 2023/03/09 22:35 (external edit)