Interfacing the Carambola (1-Wire and I2C)

Got my Carambola just after New Years day.. Thought it was about time to see what I could do with it!

Wanted to look at the i2c bus and 1-wire to see if I could get the heating control project ported from the BeagleBone over to the Carambola. The module came with a stock OpenWRT install from what I could make out.  Neither I2C, GPIO or 1-Wire worked so followed the Wiki over at, downloaded the source and got building.

I’m on my fifth or sixth recompile/build! But I guess it goes with embedded territory, every module has to be build and a new image installed. At the moment I can’t figure out how to get the repositories for opkt working to install packages on the live system. The system build tools work out of the box and are easy to get to grips with. The only thing that slows one down is finding the correct options in the “make menuconfig”. But once again the Wiki has good instructions. On my current build for this test I have i2c, gpio and 1-wire installed.  Here are the links for the three steps:

1) i2c can be found in the PCF8575 example.
2) GPIO can be found in the Simple GPIO control, but watch out the gpioctl program is no longer available so you have to do everything using the /sys filesystem!
3) 1-Wire stuff can be found in the 8devices forum. (I’ve included the patch, which works fine on the latest kernel, in the resources zip file at the bottom.)

KiCAD time (all the KiCAD files for this are in the resource ZIP file at the end of this post).

Carambola electrical test schematic

Carambola electrical test schematic

Soldering some 0.1inch headers on to the Carambola helps!

Carambola GPIO headers

Time to bread-board the circuit up:

Carambola electrical test setup on the breadboard

Carambola electrical test setup on the breadboard

The upper few rows of the breadboard are for the 1-Wire, the rest is the I2C MCP23017.

So lets see if the MCP23017 is on the i2c bus..

root@OpenWrt:~# i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

Yep, at 0x24, cool.. For this test I’m just going to make all of port A outputs and all of port B inputs (you can do much more with the registers inside the MCP23017, but lets keep it simple!). First thing to do is adjust the MCP’s registers to suit:

root@OpenWrt:~# i2cset -y 0 0x24 0x00 0x00
root@OpenWrt:~# i2cset -y 0 0x24 0x16 0xff

The first line sets port A as an output port, the second enables the internal pull-ups (100K) on port B, which is input by default.

Switching on any of the three LEDs is easy, just write the bit pattern to register 0x09 (GPIOA).. so for the first LED we’d need to do this:

root@OpenWrt:~# i2cset -y 0 0x24 0x09 0x01

For the second:

root@OpenWrt:~# i2cset -y 0 0x24 0x09 0x02

I’m sure you see where this is going…

To read the bit pattern on port B is easy.  We just need to read register 0x19 (GPIOB).

root@OpenWrt:~# i2cget -y 0 0x24 0x19
0xff    <- if switch is open
0xfe    <- if switch on pin GPB0 is closed

The 1-Wire is as easy as always under Linux, just look in the /sys/devices/w1_bus_master1 and you should see a folder for each of the 1-Wire DS18B20’s you have connected to the bus.

All the stuff you should need for this is here: Carambola_test (zip file).  In the zip file you’ll find the KiCAD schematic and library of the Carambola header, MCP23017 and the DS18B20.

One thought on “Interfacing the Carambola (1-Wire and I2C)

Comments are closed.