So communication is okay, good to know.
I2C read doesnt work that way. For some reason the acknowledge setting of a read command is an int and not a boolean, so it does not complain about your code, but that way you read a single byte writting on i2c bus, while sending an ACK back. (see: http://mbed.org/projects/libraries/api/mbed/trunk/I2C#I2C.read)
I havent checked this sensor out, but generally you need to write the register address you want to read to the device, then you transmit a restart, and then you send the device address again in read mode. In mbed code this is done by:
char read_i2c(char address)
{
char retval;
i2c.write(0xE8, &address, 1, true); //Write the register address you want to read to your sensor, do not transmit stop condition in end
i2c.read(MMA7660_ADDRESS, &retval, 1); //Open device in read mode, read 1 byte. If you need more you can simply read more bytes, normally address pointer auto increments
return retval;
}
Then your printf needs to have included which value you want to output. So for example:
address = 0x74;
pc.printf("Colour Value = %d/n",read_i2c(address));
Aditionally quite many sensors wont start automatically until you specifically put them in a measurement mode.
Edit: Had a look at its datasheet, and looks you have to do the following, do take into account it was only a quick look, so might be wrong:
Write 0x01 to register 0x00 to start a measurement.
Wait until this register is cleared again, which indicates measurement is complete.
Read the result.
So in code it would be something like:
//Write function, read function is already shown above
void write_i2c(char address, char data)
{
char temp[2];
temp[0]=address;
temp[1]=data;
i2c.write(0xE8, temp, 2);
}
int main() {
while(1) {
address=0x00;
write_i2c(address, 0x01); //Set control register to do measurement
while(read_i2c(address)==0x01); //Wait as long as control register has value 0x01
address=0x74;
//When code gets here the control register is cleared and you can read the data
printf("Your data: %d \n", read_i2c(address));
}
}
(Note: I just wrote this code in the forums, so probably there will be syntax errors)
Has anyone used this colour sensor http://littlebirdelectronics.com/products/color-light-sensor-evaluation-board-1 or atleast something simmilar? If so could you please show me some of your code/code snippet that was used to do this.