RGB Led Module BlinkM

25 Dec 2009 . Edited: 25 Dec 2009

Hello there, anyone had succedeed in changing the color of this RGB module? I am trying to port the arduino code to the mbed code.

Blinkm Module

Here you are the arduino code

 

Wire.begin();	// set up I2C
Wire.beginTransmission(0x09);// join I2C, talk to BlinkM 0x09
Wire.send(‘c’); // ‘c’ == fade to color
Wire.send(0xff); // value for red channel
Wire.send(0xc4); // value for blue channel
Wire.send(0x30); // value for green channel
Wire.endTransmission(); // leave I2C bus

And this is my translation of the code ported to mbed

 

#include "mbed.h"


I2C i2c (p28,p27);  // Setup the I2C interface: sda, scl

int main() {
    i2c.write(0x09, "c", 1); // Send command string
    i2c.write(0x09, "0xff", 1); // Send command string
    i2c.write(0x09, "0xc4", 1); // Send command string
    i2c.write(0x09, "0x30", 1); // Send command string
}

Link to the compiler code: BlinkM

The only problem is: it does not work... Can someone help me please?

Thanks

Note: 0x09 is the factory address of this I2C module

Please find below the datasheet of this module including arduino samples

http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf

25 Dec 2009

i2c.write needs the length of the string you're sending. In your example, you are sending the string "0xff", thats 4 chars followed by the '\0' (null terminator).

I am guessing you want to send the value 0xff (255). You would just need to pass a pointer to the variable that you want to send and the length of the data that you wish to send (in this case, 1 byte).

Have a look at the I2C documentation.

http://mbed.org/handbook/I2C

27 Dec 2009

Hi Francisco,

Igor has it spot on. Here would be a code example to try (translated from your code provided; I haven't looked at the datasheet):

#include "mbed.h"

I2C i2c(p28,p27);  // Setup the I2C interface: sda, scl

int main() {
    char data[4] = {'c', 0xff, 0xc4, 0x30};
    i2c.write(0x09, data, 4);
}

Also, I'd check the I2C address. If you want to see if your I2C device can be found on the bus as a sanity check, take a look at a little test program I wrote called I2CU:

Tell us how you get on and if it springs in to life!

Simon

01 Jan 2010 . Edited: 02 Jan 2010

Thank you Simon and Igor.

The code you provide me should work but I have something else which is not working. It must be something related to the I2C because when I upload and run I2CU (a modified version with pins 28 and 27) something weird happens:

- If I have nothing connected to the I2C then it finds 0 devices connected

- If I connect the blinkm module then the program sometimes does nothing but printf "looking for devices", sometines it finds like 3 or 4 devices at random addresses

Does the I2C bus requires some kind of line end resistor or something I am missing? I connect p28 to sda in the device and p27 to clock in the led device. Is this the correct wiring? (I am a complete newbie, sorry for disturbing you with these so basic questions)

-----------------------------------------------------

EDIT: I now know that I need something called pull-ip resistors...

EDIT 2: Ok I am just stupid, I didn't read the wikipedia about the I2C bus. Tomorrow I will power the bus line with the regulated 3,3 V of the mbed using a 4K7 resistor por each line and the I will connect the led.  module to the bus. We'll see if I don't burn anything.

EDIT 3: Not working either. (when I say it does not work I mean the led powers but it does not obey to change color) Wiring the module directly to the sda and clk pins of mbed is a good wiring diagram? In arduino mega they connect it like this

 

Connection of arduino to blinkm module

09 Jan 2010

Hi Francisco,

I've had a Blinky for a while and it's in the queue to be got going. You helped it jump to to the front!

I found three things getting in the way of it working :

1) It does need a pair of pull up resistors, I used 4k7.

2) The address may be wrong. I used I2CU to read back what was connected. Got 0x00 and 0x12. 0x00 is the broadcast address so it reponded to that and 0x12 is its own unique address which it now works from.

3) You have to stop the script it is shiped with before you can program in your own commands at whatever address it's at.

    char data[1] = {'o'};
    i2c.write(0x00, data, 1);  // will stop it at whatever address

After that it seems to work with Chris's suggestion and variations.

    char data[4] = {'c', 0xff, 0xc4, 0x30};
    i2c.write(0x12, data, 4);

Good luck,

Pip

 

08 Oct 2014

(fixed)