During the Hackster Hardware Weekend I had the chance to test the Intel Edison board and was pretty amazed by its form factor and speed.
Intel has made sure to include Arduino compatibility in its Edison and Galileo boards, and while I think it's a nice alternative to have, I feel that adding that additional layer to a project makes it harder to program and may use more resources.
So I looked for ways to access the GPIO pins directly from the Linux environment, without the Arduino overhead, and luckily I found the MRAA library. It makes it SO easy to interface with the Edison pins from the comfort of a Python script (and there's also a Javascript binding).
In this tutorial we'll use the MRAA Library to log sensor data and stream it to the Ubidots cloud service.
Connect the two usb cables from your computer to the Edison board (one for power, one for serial data). In OSX, open a serial connection to the board from your terminal:
screen /dev/tty.usbserial-AJ035OK6 115200 -L
The default Edison login is root. Once you're in, configure the wifi network:
configure_edison --wifi
Select your Wi-Fi network and connect to it.
2. Installing the required librariesLet's add a sources list to be able to download packages from the Edison. Open this file:
root@edison:~# vi /etc/opkg/base-feeds.conf
And add these lines to it (type "i" to be able to insert text in the vi editor):
src/gz all
http://repo.opkg.net/edison/
repo/allsrc/gz edison
http://repo.opkg.net/edison/
repo/edisonsrc/gz core2-32
http://repo.opkg.net/edison/
repo/core2-32
Then update the sources and install the required libraries for our project:
root@edison:~# opkg update
root@edison:~# opkg install libmraa0 nano
root@edison:~# opkg install python-pip
root@edison:~# curl
root@edison:~# pip install ubidots
Done! now we're ready to code.
3. The Python codeThe following code will (1) connect to Ubidots (creating an “api” object), (2) link two analog inputs to the MRAA library, and (3) send the values to your Ubidots variables using the “save_collection” function:
Connect to Ubidots:
#!/usr/bin/python
import time, mraa
from ubidots import ApiClient
#Connect to Ubidots
for i in range(0,5):
try:
print "Requesting Ubidots token"
api = ApiClient('YOUR-UBIDOTS-API-KEY-HERE')
break
except:
print "No internet connection, retrying..."
time.sleep(5)
Link the analog pins to the MRAA library:
a0 = mraa.Aio(0)
a1 = mraa.Aio(1)
Send data to Ubidots inside an infinite loop:
while(1):
api.save_collection([{'variable': '558073727625425555af27e4','value':a0.read()}, {'variable': '5580737876254257514be1e6','value':a1.read()}])
4. ResultsAfter getting your data in the cloud, you can create SMS/Email alerts, Webhooks, or a neat live dashboard like this:
Comments