Reading I2C data from an lcd screen

31 Dec 2009 . Edited: 31 Dec 2009

I'm using the mbed to talk to a lcd screen lcd03 (details below)

http://www.robot-electronics.co.uk/htm/Lcd03tech.htm

I'm using I2C and can send commands to the screen happily using the following

const int lcdAddress = 0xC6;
char cmd[2];
cmd[0] = 0x0;
cmd[1] = 0xD;
i2c.write(lcdAddress, cmd, 2);

I'm now trying to read data back form the lcd screen (it has built in keypad connections) which should just return a byte value for the registers 0x01 and 0x02.

I have tried sending the following code, but seem to get the same thing back every time (no matter what buttons are pressed, and what register I send) which makes me think the data I'm getting back isn't right

const int lcdAddress = 0xC6;
int var[1] = 0x01;   
int varResult[1];
    
i2c.write(lcdAddress, var, 1); 
i2c.read(lcdAddress, varResult, 1);
    
pc.printf("%x", varResult);

I put the %x in there to force the display to output the hex value, rather than the ascii response.

I assume I have the basics right here...

I would expect to see back either 0x00 (no buttons pressed) or something like 0x01, 0x02, 0x04, 0x08 etc...

31 Dec 2009 . Edited: 31 Dec 2009

Hi Richard,

Your first example is fine, but the second starts using ints instead of chars for the arrays. (I2C reads and writes arrays of chars). Also, when you come to print it out, you print out the address of the array, rather than the contents of the first element.

To make the second example analogous to the way you coded the first, perhaps try:

const int lcdAddress = 0xC6;

char cmd[1];
cmd[0] = 0x01;   
i2c.write(lcdAddress, cmd, 1); 

char res[1]; 
i2c.read(lcdAddress, res, 1);
    
pc.printf("%x\n", res[0]);

Not saying this will work, but hopefully will help you track it down.

Simon

06 May 2011

Good evening, I have a LCD03, it works in I2C mode with the micro-controller, I am now looking to send the value of a counter, are there any fonction Int to String conversion?

Thank you in advance. Bertrand