An example to turn an LED on/off using iGPIO
At the end of this example, you will be able to turn an LED on/off on a remote device from a browser using the iGPIO website interface.
Parts needed in the example:
- Raspberry Pi Model B (with Internet access, either wired or wireless)
- an LED and a 330 ohms resistor
- Jumper Wire, Breadboard
Also needed is a PC or smartphone to access iGPIO website.
Follow these steps to setup the LED controller:
(1) Register for a free account at iGPIO
Click here to visit the iGPIO registration page
You will need to have an email address and to select a password to
register for an account. After registration, you will have an account
with user ID, i.e., your email address, and password.
(2) Setup device general parameters at iGPIO
After registration at the iGPIO
website, click this link.
This will bring you to the sign in page; sign in using your account email
and password, then click on the Device Manager button. Set the following
- Name: LED switch
- Update Interval: no change (default value is 300 seconds between two
updates from a device, e.g., Raspberry Pi)
- Mail Interval: no change (default value is 3600 seconds (one hour) between
two system email notifications)
- D Mail Interval: no change (default value is 3600 seconds between two
device email notifications)
- Alert Delay: 600 (wait this time in seconds before the iGPIO system sends an email
warning to user if device has not accessed the iGPIO website at the expected
Update Interval setting)
Check the Enable box and then click on the 'Update' button. This will upload the revised Table data to the iGPIO website.
(3) Setup device detail parameters at iGPIO
After completing the device parameters setup, click on 'Open #1' link
to bring up the detail parameters page for device #1. In this example, we
use CH 1. Set parameters as following:
- Label: LED (This channel is an LED switch)
- Value: 1 (turn on, i.e., Value = 1, the remote LED, or 0 to turn it off)
- Value1: 0 (not used in this example)
- Value2: 0 ((not used in this example)
- Flag: 2 (browser controls this channel, i.e., only the browser is allowed to modify this parameter)
Check the Enable box (a channel must be enable before use) and then click on the 'Update' button to complete the setting, i.e., to upload this table data to the iGPIO website. This setting will allow the device to read the Value. If Value =1, the device is directed to turn the LED on; if it is 0, it is directed to turn the LED off.
(4) Build the LED switch
This link will tell you all steps to build the LED controller/switch:
From now on, it is assumed you have connected your LED on the GPIO 23, i.e., pin 16 on the Raspberry Pi. To test if the setup on the Raspberry Pi is correct, put the following python code in a file, e.g., /home/pi/led_blink.py:
import RPi.GPIO as GPIO
led1 = 23
Then enter the following command and press the enter key:
sudo python led_blink.py
If everything is working correctly, the LED should blink (on for 5s then off) and you can continue with the following steps.
(5) Run a sample python code on Raspberry Pi
Connect Raspberry Pi to the Internet either wired (using an ethernet cable to a router) or wireless (using a USB WiFi adapter a router, http://www.raspberrypi.org/documentation/configuration/wireless/). Download the sample code from this link. Edit the top 2 lines, viz., use your
account name (email address) and password, and save it to /home/pi. For more information, please read Specification of device user interface. Use
this command to run the sample python program:
sudo python led_siwtch.py
Please note, since the update interval is 300 (s), after running the
code once, you will need to wait 300 s before running it again. Therefore,
it is recommended to run the code in crontab (an operating system
scheduler). To do this, use the command
and add a line at the end of crontab
*/5 * * * * sudo /usr/bin/python /home/pi/led_switch.py
Save and exit crontab. With this setting, the device will read the CH 1 value at the iGPIO website every 5 minutes (300s), and it will turn the LED on and off according to the CH 1 Value. A user can turn the LED on and off by setting the CH 1 Value (1 for on and 0 for off) from anywhere in the world with a PC, tablet or smartphone that has a browser and web access.