One of the first projects I did when I got the BeagleBone was to continuously read the temperature outside our house. This is a small part of a much bigger project but maybe of interest to others coming to this platform.
To sense the temperature I am using a sensor device from CISECO. This comes in two flavours and I chose the wrong one. The DALLAS version uses a lot more power and therefore needs a much larger battery whereas the “thermistor” version will run for a decent length of time on a coin cell. Into this I placed one of their XRFs, essentially a low-cost substitute for an Xbee. (This needs a little setup but can also be purchased ready programmed for the temperature sensor.)
At the other end I needed another XRF wired up to my BeagleBone. Given that I was in prototyping mode I used the ‘Bone’s proto-cape (cape == shield in ‘Bone parlance). This connects the XRF, in an Xbee-to-breadboard adapter to UART1 on the ‘Bone.
As the XRFs are based on 866Mhz radios I am confident about the range (though I have yet to be fully verify this).
Now for some code. I wanted to do this in node.js which is supported out of the box on ‘Bone. Well almost. There’s also an IDE called Cloud9 which is very handed but runs on an older node.js version not compatible with node module “serialPort”. I did not want to destroy this with a node.js upgrade, particularly as I did not have a spare uSD card to play with. So I did this in python, another well-supported language on the ‘Bone.
Thanks to quasiben’s blog it was easy to find out how to set up the bone with reading the enormous manual cover to cover. This what I ended up with:
import serial, os import sys import time ## for beaglebone serial IO uart1_pin_mux = [ ('uart1_rxd', ( 0 | (1<<5) )), # Bit 5 enables receiver on RX Pin ('uart1_txd', ( 0 )), # No bits need be set for TX Pin ] for (fname, mode) in uart1_pin_mux: with open(os.path.join('/sys/kernel/debug/omap_mux', fname), 'wb') as f: f.write("%X" % mode) ser=serial.Serial('/dev/ttyO1', 9600, timeout=1) ## temperature data i = 0 while i < 12: # or True once tested c = ser.read() while c != 'a': c = ser.read() s=ser.read(11) # a--TEMPdd.dd t=s[2:6] if t == "TEMP": # ignore anything except temperature print s[6:] i+=1 if i >= 6: time.sleep(3) ser.write("a--TEMP------");
This just prints the temperature every 3 seconds. Note that this is far from a complete implementation as it does not set the device ID nor tell it how often to send the reading. The definition of the LLAP protocol used by the XRF firmware is at openmicros.org.
Watch this space for a version combined with other sensors and actuators, probably node.js based. Alternatively, some other way to making this asynchronous would be needed.