This is a project Iāve been working on for a while, and still have ways to go, but I have enough success right now that I can I share what Iāve got. This covers connecting a Beaglebone and an Arduino via TTL serial and I2C, using a parallel LCD with an Arduino, using a DHT-22 with Arduino, and using DS18B20 1-wire sensors with a BeagleBone in the next week or so.
I believe that all the instructions here will apply more or less as-is to a RaspberryPI or pcDuino or any other little computer that supports TTL serial and i2c, and 1-wire for the DS18B20. As I get some ArchReactor (the local hackerspace) members to try this on their devices, Iāll update here confirming what devices work and add any relevant information.
My end-goal is to use several temperature, humidity, and other sensors spread through my house, including outside, and control my heat and AC and whole house fan in order to optimize and balance comfort and energy use. The details of how that will work are yet to be nailed down, and Iām going to start with monitoring so I can see what kind of data I have to work with.
This instructable will explain how to get started with using an Arduino and Beaglebone and a couple sensors and a display.
Stuff youāll need:
ā BeagleBone
ā Ardunio
ā TFT LCD
ā Sensors
ā lots of jumper wires!
Iāve had a BeagleBone for a while, but a Black should work the same. For the Arduino you can prototype with an Uno or other standard arduino compatible, but Iām using a breadboard arduino, and Iāll eventually make a PCB for it, so that I can integrate it into as small a case as possible. For the LCD, Iāve chosen an 2.8ā³ TFT with touch screen. There are certainly easier to use LCDs out there, but this one is only $18, and I have enough IOās to make this run in 8-bit mode. Iām starting with the DHT-22 temp and humidity sensor, and Iāll be adding DS18B20 temp sensors soon.
Iāve made a SparkFun wishlist for the breadboard Arduino parts and the sensors.
Another goal of mine was to be able to update the Arduinoās program from the BeagleBoneās TTL serial. Iāve detailed that in this instructable, and the serial parts here will be based on that. After I got the LCD working I realized that it requires use of D0 and D1 (the serial port) and so to communicate with the Beaglebone I had to use something different. I decided to learn something new and use I2C.
Step 1: Wire the BB and Arduino together
Weāll start by getting the BeagleBone to talk to the Arduino. I recommend reading my instructable for getting them wired up and running the test code. Iāll do a quick overview here, refer the image with the chart for pin numbers:
Wire the bare bones Arduino, minus the FTDI.
wire BeagleBone Serial2 to the level shifter.
wire Ardunio serial to the level shifter, RX and TX crossed.
wire BeagleBone and Arduino i2c together. Level shifter is not needed, the BeagleBoneās pullupās are strong enough to handle the low current.
wire BeagleBoneās P9 23 to Arduino Reset
Wire 5V supply on one power rail, and 3.3V on the other.
Wire the grounds together.
Iāve included a new Fritzing to show the I2C lines. Unfortunately I did not save a simple set of i2c test programs. If anyone has trouble getting this to work I can make one.
Step 2: Wire up the LCD and DHT-22
The ITDB02 LCD supports 16bit and 8bit display modes. 8bit mode is done by using only 8 of the data wires and jumping the others to ground. Since Iām really only displaying text and some basic graphics, Iām using 8 bit mode to free up the IO pins for other uses.
Iām using the UTFT library to drive the LCD. Their requirements pdf has a chart showing the pin mapping for the Arduino. I found the pin labels on the LCD hard to read after a few wires were connected and referring to the image and chart on the product page was a big help.
Since the LCDās pin header is not breadboard friendly, I used some female<->female jumpers on it with some normal male<->male jumpers to get it all hooked up. This is a ton of wires, so just take your time and double check it all.
The DHT22 works on 1wire protocol, but itās not Dallas 1-wire compatible. Adafruit has a great tutorial on connecting and using the DHT-22, I recommend following her guide.
Step 3: Programming
The UTFT library turned out to be quite easy to use, and I also found an easy to use library for the DHT-22. Even with these nice libraries, there were some challenges.
The Arduino as a i2c slave seems to only behave if you limit your use to single-byte operations, and this makes sending flexible complex structures difficult. I want to be able to send screen drawing commands from the BeagleBone to the Arduino. My options were to code a system where a byte is sent as a ācommand typeā then branch to read more bytes to complete the structure, or work out a way to encapsulate a delimited string and process it. Method 1 would mean I canāt have optional parameters, and if the byte sending gets out of sync it will be difficult to re-sync. So I used method 2 by using some buffer variables and sending a 0-byte as a null terminator, like C uses for strings. Even if a byte gets dropped, the 0-byte will end the structure at some point and then itās just a matter of dealing with weird data when I parse.The next challenge was that the DHT22 is slow. like, really really slow. Solved that using a ācurrent valueā variable and a delay. I donāt need super fast response when the values change, but I want it to respond quick when I ask for the values. The main loop polls a function every time, that function then checks when the value was last updated, and updates it if itās been more than 3 seconds. Iāll probably end up converting this to a timer of some sort.I also programmed in a ādev modeā so I can disconnect the LCD and get some information on serial. Itās been handy so far, but now that the basics are worked out I probably wonāt use it again.On the Beaglebone, Iām using PyBBIO right now. itās arduino like commands and methods keep me from getting super confused when dealing with such different languages as C and Python are. Itās pretty easy to install, and has a few nice classes build in. It is my intention to try and get some sort of i2c class into it, if Haim doesnāt first!Youāll find a zip file attached with my code, an ino file for the arduino, and a python file for the beaglebone. Currently thereās only support for the DHT22 temp and humidity readings. It updates the display on the arduino even if the python script isnāt running. The python script simply gets the values and prints them to the terminal. Like I said at the start, I still have a lot of work to do!