Hello,
This class and main call works well on I2C code on Neduino Plus2 4.2 but fails on Netduino3 with 4.3. I have used new I2C pins on ND3.
Please Help.
Thank you in advance.
Kashani
public class LCD_HK
{
private static byte[] buffer = new byte[1];
private static I2CDevice device = new I2CDevice(new I2CDevice.Configuration(0x4E >> 1, 100));
private static I2CDevice.I2CTransaction[] actionsWrite = new I2CDevice.I2CTransaction[]
{
I2CDevice.CreateWriteTransaction(buffer)
};
private void WriteCommand(byte value)
{
// send data with EN high. shift data in the high nibble and create control in low nibble
buffer[0] = (byte)((value << 4) | 0x0C);//shift left 4 bits, then OR with 0000 1(1)00. bit (En) forced high
device.Execute(actionsWrite, 200); //shift the crtl byte low to high and padd E toggle
// send data with EN low
buffer[0] = (byte)(buffer[0] & 0xFB);//and with 1111 1(0)11. bit (En) is forced low
device.Execute(actionsWrite, 200);
}
private void WriteData(byte value)
{
// send data with EN high. shift data in the high nibble and create control in low nibble
buffer[0] = (byte)((value << 4) | 0x0D);// or with 0000 1101
device.Execute(actionsWrite, 100);
// send data with EN low
buffer[0] = (byte)((buffer[0]) & 0xFB);//and with 1111 1(0)11. bit (En) is forced low
device.Execute(actionsWrite, 100);
}
public void displayChar(char value)
{
byte upper = (byte)((value & 0xF0) >> 4);// and with 1111 0000 then shift right 4 bits
WriteData(upper);
byte lower = (byte)(value & 0x0F);
WriteData(lower);
}
public void displayString(string msg)
{
for (int i = 0; i < msg.Length; i++)
displayChar(msg[i]);
}
public void InitializeLCD()
{
// Initialize and clear LCD
WriteCommand(0x2);
WriteCommand(0x2);
WriteCommand(0x8);
WriteCommand(0x0);
WriteCommand(0xE);
WriteCommand(0x0);
WriteCommand(0x6);
}
public void clearLCD()
{
WriteCommand(0xFE);
WriteCommand(0xB); //set cursor home
displayString(" ");//clear screen
WriteCommand(0xFE);
WriteCommand(0xB); //reset cursor home
}
}