With embedded widgets blinking an LED is the equivalent of "Hello World". I could not find an example of using python to blink an LED here so I thought I would share this. Hopefully this will save someone some time when they want to blink an LED using MRAA and Python. I have only used/tested this with the Galileo Gen 2 built with the EGLIBC image: http://downloadmirror.intel.com/25384/eng/iot-devkit-201510010757-mmcblkp0-galileo.direct.xz http://downloadmirror.intel.com/25384/eng/iot-devkit-201510010757-mmcblkp0-galileo.direct.xz.
0 . First is to install mraa
opkg update
opkg install mraa
1. Next you open python and import MRAA.
import mraa
2. Then initialize the pin, in this example I am using digital pin 12.
pin = mraa.Gpio(12)
3. Next set the pin to output mode.
pin.dir(MRAA.DIR_OUT)
4. And then set it high or low to turn it on or off.
pin.write(0)
All together in one script using digital pin 12 and blinking on/off ever second.
# !/usr/bin/env python
import mraa
import time
pin = mraa.Gpio(12)
pin.dir(MRAA.DIR_OUT)
while True:
pin.write(1)
time.sleep(1)
pin.write(0)
time.sleep(1)
It is just that easy!
You can download a script here that does it all for you : https://github.com/joemcmanus/led GitHub - joemcmanus/led: Intel Galileo LED python script
Use:
root@galileo:~# ./led.py 1
Blinking LED 1
Using delay 10 and for 0 attempts
Turning LED 1 on, for 10 seconds, count 0.
root@galileo:~ ./led.py --help
usage: led.py [-h] [--count COUNT] [--delay DELAY] [--version] pinNumber
Simple LED Blinker for Galileo
positional arguments:
pinNumber Specify the pin number, i.e. 0-13
optional arguments:
-h, --help show this help message and exit
--count COUNT Number of times to execute, default infinity
--delay DELAY Number of seconds to wait between blinkings, default 10
--version show program's version number and exit
Cheers,
-Joe
Link Copied
For more complete information about compiler optimizations, see our Optimization Notice.