BeagleBone/I2CLCDDemo

= I2C LCD Demo with Onewire Temperature Sensor =



Introduction
I created this tutorial to show how to use inexpensive components (commonly used arduino components) with the BeagleBone Black. The cost of this project can easily be under $20 USD shipping and all.

If you have come from tinkering with Arduino boards you need to understand that the BBB is much more sensitive than what you are used to. It can't handle the voltages or amounts of current. For this demo we'll be using a logic converter to allow the BBB to communicate with a 5V device over I2C.

For the software side I'm using python.

Hardware

 * 8 Channel Logic Converter $4.95 each and free shipping.
 * IIC I2C LCD Module $3.20 each and cheap shipping.
 * Sturdy 4 Line LCD $6.90 each and cheap shipping.
 * (Optional) Waterproof Temperature Sensor $2 and free shipping. Also uses a 4.7k resistor (there is some wiggle room here).

Logic Converter Wiring
For the logic converter you need to
 * 1) Run a wire from a 3.3v pin to the VCC on the low side of the logic converter.
 * 2) Run a wire from a 5v pin to the VCC on the high side of the logic converter.
 * 3) Run a wire from a ground pin to the ground of one side and a jump a wire from the ground of one side to the ground on the other side.

I2C LCD wiring
For the LCD module you need to
 * 1) Wire the I2C module into 5V and Ground with the high side of the logic converter
 * 2) Plug SCL and SDA from the I2C module into the first two pins on the logic converter on the high side (for example H0 and H1)
 * 3) On the other side of the logic converter run wires to the BBB to pins 19(SCL) and 20(SDA)

Temp sensor wiring
For the temperature sensor you need to
 * 1) Run a jumper wire from the 3.3v from the VCC low side of the logic converter to the sensor's VCC wire
 * 2) Run a jumper wire from ground to the sensor ground wire
 * 3) Put a 4.7k resistor from the 3.3V VCC to the data wire
 * 4) From the data wire, run a wire to the BBB at P9_22

Software
For the 1-Wire temperature sensor, you can follow this tutorial to get the device recognized by the system. For the purposes of this tutorial the address I will be using is "/sys/bus/w1/devices/28-000004d43557/w1_slave"  yours will be different. To get your 1-wire device address you should be able to.

You can setup python for working with I2C by following the guide from Adafruit. The main priority is having smbus working. You need to have i2c tools installed to figure out what address the I2C LCD module is at. Mine is on bus 1, at address 0x20.

The particular I2C module I listed in the hardware section had a peculiar wiring that didn't easily work with any I2C LCD libraries. For one the backlight pin toggles the opposite of the PyLCD library. I was able to find the pinout by digging through tons of sites, and finally found a comment on dx.com for a different module which mostly worked, and then found an unpopular Arduino sketch that worked with it, and got it all sorted out from there.

Below is the actual code to make this app run. You'll have to at the very least modify the w1 device address. The first "os path exists" checks to see if the device is loaded, and if not, loads it up and give enough time before continuing. To run the application run "python weather.py".

weather.py

Here is the library. Besides the modified pins from the original source at github, I added  to turn the backlight off during sleeping hours. It was the easiest place to hack it in, as I didn't want to spend a lot of time on that.

pylcd.py