and i am using the c++ classes as reference. But when testing it seems that the display is not displaying the last charecter i send. and then when i send it a new one it displays the previous one.
so if i want to display in sequence 1, 2, 3, 4 ,5 ,6 ,7 ,8, 9 i get -, 1, 2, 3, 4, 5, 6, 7, 8
I am using the i2c netmf reference code so nothing to crazy.
lock (I2CHelper.Device)
{
byte len;
byte x, y;
x = X;
y = Y;
len = (byte)text.Length;
for (int i = 0; i < len; i++)
{
//create transactions (we need 2 in this example)
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[1];
// create write buffer (we need one byte)
byte[] RegisterNum = new byte[4] { LCD_WR, y, x, (byte)text[i] };
xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
// Explicitly set the I2C bus to access device A by setting the I2C Config to the Device A's config.
I2CHelper.Device.Config = LCDConnection;
if (I2CHelper.Device.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("write: " + text[i]);
}
// delay(20);
Thread.Sleep(20);
x++;
if (x > 15)
{
x = 0;
y++;
if (y > 2)
return;
}
}
What can you see when you step through your code? Particularly what does RegisterNum look like? That seems like the area of your code that’s most likely to lead to the behavior that you explain.
i have gone through it, and as far as i can see is it sends all 9 numbers. but after the last send it does not update the display. this is how it is done in the c lib
void LCD16x2::lcdWrite(char* string){
uint8_t len;
uint8_t x, y;
x = X;
y = Y;
len = strlen(string);
for(int i = 0; i < len; i++){
Wire.beginTransmission(ADDRESS);
Wire.write(LCD_WR);
Wire.write(y);
Wire.write(x);
Wire.write(string[i]);
Wire.endTransmission();
delay(20);
x++;
if(x > 15){
x = 0;
y++;
if(y > 2)
return;
}
}
}
i am wondering coud the way it sends the data be different? its like the lcd is still expecting data and so does not update. does netmf send the data differently?
No I2C expert but I did notice one thing in your code.
//create transactions (we need 2 in this example)
I2CDevice.I2CTransaction xActions = new I2CDevice.I2CTransaction[1]; << You are using [1]
GHI sample code
This example will read the value of the register on an I2C device with the 7-bit address of 0x38.
you first have to write the register number you want to read, two in this case, and then read the value back.
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
public class Program
{
public static void Main()
{
//create I2C object
//note that the netmf i2cdevice configuration requires a 7-bit address! It set the 8th R/W bit automatically.
I2CDevice.Configuration con = new I2CDevice.Configuration(0x38, 400);
I2CDevice MyI2C = new I2CDevice(con);
// Create transactions - We need 2 in this example, we are reading from the device
// First transaction is writing the "read command"
// Second transaction is reading the data
I2CDevice.I2CTransaction[] xActions = new I2CDevice.I2CTransaction[2];
// create write buffer (we need one byte)
byte[] RegisterNum = new byte[1] { 2 };
xActions[0] = I2CDevice.CreateWriteTransaction(RegisterNum);
// create read buffer to read the register
byte[] RegisterValue = new byte[1];
xActions[1] = I2CDevice.CreateReadTransaction(RegisterValue);
// Now we access the I2C bus using a timeout of one second
// if the execute command returns zero, the transaction failed.
// (this is a good check to make sure that you are communicating with the device correctly
// and don’t have a wiring issue or other problem with the I2C device)
if (MyI2C.Execute(xActions, 1000) == 0)
{
Debug.Print("Failed to perform I2C transaction");
}
else
{
Debug.Print("Register value: " + RegisterValue[0].ToString());
}
}
}
Interesting. Might want to try the GoToXY function between calls. Looks like it’s not positioning properly, at least on those latter ones. Doesn’t explain the odd behavior on the first call, though.
I might have one of those LCD shields in my stash here. I’ll take a peek today when I go in.