The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
public class LCD : I2CPlug
{
public LCD(byte address) : base(address) { }
public void Write(string str)
{
//this.WriteToRegister(0, System.Text.Encoding.UTF8.GetBytes(str));
this.WriteToRegister(0, new byte[] { 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65 });
}
}
And here is my main while we are at it:
public static void Main()
{
LCD lcd = new LCD(0x27);
lcd.Write("Hello World Hello World");
while (true) { }
}
It does not throw an exception. The address is something I've tracked down by the model numbers on the LCD driver attached to the backside of the LCD ("T313S06" and "LCD1602" are the ones I see). The wiring:
Initialization sequence? Thank you for the input again Guido, but I don't understand why/how I can initialize the LCD, do I need to send the bytes in the documentation before:
That Adafruit display is a "pixel"-display? Where you can If you will paint whatever pixel you want. The one i have I just a simple 16x2 character display?
You probably got a point, the code I've found seems to be for a sensor. One thing doh: the I2CCommand, what is it?
Instead of WriteRegister i could simply use Write ->
public int Write(I2CDevice.Configuration config, byte[] writeBuffer, int transactionTimeout)
{
// Set i2c device configuration.
_slaveDevice.Config = config;
// create an i2c write transaction to be sent to the device.
I2CDevice.I2CTransaction[] writeXAction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(writeBuffer) };
lock(_slaveDevice)
{
// the i2c data is sent here to the device.
int transferred = _slaveDevice.Execute(writeXAction, transactionTimeout);
// make sure the data was sent.
if (transferred != writeBuffer.Length)
throw new Exception("Could not write to device.");
return transferred;
}
}
And as you can see it has an adapter attached. I've cooked down my code to the following, by using the I2CBus:
public class Program
{
public static void Main()
{
I2CDevice.Configuration config = new I2CDevice.Configuration(0x27, 59);
I2CBus.GetInstance().Write(config, System.Text.Encoding.UTF8.GetBytes("Hello World"), 3000);
}
}
But I guess I'm missing initializing part of the LCD...
I'm not sure if this will help, but it may give you another option to try. Iv'e written a driver for the Grove RGB I2C LCD dislpay. The code is pretty generic and will likely work with minor modifications to for your I2C controller. You could remove all the RGB backlight code pretty easily and then just add the right codes to perform all the functions.
Hi wendo! Thanks for the links, it might be what I'm looking for! But now I'm thinking that the various byte commands might be different. From the your link it is defined:
private byte LCD_ENTRYMODESET = 0x04;
And I think I've found the documentation on openhacks.com, here "Entry Mode Set"'s "instruction code is
0 0 0 0 0 0 0 1 I/D S
Regarding I/D, text is to move to the right so "1" there
And I'm back using Jaroen's I2CPlug; I've got the following that should work (why isnt it... bah!):
I2CPlug lcd = new I2CPlug(0x27);
Thread.Sleep(50); // need to wait for the device to power up
// init starts
lcd.Write(new byte[] { 0x3 });
Thread.Sleep(5);
lcd.Write(new byte[] { 0x3 });
Thread.Sleep(1);
lcd.Write(new byte[] { 0x3 });
lcd.Write(new byte[] { 0x2 });
lcd.Write(new byte[] { 0x28 }); // function set, set config: two lines, 5x8 font size
lcd.Write(new byte[] { 0x8 }); // display off
lcd.Write(new byte[] { 0x1 }); // clear
Thread.Sleep(2);
lcd.Write(new byte[] { 0x4 });
Thread.Sleep(1000);
// init is done, lets write text to screen
lcd.Write(System.Text.Encoding.UTF8.GetBytes("Hello World"));
When I run this the LCD lights up 100% brightness. Line 1 is filled with blocks, line 2 is empty. After the code is run and I would expect it to show "Hello World" the LCD has no backlight (i did turn that off, but was it me or a screw up? ) and line 1 has blocks, line 2 is empty.