Topic: Adding an I2C device to a Chumby

The Chumby has an I2C bus that makes it possible to control peripheral boards with 2 wire control.  They currently use it to control some internal devices like the Radio and the accelerometer.

I wanted to be able to add additional (non-servo) PWM ports for external LED control.  One option is to add USB based PWM devices using something like the Nifty Pololu USB servo control boards http://www.pololu.com/catalog/product/1350.  I needed my USB ports for other things so I instead went with adding an I2C device.  A lot of I2C devices require a 5V interface but JeeLabs makes 3.3V I2C devices that are compatible with a 3.3V Chumby / Infocast.

The folks at ladyada.net have an example program that shows how to talk with the built-in accelerometer via a regutil like command line tool and via custom code.  The i2c demo program can be used to talk with any device via shell scripts.  You can find some notes on using a I2C dimmer on a Chumby at http://joe.blog.freemansoft.com/2011/02 … umby.html. 

It turns out to be a 5 wire connection for the LED dimmer board, 3.3V, ground, SDA, SCL and optional power to external items plugged into the ports of the added I2C device.  A compass or pressure sensor would only need a 4 wire connection.

I also have a JeesLabs non-PWMhigher current "output board" that I hope to play with.

Re: Adding an I2C device to a Chumby

There's 3 USB ports to play with on each Chumby.  You could always use a Hub too.

The programming simplicity of using the USB is a huge gain for sticking with USB rather than I2C for something like servo/micro interfacing.

I'll only use the I2C for low level stuff like reading temperature chips, EEPROMS, accelerometers and the like.

Re: Adding an I2C device to a Chumby

The code to run the I2c LED dimmer is super simple,  5 configuration registers set it up and one call to a PWM register each time to change the brightness.  The shell script mentioned in the original posting shows how easy it is.   Directly driving Servos would also be easy with the right I2C device for simple operations\. I2C has the advantage that you can add multiple controllers without hubs, up to the power limit of the device. BlinkM is a nice I2C device that is possibly incompatible with Chumby because of voltage levels..

USB devices are harder to talk to unless you have a good wrapper library because you have of the elaborate connection mechanisms. Many USB devices used to emulate COM ports was because of the simpler communication model.   Phidgets are a good example of a wrapper library that covers complexity.  USB devices have a possible advantage of having on board smarts so you can tell it to send the servo somewhere and wait a certain amount of time or for a signal and them move.  USB devices also have an advantage of simple off-the-shelf cabling and standard voltages.


#!/bin/bash
# DimmerDemo.bash V1
#
# Exercise the jeelabs I2C PWM dimmer board on a Chumby device
# More info on the jeelabs 3.3v compatible i2c dimmer board can be found at
# Info at http://jeelabs.org/2010/03/20/dimmer-plug/

# i2c command line tool like regutil that exercises i2c devices
# i2c source available at http://www.ladyada.net/learn/chumby/i2c.html
I2C=/mnt/storage/dev/i2c

#jeelabs dimmer is at 0x40 but shift up one for 0x80 or 128
DIMMER_BASE_ADDRESS=128

# NXP PCA9635 I2C bus driver registers
# http://www.nxp.com/documents/data_sheet/PCA9635.pdf
# global mode registers
MODE1=0
MODE2=1
# individual brightness controls
PWM0=2
PWM1=3
PWM2=4
PWM3=5
PWM4=6
PWM5=7
PWM6=8
PWM7=9
PWM8=10
PWM9=11
PWM10=12
PWM11=13
PWM12=14
PWM13=15
PWM14=16
PWM15=17
# group brightness
GRPPWM=18
# group duty cycle for blinking
GRPFREQ=19
# all channels modes selected here in two bit fields
LEDOUT0=20
LEDOUT1=21
LEDOUT2=22
LEDOUT3=23

# run in normal mode
$I2C w $DIMMER_BASE_ADDRESS $MODE1 0
# blink
$I2C w $DIMMER_BASE_ADDRESS $MODE2 32
# set duty cycle to 25%
$I2C w $DIMMER_BASE_ADDRESS $GRPPWM 64
# blink 4x per second
$I2C w $DIMMER_BASE_ADDRESS $GRPFREQ 5
# enable controls and blinking on LED0 low bits in LEDOUT0
$I2C w $DIMMER_BASE_ADDRESS $LEDOUT0 3

# set the brightness for PWM 0
for i in {0..128..16}
do
$I2C w $DIMMER_BASE_ADDRESS $PWM0 $i
sleep 1
done
# turn it off before exiting
$I2C w $DIMMER_BASE_ADDRESS $PWM0 0