Geeks With Blogs

News
View Szymon Kobalczyk's profile on LinkedIn

Szymon Kobalczyk's Blog A Developer's Notebook

.NET Micro Framework includes reach graphics capabilities with WPF-like libraries, and quite a few high end development boards (Tahoe II, ChipworkX, or FEZ Cobra to name a few) include fancy graphic TFT screens, often with touch input thrown in as well. But this comes at a significantly higher costs, and requires a speedy CPU. Thus it might seem that if you are using a much cheaper board such as Netduino or one of FEZ family, you are doomed to rely on blinking LEDs only. Not quite so. In most scenarios an alphanumeric LCD might be a cheap alternative (or if you have higher budget you might consider using an OLED screen that also works with Netduino).

altFor a larger project I’m working on I plan to use an alphanumeric LCD to display all sorts of status information. Practically all popular LCDs are controlled by a HD44780 compatible parallel interface chipset. There is wide range of these screens available in various combinations of backlight and text color. The common size is 16x2 characters (16 columns in 2 rows). Take a look at the wide selection of LCDs available from SparkFun. I got mine from local electronics store that has very cool looking combination white text on blue background.

When you buy the LCD take notice if you get the 5V or 3V3 version. I’m sure both work fine with Netduino (which uses 3V3 logic) but make sure to wire them to correct power source pin.

These LCDs are quite easy to wire and program. If you look at the above picture notice the 16pin header on top of the display. The HD44780 chipset uses parallel interface for data communication and supports 8bit and 4bit modes. In the former case it will use at least 10 digital output pins from the microcontroller, in the later at least 6. The R/W pin (read write) bit can be permanently wired to ground. You can find the wiring instructions in the examples for the Arduino Liquid Crystal library – it will work the same way on the Netduino. To avoid soldering you can also try to use the DFRobot LCD Keypad Shield for Arduino, and I learned via twitter that Mr. Kogoro Kotobuki (@kotobuki), is designing a similar LCD shield that appears to work great with Netduino. I was told it’s a prototype and not yet sold, but it looks very nice (see one more photo and the schematics).

However if we take the direct approach, the LCD will use at least six of available digital pins. If you use a microcontroller that exposes a massive number of IO ports (like FEZ Rhino or upcoming FEZ Panda) this might be okay, but in case of Netduino or similar board that has only a handful of digital pins this might be not suitable. In this case you might want to multiplex the output over fewer lines. In my previous post I already talked about using shift registers to work around such situation and in this case we can reduce the number of outputs to only three.

Another alternative could be to buy a Serial Enabled LCD. Usually they include as special daughter board on the back (hence called a “backpack”) that has a MCU responsible for translating the UART communication to the interface of the LCD. So if you can sacrifice one of the UART ports on the Netduino this might be a good option, but they usually cost about $10 more than regular LCDs. You can also buy the serial backpack alone, for example the one from Sparkfun or the LCD117 Serial LCD Kit from Modern Devices.

For my project I will be using the same 74HC595 shift register that I used in my earlier demo. Pavel Bánský already demonstrated how to do this on .NET Micro Framework devices. In his first post he shows how to interface LCD with 3 wires using the 4094 shift register, and then in the second post he added support for an I2C 8-bit port extender. I have modified and extended his library to include functionality available in the Arduino LiquidCrystal library.

Pavel introduced a nice abstraction in his implementation to separate the LCD high level functions from underlying transport interface into separate classes. Thus the constructor of top level class LiquidCrystal requires you to provide an instance of a class implementing the ILiquidCrystalTransferProvider interface. This enables to use this library with all the methods of communication described above. In the source code you will already find an GpioLiquidCrystalTransferProvider and Shifter74Hc595LiquidCrystalTransferProvider for the 74HC595 shift register. Later I’m going to add support for the I2C port expander. I got a nice LCD backpack from JeeLabs shop that uses the MCP23008 chip but I don’t know yet how much different it is from Pavel’s PCF8574P. In preparation for this some common bit handling code is already abstracted in the BaseShifterLiquidCrystalTransferProvicer class.

Here you can see the wiring I used:

Wiring 16x2 LCD to Netduino via shift register

Notice that because this time I’m going to use SPI interface the serial data is connected to pin 11 (MOSI) and pin clock is connected to pin 13 (SPCK). Pin 10 is connected to the latch pin, and in the code it is passed as Slave Select pin to the SPIConfiguration object. Since we are going to use seven outputs from the shift register the one remaining output is connected via 2N2222A transistor to control the LCD backlight. This allows us to turn the backlight on or off from code. Finally the 10K potentiometer is used to control the display contrast.

_MG_1274Photo on the right shows the backpack I created for my LCD (I’ll cut the board later along the marked lines). Notice that because the board will be mounted “upside down” the outputs from the shift register to LCD are reversed, but it’s easy to correct it in the code (Shifter74Hc595LiquidCrystalTransferProvider constructor has the optional BitOrder option).

Below you can find a list of methods exposed by the LiquidCrystal class:

  • Begin(columns, lines) - Use this method to initialize the LCD. Specifies the dimensions (width and height) of the display.
  • Clear() - Clears the LCD screen and positions the cursor in the upper-left corner.
  • Home() - Positions the cursor in the upper-left of the LCD.
  • SetCursorPosition(column, row) - Position the LCD cursor; that is, set the location at which subsequent text written to the LCD will be displayed.
  • ScrollDisplayLeft() - Scrolls the contents of the display (text and cursor) one space to the left.
  • ScrollDisplayRight() - Scrolls the contents of the display (text and cursor) one space to the right.
  • Write(text) - Writes a text to the LCD.
  • Write(buffer, offset, count) - Writes a specified number of bytes to the display using data from a buffer.
  • WriteByte(data) - Sends one data byte to the display.
  • CreateChar(location, charmap)

And its properties:

  • Backlight - Turns the LCD backlight on or off.
  • BlinkCursor - Display or hide the blinking block cursor at the position to which the next character will be written.
  • ShowCursor - Display or hide the LCD cursor: an underscore (line) at the position to which the next character will be written.
  • Visible - Turns the LCD display on or off. This will restore the text (and cursor) that was on the display.
  • Encoding - Get or set the encoding used to map the string into bytes codes that are sent LCD. UTF8 is used by default.

Finally let’s look at the sample code. Here is a simple “hello world” demo:

public static void Main()
{
    // create the transfer provider
    var lcdProvider = new Shifter74Hc595LiquidCrystalTransferProvider(SPI_Devices.SPI1, 
        SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D10);

    // create the LCD interface
    var lcd = new LiquidCrystal(lcdProvider);

    // set up the LCD's number of columns and rows: 
    lcd.Begin(16, 2);

    // Print a message to the LCD.
    lcd.Write("hello, world!");

    while (true)
    {
        // set the cursor to column 0, line 1
        lcd.SetCursorPosition(0, 1);

        // print the number of seconds since reset:
        lcd.Write((Utility.GetMachineTime().Ticks / 10000).ToString());

        Thread.Sleep(100);
    }
}

You can download the source code for this project below. Please keep in mind that not all functions are implemented yet, and some other are not tested.

Update 2010-09-06: Eric D. Burdo figured out how to use this library with LCD from Seedstudio Electronic Brick Starter Kit. The connections were a little tricky but he shows the proper pin assignment for the GpioLiquidCrystalTransferProvider in his blog post. Thanks for sharing!

Update 2010-09-22: The library is now available on CodePlex at http://microliquidcrystal.codeplex.com/

Posted on Sunday, September 5, 2010 6:27 PM Development , Robotics , Electronics , .NET Micro Framework | Back to top


Comments on this post: .NET Micro Framework – Using alphanumeric LCDs

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Any chance you could help with building the ITransferProvider (or advice on how to do so) for the following LCD?

http://www.seeedstudio.com/depot/electronic-brick-lcd-162-characters-p-482.html?cPath=48_55
Left by Eric on Sep 06, 2010 3:40 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
For reference... I've figured out how to use the library and code provided above with the Seeeduino 16x2 LCD panel as well.

http://forums.netduino.com/index.php?/topic/281-seeeduino-lcd/
Left by Eric on Sep 06, 2010 10:14 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Hello, did you use some kind of specialized program to draw the wiring picture ? Or plain image editor ?
Left by Randoom on Sep 16, 2010 4:36 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Never mind, I found the answer in one of your previous posts : http://fritzing.org/
Left by Randoom on Sep 16, 2010 4:51 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Hi - On your backpack picture i can see a resistor, but can't find areference in the text. Can you tell me what its for please.
Many thanks
Left by Karashnaho on Nov 16, 2010 6:05 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
I've setup my 4x20 LCD exactly as Pete Brown have shown in "http://10rem.net/blog/2010/09/24/using-a-4x20-hd44780-controlled-lcd-display-with-the-netduino" and used his same code. When I write to the screen it displays on the rows in this order - 1,3,2,4 and then raps back around to write over row 1 again. What is going on? I have used Your Shift Register setup, using your exact chips and get the same result...

public static void Main()
{
// create the transfer provider
var lcdProvider = new GpioLcdTransferProvider(
Pins.GPIO_PIN_D12, // RS
Pins.GPIO_NONE, // RW
Pins.GPIO_PIN_D11, // enable
Pins.GPIO_PIN_D9, // d0
Pins.GPIO_PIN_D8, // d1
Pins.GPIO_PIN_D7, // d2
Pins.GPIO_PIN_D6, // d3
Pins.GPIO_PIN_D5, // d4
Pins.GPIO_PIN_D4, // d5
Pins.GPIO_PIN_D3, // d6
Pins.GPIO_PIN_D2); // d7

//Used with the Shift Register
//var lcdProvider = new Shifter74Hc595LcdTransferProvider(SPI_Devices.SPI1,
// SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_D10);

// create the LCD interface
var lcd = new Lcd(lcdProvider);

// set up the LCD's number of columns and rows:
lcd.Begin(20, 4);
lcd.ShowCursor = true;
lcd.BlinkCursor = true;

// Print a message to the LCD.
lcd.Write("Ready:");

InputPort button = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.PullUp);

while (true)
{
//// set the cursor to column 0, line 1
//lcd.SetCursorPosition(0, 1);

//// print the number of seconds since reset:
//lcd.Write((Utility.GetMachineTime().Ticks / 10000).ToString());

if (!button.Read())
{
//if (lcd.
lcd.Write("A");
}

Thread.Sleep(100);
}
}

Any help would be nice. Thank you for your time.
Left by Jay Sheldon on Jan 20, 2011 6:19 AM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
@Jay Sheldon

I have the exact same LCD as in the article you posted (bought from Hacktronics), and have the same issue. I'm using a FEZ Panda, but I had the same issue when using a Arduino Duemilanove. I discovered it has to do with how the memory is laid out in the 20x4 display. There is a real good article on why this occurs here: http://web.alfredstate.edu/weimandn/, under the LCD Addressing link. There is also a forum post on the Arduino forums discussing this issue and provides sample code to work around the issue (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1252901403/4).

It seems that manually setting the cursor position allows you to write to specific lines correctly, but word wrap will send the text in the line order 1,3,2,4. It should be possible to modify the Lcd class to account for this. I just discovered this library, so I haven't had a chance to dig in to any of the code yet to see how difficult it would be to modify it.
Left by Brady on Feb 23, 2011 2:23 AM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Was looking at this diagram http://schemecircuit.com/3-wire-serial-lcd-using-a-74hc595-shift-register/ and noticed with the ShifterSetup you added, we should be able to use this in a 2-wire control setup.

@Brady - Seeing some of the same issues with my 20x4, thanks for the link.
Left by Greg on Mar 11, 2011 7:41 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Szymon, This was a great post, thanks for publishing this. I am able to wire mine up per your wiring diagram however I want to make a backpack just like yours and it will require mounting the LCD "upside down" also. I am struggling with getting the reversed pin schema wired up. Do you have a wiring diagram for it?

Thanks,
--Jim Oxenhandler
Left by Jim Oxenhandler on May 22, 2011 3:03 AM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Awesome post! You really tipped me off on the codeplex project I would have never found. How did you make the wiring diagram? I love it too!
Left by Eric Falsken on Oct 30, 2011 4:15 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
H

I have a Netduino and I am planning on a project requiring LCD. Your guide is about as close as I have come to what needs doing, but when I compare your diagram showing the wiring, to the photo of your "backpack" I notice the backpack has some extra components (resistors etc)

Are these for additional components to your project, or have they been missed from the wiring diagram?.

Thanks in advance
Left by Alan on Nov 14, 2011 7:54 PM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
.NET Micro Framework Boards

The .NET Micro Framework is .NET for small and resource constrained devices. It offers a complete and innovative development and execution environment that brings the productivity of modern computing tools to this class of devices.

For current .NET developers, this means that they can now create applications that run on a range of devices from targeted devices like remote controls to PCs and Servers and on to the cloud – all with the same programming model and tools.

For current Embedded developers, this means that they can now leverage the productivity gains that have been achieved on the desktop and reduce their time to market.

The .NET Micro Framework is a fully integrated Visual Studio experience brings a reliable and productive development system to the embedded world.

The typical .NET Micro-Framework device has a 32 bit processor with or without a memory management unit (MMU) and could have as little as 64K of random-access memory (RAM). The .NET Micro Framework supports rich user experience and deep connectivity with other devices.

Such devices include: consumer devices, consumer medical, home automation, industrial automation, automotive, sideshow devices / PC peripherals.



to buy .NET Micro Framework Boards visit http://www.netmfdevices.com/eshop/products.php?21&sid=70198e2d5f1e12ef69cd68c24a5ec773

For more on what the.NET Micro Framework is, please go to www.microsoft.com/netmf.
Left by Netmfdevices on Feb 21, 2012 10:49 AM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
Thanks for the thorough explanation of the setup, I was up and running on my Netduino very quickly!
Left by Andrew on Sep 29, 2014 6:38 AM

# re: .NET Micro Framework – Using alphanumeric LCDs
Requesting Gravatar...
I have this correctly wired and have correctly implemented the library referenced here "Update 2010-09-22: The library is now available on CodePlex at http://microliquidcrystal.codeplex.com/" however 80% of the time the LCD displays random characters. Whats the deal with this?
Left by Tim on Mar 10, 2016 7:27 PM

Your comment:
 (will show your gravatar)


Copyright © Szymon Kobalczyk | Powered by: GeeksWithBlogs.net