I2C on Cerbuino Bee vs Panda II

I connected a device using I2C on my FEZ Panda II with no problems. I used D2 and D3 (marked SCL and SDA).

Recently I switched to a Cerbuino Bee and connected everything the same way, now my I2C interface isn’t working. The I2C pins are the same right?

I also tried using the SoftwareI2CBus as follows…

GHI.OSHW.Hardware.SoftwareI2CBus bus = new GHI.OSHW.Hardware.SoftwareI2CBus(Cpu.Pin.GPIO_Pin2, Cpu.Pin.GPIO_Pin3);
SoftwareI2CBus.I2CDevice i2cDevice1 = bus.CreateI2CDevice(0xc, 12);
int numWritten = i2cDevice1.Write(data, 0, data.Length);

numWritten is always 0. What gives?

This should help GHI Electronics – Where Hardware Meets Software

Check schematics in Download tab of the product description. I think it is D0 and D1.

Thanks guys, I was beat my head against this stupid problem all day. I liked how this worked on the Panda II much better. The I2CDevice class just worked out of the box.

The Cerbuino Bee and the Panda II expose I2C in a slightly different location. And on the Bee it’s the second I2C (I2C_2 instead of I2C_1). The Bee doesn’t work with the I2CDevice class out of the box. No big deal, but it’s a difference I hadn’t expected.

I never figured out how to use the I2CDevice class with the second I2C on the Bee. But the SoftwareI2CBus class is working for me now, and that’s fine for my purposes.

My background is software, this hardware stuff is still new to me. For the next idiot, this is my working code…

byte[] data = new byte[1]; // Changed because my data was private.

data[0] = (byte)128;

Cpu.Pin I2C_SDA = (Cpu.Pin)GHI.OSHW.Hardware.FEZCerbuino.Pin.Digital.D2;
Cpu.Pin I2C_SCL = (Cpu.Pin)GHI.OSHW.Hardware.FEZCerbuino.Pin.Digital.D3;

GHI.OSHW.Hardware.SoftwareI2CBus bus = new GHI.OSHW.Hardware.SoftwareI2CBus(I2C_SCL, I2C_SDA);

SoftwareI2CBus.I2CDevice device = bus.CreateI2CDevice(0xc, 0);

int numW = device.Write(data, 0, data.Length);

I had been using Cpu.Pin, etc. because the SoftwareI2CBus method expects that type. Intellisense automatically presents wrong options to you. I wish they’d used an Abstract or Interface to prevent the mixup, but what do I know. At any rate, casting my device’s pins as a Cpu.Pin returned the correct object. See lines 3 and 4 above.

EDIT: GHI Electronics – Where Hardware Meets Software didn’t have an answer for me. It says, “???” where it should say I2C_2. I found this on the schematic, and fyi the text on that is overlapped by other text, making it difficult to read. In general though, I love these products and your websites.

I2C 2 us not supported. You can only use 1. But software I2C is implemented natively and should be just fine for most applications.

For software developers, we recommend gadgeteer. It makes everything much simpler and there is a wide range of available modules.