Netduino home hardware projects downloads community

Jump to content


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.
Photo

Need help with I2C LCD display


  • Please log in to reply
13 replies to this topic

#1 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 03 June 2014 - 06:24 PM

I've got a LCD the other day, have been trying to get it to work but I'm messing up somewhere... not sure where, so I hope someone could enlighten me.
 
I've started out with Jeroen's I2CPlug code. I've added my own LCD class:

    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:
 
http://bildr.no/view/SU1uTDNo
 
- VCC goes to 5V
- GND goes to GND
- SDA goes to SDA, pullup to 3.3V by a 2k2 resistor
- SCL goes to SCL, pullup to 3.3V by a 2k2 resistor

- DefaultClockRate is 60

- TransactionTimeout is 1000
 
What am I doing wrong? :-) Ignore the fact that the string i want to write is ignored, I've just created a array that should be 19 A's on the display!
 
EDIT:
Updated the wiring by Guido's comment.



#2 dino4net

dino4net

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 04 June 2014 - 10:31 AM

Hello,

 

I2C Ports on the Netduino 2 are on the other side "SC" and "SD", and not A4 / A5 any more.

 

Guido



#3 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 04 June 2014 - 01:52 PM

Thank you for your input Guido! It is still nor working but atleast something is happening! :-)

 

Now the screen is flickering from what you see on the image and a darker version. Maybe Im using the wrong pullup resistors?



#4 dino4net

dino4net

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 05 June 2014 - 08:42 AM

Hi,

 

Pull up should be fine. My guess would be a wrong initialization sequence.

Maybe this helps, also I'm not sure if it's yours ...

 

Guido

 

 

 

Attached Files



#5 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 05 June 2014 - 08:55 AM

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:

this.WriteToRegister(0, new byte[] { 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65 });

?



#6 dino4net

dino4net

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 05 June 2014 - 01:59 PM

Yes, that is normally done first.

 

An example for the Adafruit SSD1306

 

Attached File  Display Sample.zip   583.03KB   85 downloads

 



#7 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 05 June 2014 - 06:07 PM

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?

 

Should not be that hard?

 

What is the registerBuffer and writeBuffer? I'm currently looking at http://wiki.netduino...-Bus-class.ashx ->

        public void WriteRegister(I2CDevice.Configuration config, byte register, byte[] writeBuffer, int transactionTimeout)
        {
            byte[] registerBuffer = { register };
            Write(config, registerBuffer, transactionTimeout);
            Write(config, writeBuffer, transactionTimeout);
        }

It writes first the registerBuffer, then the writeBuffer... im calling it  here ->

public void Write(string str)
        {
            I2CBus.GetInstance().WriteRegister(_slaveConfig, 0x3C, System.Text.Encoding.UTF8.GetBytes(str), TransactionTimeout);
        }

But what is the 0x3C? Might be the problem?

 



#8 dino4net

dino4net

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 05 June 2014 - 09:13 PM

3C should be the register you write to, but for displays you normally write commands. Registers are more used in sensors.

Try

I2CBUS.GetInstance().Write(_slaveConfig, I2CCommand, I2CTimetout);



#9 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 06 June 2014 - 07:10 AM

3C should be the register you write to, but for displays you normally write commands. Registers are more used in sensors.

Try

I2CBUS.GetInstance().Write(_slaveConfig, I2CCommand, I2CTimetout);

 

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;
}
}

?

 

Think I've already tried this without luck.



#10 dino4net

dino4net

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 06 June 2014 - 08:19 AM

There is something available for Arduino you can have a look at.

Attached Files



#11 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 06 June 2014 - 02:22 PM

Hmm... from some arduino threads it seems that the problem here is initialization.

 

The LCD I have comes with an adapter, I would think i would prep the LCD for input. The LCD I have is this one: http://www.dx.com/p/...70#.U5HNZ_l_sfM

 

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...



#12 wendo

wendo

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 06 June 2014 - 10:27 PM

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.

 

The driver is here

 

https://github.com/s...veRGBLCD/lcd.cs

 

The actual repo has an example program as well but it's pretty straightforward



#13 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 07 June 2014 - 05:26 PM

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

Regarding S, again: shift right so "0"?

 

That makes up

0 0 0 0 0 0 0 1 1 0

which is 6, or 0x6? Am I doing this right?



#14 Larsey

Larsey

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts

Posted 07 June 2014 - 08:21 PM

Sorry for double posting, but I've been working all evening and have not got anything usefull displayed yet!

 

I found several datasheets that says pretty much the same:

http://www.renanaran...s/LCD-1602A.pdf

http://oomlout.com/p...1-datasheet.pdf

 

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? :P) and line 1 has blocks, line 2 is empty.

 

Giving up now really...






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.