Simple design 20x4 LCD I2c -from beginning to end - for beginners: - General Discussion - Netduino Forums
   
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

Simple design 20x4 LCD I2c -from beginning to end - for beginners:

netduino c# i2c display lcd 20x4 beginner for dummies

  • Please log in to reply
12 replies to this topic

#1 dorathoto

dorathoto

    Member

  • Members
  • PipPip
  • 12 posts

Posted 26 March 2014 - 07:51 PM

the display: 
IIc/I2c/Twi Serial LCD2004 2004 20 * 4 Module Shield Display Blue / White 
 
 
wanted to write a simple "Hello World"
 
I tried to use the library Cet Open Toolbox 
I found it extremely difficult and complex to be able to make a simple text. 
 
/ / draw some text 
             composition.DrawString (
                 "Ciao!" 
                 null, 
                 Brushes.White, 
                 new Point (3, 0) 
                 );
My connections:
 
Display / Netduino
GND     /  GND
VCC     / 3v3
SDA     / SD
SCL      / SC
 
there is nothing that I can write something like?
lcd.write(1,1, "hello word");  //example only

 

Attached Files



#2 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 27 March 2014 - 02:00 AM

Hello, I've had lot of success using the MicroLiquidCrystal library and this similar display:

http://www.sainsmart...no-mega-r3.html

I have more details here (and that thread has a great discussion in general for I2C LCDs). You may need to adjust the shifter pins to get the MicroLiquidCrystal library to work for your particular device. Otherwise, that thread has some excellent info that may be of use to you as well.

 

Good luck!



#3 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 27 March 2014 - 05:28 AM

 

the display: 
IIc/I2c/Twi Serial LCD2004 2004 20 * 4 Module Shield Display Blue / White 
 
 
wanted to write a simple "Hello World"
 
I tried to use the library Cet Open Toolbox 
I found it extremely difficult and complex to be able to make a simple text. 
 
/ / draw some text 
             composition.DrawString (
                 "Ciao!" 
                 null, 
                 Brushes.White, 
                 new Point (3, 0) 
                 );
My connections:
 
Display / Netduino
GND     /  GND
VCC     / 3v3
SDA     / SD
SCL      / SC
 
there is nothing that I can write something like?
lcd.write(1,1, "hello word");  //example only

 

 

First off, the LcdBoost library is useful only when the display has no "accelerators" like the model you chose. I mean a very basic LCD-module with just the HD44780 controller and nothing more. The module you chose offers a little microcontroller that acts as interface I2C/SPI, and maybe also helps with some primitive function.

At the time of the library development there were none of such a "accelerators".

 

The original MicroLiquidCrystal works with just a bunch of "wires" from the Netduino to the LCD module, but you'll run easily out of available I/Os. The most reasonable option is using a very common shift-register as the 74HC595: this will save a lot of I/Os, and performs a bit faster.

 

I decided to write my own lib, because the MicroLiquidCrystal is *VERY* slow. If you try to run any function (e.g. Write) it takes a lot of time. However, this may be not an issue, but most of the times the running application does something important other than driving the LCD. When compared to the MicroLiquidCrystal, the LcdBoost also uses the shift-register and requires just a transistor more, but it is *WAY* faster.

Here is a detailed comparison: http://highfieldtale...e-for-netduino/

The LcdBoost is 12 times faster.

 

The LcdBoost has another advantage over the MicroLiquidCrystal: it yields two different approaches of programming. The "imperative" way, which is what you look for, and the "declarative" one, which is far simpler when you wanna deal with a complex graphics.

It's up to you decide what's the best for your goal.

 

Here is an excerpt from the article, where probably you've seen the library demo:

http://www.tinyclr.i...lcd-module.aspx

 

    public class Program
    {
        public static void Main()
        {
            //create a lcd-char driver instance
            _renderer = new BoostHD44780(
                cspin: Pins.GPIO_PIN_D8,
                config: BoostHD44780.Layout20x4);

            //creates the target composition instance
            var composition = _renderer.CreateTarget();

            //draw some text
            composition.DrawString(
                "Ciao!",
                null,
                Brushes.White,
                new Point(3, 0)
                );

            //dumps the composition to the physical device
            _renderer.Dump(composition);

            //keep alive
            Thread.Sleep(Timeout.Infinite);
        }
    }
And that's your target:
    lcd.write(1,1, "hello word");  //example only
Where is the "extremely difficult and complex" section?
  • Instead of "lcd" place "composition";
  • if you don't mind a different font, leave the "null" as second parameter;
  • the third specifies the shading;
  • the latter are the coordinates.

 

Finally, here is a piece of code used as a test for the LcdBoost, where the usage is "imperative":

http://cetdevelop.co...Test/TestSet.cs

 

Have fun!


Biggest fault of Netduino? It runs by electricity.

#4 dorathoto

dorathoto

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 March 2014 - 02:11 PM

thank you all, ShVerni, and Mario Vernari. 
Vernari with this surname will find it Italian. 
Buongiorno, Parla italiano? :)
 
So my application is simple, I think the performance will not be the problem. 
I do not want to lose so much time, I wanted it to be easy to manipulate igual servo. 
 
Fix 2 errors I was doing. 
1 - 3v3 changed to 5v 
2 - I am using the MicroLiquidCrystal and using FusionWare.SPOT.Hardware; 
 
I tried something simple. 
 
using System.Diagnostics;
using System.Threading;
using FusionWare.SPOT.Hardware;
using MicroLiquidCrystal;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using FusionWare.SPOT.Hardware;
using FusionWare;


public static void Main()
{
   var bus I2CBus = new (); 
   var = new lcdProvider MCP23008LcdTransferProvider (bus); 
   // here I think you should switch to my drive? 
   var lcd = new Lcd (lcdProvider); 
   lcd.Begin (20,4); 
   lcd.Clear();
   lcd.Write ("hello, world!");
}


#5 dorathoto

dorathoto

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 March 2014 - 06:52 PM

ShVerni My display is exactly the same, I calmly read your post.

#6 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 28 March 2014 - 02:47 PM

Hello,
 
I take it you're still having problems then. There were a few quirks to the display, as I said I had to reassign the pins like so:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using MicroLiquidCrystal;
using FusionWare.SPOT.Hardware;
namespace LCD
{
    public class Program
    {
        private static OutputPort power = new OutputPort(Pins.GPIO_PIN_D0, false); 
        private static I2CBus bus = new I2CBus(); 
        private static BaseShifterLcdTransferProvider.ShifterSetup shifter = new BaseShifterLcdTransferProvider.ShifterSetup();
        public static void Main()
        {
            shifter.RS = ShifterPin.GP0;
            shifter.RW = ShifterPin.GP1;
            shifter.Enable = ShifterPin.GP2;
            shifter.BL = ShifterPin.GP3;
            shifter.D4 = ShifterPin.GP4;
            shifter.D5 = ShifterPin.GP5;
            shifter.D6 = ShifterPin.GP6;
            shifter.D7 = ShifterPin.GP7;
            power.Write(true);
            MCP23008LcdTransferProvider lcdProvider = new MCP23008LcdTransferProvider(bus, 0x3F, shifter);
            Lcd lcd = new Lcd(lcdProvider);
            lcd.Begin(20, 4);
            // LCD is now ready, let's test it! 
            lcd.SetCursorPosition(0, 0);
            lcd.Write("Hello, world!");
        }
    }
}

The important thing to note is that you need to be sure you have the correct I2C address here:

MCP23008LcdTransferProvider lcdProvider = new MCP23008LcdTransferProvider(bus, 0x3F, shifter);

In my case, that is 0x3F, it may be the same for you. I should also point out that while you may have the same model of shift register, it may not be hooked up the exact same way (I couldn't find a datasheet for your LCD when I looked briefly on that site), so you may need to play around with these settings:

shifter.RS = ShifterPin.GP0;
shifter.RW = ShifterPin.GP1;
shifter.Enable = ShifterPin.GP2;
shifter.BL = ShifterPin.GP3;
shifter.D4 = ShifterPin.GP4;
shifter.D5 = ShifterPin.GP5;
shifter.D6 = ShifterPin.GP6;
shifter.D7 = ShifterPin.GP7;

Lastly, I noted that I had to keep the LCD powered off until just before I was ready to use it. You can uses a transistor and an output port like I did, or you can just plug the LCD in manually a second or so after the program starts. As an alternative, you may be able to get it to work by flushing the SDA pin, like so:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using MicroLiquidCrystal;
using FusionWare.SPOT.Hardware;
namespace LCD
{
    public class Program
    {
        private static BaseShifterLcdTransferProvider.ShifterSetup shifter = new BaseShifterLcdTransferProvider.ShifterSetup();
        public static void Main()
        {
            // Add this
            OutputPort op = new OutputPort(Pins.GPIO_PIN_SDA, false);
            op.Write(true);
            Thread.Sleep(200);
            op.Write(false); 
            I2CBus bus = new I2CBus();   
          
            shifter.RS = ShifterPin.GP0;
            shifter.RW = ShifterPin.GP1;
            shifter.Enable = ShifterPin.GP2;
            shifter.BL = ShifterPin.GP3;
            shifter.D4 = ShifterPin.GP4;
            shifter.D5 = ShifterPin.GP5;
            shifter.D6 = ShifterPin.GP6;
            shifter.D7 = ShifterPin.GP7;
            MCP23008LcdTransferProvider lcdProvider = new MCP23008LcdTransferProvider(bus, 0x3F, shifter);
            Lcd lcd = new Lcd(lcdProvider);
            lcd.Begin(20, 4);
            // LCD is now ready, let's test it! 
            lcd.SetCursorPosition(0, 0);
            lcd.Write("Hello, world!");
        }
    }
}

I haven't tested the above code, which I borrowed from this excellent thread, which may also be of help to you:

http://forums.netdui...56-help-on-i2c/



#7 dorathoto

dorathoto

    Member

  • Members
  • PipPip
  • 12 posts

Posted 29 March 2014 - 12:18 PM

ShVerni good day, thank you for your patience and help. 
 
The first code you posted, I got 2 questions, did not work, but as you yourself said, I need to make some adjustments. 
 
private static power OutputPort = new OutputPort (Pins.GPIO_PIN_D0, false); 
why? I'm calling the power at 5V, digital port transmits many volts? this line is optional? 
 
Another question: 
my display is: device address 0x27 
in your code was 0x3F I put 0x27F?? 
 
You said I should change 
shifter.RS = ShifterPin.GP0; 
             shifter.RW = ShifterPin.GP1; 
             shifter.Enable = ShifterPin.GP2; 
             shifter.BL = ShifterPin.GP3; 
             shifter.D4 = ShifterPin.GP4; 
             shifter.D5 = ShifterPin.GP5; 
             shifter.D6 = ShifterPin.GP6; 
             shifter.D7 = ShifterPin.GP7; 
 
however, but with 8 possible choices of over 16 million combinations!. lol 
if I get Datashet easier? 
 
Sorry my english, I'm still learning.


#8 dorathoto

dorathoto

    Member

  • Members
  • PipPip
  • 12 posts

Posted 29 March 2014 - 01:12 PM

Can not be that hard as well make a run on the Netduino display, 
tangle is a link in the forums to try to find something that can help. 
And honestly this is practically a CTRL + C, CTRL + V code and testing the blind. Not much information because of the things. : (
This is very sad , for those familiar with this knowledge, which always encotramos in Microsoft msdn
I know it is a project independent counsel, but I think I got used poorly, with the amount of items that we always find at Microsoft.


#9 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 29 March 2014 - 01:21 PM

Hello again,
 

Another question: 
my display is: device address 0x27 
in your code was 0x3F I put 0x27F??

Yes, you should absolutely put your address in there.
 
As for this:

private static power OutputPort = new OutputPort (Pins.GPIO_PIN_D0, false);
why? I'm calling the power at 5V, digital port transmits many volts? this line is optional?

That's a bit more complicated. I found that I had to keep the LCD powered off untill just before this line:

MCP23008LcdTransferProvider lcdProvider = new MCP23008LcdTransferProvider(bus, 0x3F, shifter);

I don't know if this is also true for your LCD. You can test if you need to do this by putting a break point before this line in the debugger, unplugging your LCD, and then plugging the power pin back in just as your continue execution of the code (it may take a few tries to get the timing right). Alternatively, you could use an NPN transistor like so :
Attached File  transistor.png   278.96KB   0 downloads
 
Alternatively alternatively, you could try using that second block of code I posted, essentially adding this piece of code I found (but haven't tested) instead of the power pin (be sure to look at the thread I linked to in my last post):

OutputPort op = new OutputPort(Pins.GPIO_PIN_SDA, false);
op.Write(true);
Thread.Sleep(200);
op.Write(false);
I2CBus bus = new I2CBus(); 

Again, none of that may be necessary for your device.

 

Lastly, the LCD works by using a shift register to take the serial data from the Netduino and control the LCD numerous pins (instead of the Netduino controlling all those pins directly), so all the shifter assignments as there to tell the code which shift register pin is connected to which LCD pin.

however, but with 8 possible choices of over 16 million combinations!. lol
if I get Datashet easier?

This is true, so the datasheet would hopefully help, since I can't know which shift register pins are connected to which LCD pins on your device. It would also be useful if there was an example Arduino library you could use as a starting example.

 

It may also be that you will find it easier to use a different LCD library like these:

http://forums.netdui...-i2c-interface/

 

Or

 

http://forums.netdui...on-i2c/?p=57124

 

Or the LcdBoost library Mario Vernari mentioned.



#10 vedat

vedat

    New Member

  • Members
  • Pip
  • 1 posts

Posted 29 April 2014 - 07:01 PM

@dorathoto, I was having a similar issue and I came across this thread. Firstly, I’d like to thank you for starting this thread and asking the right questions, it was worth reading I surely got some great information from this thread. I’m actually now more interested in finding a new library. I’m working with a blue/black LCD with a similar controller as yours but the problem that I’m facing is that it isn’t quick enough. For example, sometimes, it doesn’t get the clear or new line signals and starts re-writing on the same line. I was wondering if you guys had this issue before. Thanks in advance.



#11 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 30 April 2014 - 02:58 AM

Hello Vedat and welcome!

 

I can't say I've had that problem with my LCD, but I've only tried one model. A simple, though inelegant, workaround may be to create your own method that calls the clear/new line command, then has a brief delay of a few milliseconds to make sure the command is received.

 

Maybe something like:

public void clearNew()
{
     lcd.Clear();
     Thread.Sleep(5);
}

Though you'd obviously want to use whatever clear methods/command your library does.

 

If the problem is that the screen doesn't receive those commands at all, then I'm afraid I can't think of a reason without knowing some more details, or maybe someone else has a better idea?

 

Best of luck!



#12 dorathoto

dorathoto

    Member

  • Members
  • PipPip
  • 12 posts

Posted 04 July 2014 - 07:28 PM

I'm still having problems, I started tinkering in Netduino.

My Netduino is 4.3.1.0
Can I downgrade if necessary, but it works for other applications.

When trying to use the Toolbox + uLiquidCrystal
I am encountering this problem while compiling
Resolving.

Link failure: some assembly references can not be resolved!
Assembly: display20x4_test (1.0.0.0) needs assembly 'Cet.HW.GDI_MF42' (1.0.0.0)
Assembly: display20x4_test (1.0.0.0) needs assembly 'Cet.HW.Drivers.BoostHD44780_MF42' (1.0.0.0)
Assembly: display20x4_test (1.0.0.0) needs assembly 'Microsoft.SPOT.Hardware' (4.2.0.0)
Assembly: Cet.HW.Drivers.BoostHD44780_MF42 (1.0.0.0) needs assembly 'mscorlib' (4.2.0.0)
Assembly: Cet.HW.Drivers.BoostHD44780_MF42 (1.0.0.0) needs assembly 'Cet.HW.GDI_MF42' (1.0.0.0)
Assembly: Cet.HW.Drivers.BoostHD44780_MF42 (1.0.0.0) needs assembly 'Microsoft.SPOT.Hardware' (4.2.0.0)
Assembly: Cet.HW.Drivers.BoostHD44780_MF42 (1.0.0.0) needs assembly 'SecretLabs.NETMF.Hardware.Netduino' (4.2.1.0)
Assembly: Cet.HW.Drivers.BoostHD44780_MF42 (1.0.0.0) needs assembly 'Microsoft.SPOT.Native' (4.2.0.0)
Assembly: Cet.HW.GDI_MF42 (1.0.0.0) needs assembly 'mscorlib' (4.2.0.0)
Error: a3000000
Waiting for debug commands ...
The program '[5] Micro Framework application: Managed' has exited with code 0 (0x0).


I believe the problem seje because I'm on 4.3.1?



#13 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 09 July 2014 - 02:23 AM

That does seem to indicate you need to use version 4.2. It might be possible to rebuild the micro LCD framework for version 4.3, but I've never tested that, so your guess is as good as mine as to whether that will work.

 

Best of luck!







Also tagged with one or more of these keywords: netduino, c#, i2c, display, lcd, 20x4, beginner, for dummies

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.