TIP: GHI Character Display Module with mBuino

Wanted to share my experience, for any folks wanting to use the GHI Character Display Gadgeteer module with the mBuino.

To wire up the module, get yourself an Extender or Breakout module (https://www.ghielectronics.com/catalog/category/510), and connect as follows:
[ul]
rs (Gadgeteer pin 4) to pin P0.10
e (Gadgeteer pin 3) to P0.9
D4 (Gadgeteer pin 5) to P0.15
D5 (Gadgeteer pin 7) to P0.11
D6 (Gadgeteer pin 9) to P0.13
D7 (Gadgeteer pin 6) to P0.18
Gadgeteer pin 2 to external 5V supply (mBuino does not appear to supply enough current, at least not in my tests)
Gadgeteer pin 10 to ground (make sure this connects to ground on both the external 5V power supply and the mBuino)
A note on Gadgeteer pin 8, which controls the backlight. I found that this only worked if I fed this pin 5V from the external power supply. I think that’s the right way to do it, but since this is my first go-round with this display on mBuino, I welcome feedback on this point.[/ul]

Here’s the code, which leverages the very easy-to-use TextLCD library by Simon Ford. If you don’t plan to use serial debugging over USB, you can remove the USBSerial declaration and printf statements. To use the code below, you’ll need to create a program in the mBed online compiler, and import the mbed, TextLCD, and USBDevice libraries, then create a file (I called mine main.cpp) in the root, and copy the code below into that file.

#include "mbed.h"
 #include "TextLCD.h"
 #include "USBSerial.h"

USBSerial pc;

TextLCD lcd(P0_10, P0_9, P0_15, P0_11, P0_13, P0_18); // rs, e, d4-d7

int main() {
    pc.getc();
    pc.printf("Initializing...\r\n");
    wait(2);
    
    pc.printf("Writing Hello, World! to char display...\r\n");
    lcd.printf("Hello World!\n");
    wait(2);
    pc.printf("Text written to char display...\r\n");

    pc.printf("Writing mBuino rocks! to char display...\r\n");
    lcd.printf("mBuino rocks!");
    wait(2);
    pc.printf("Text written to char display...\r\n");
}
4 Likes

Forgot the action shot…mBuino is out of the frame.

Used a USB Client DP module for power, connected to @ GMod’s breadboard module to feed the 5V and connect the grounds.

1 Like

@ devhammer - Congratulations!

Perhaps you can share your program and tips on mbed.org?
I have an LCD shield for Arduino laying around. Perhaps I can connect it in a similar way. It will probably need a level converter…

That’s a good idea. Will do that once I figure out why the code isn’t working for me when powered from the 5V pin on the mBuino instead of from USB. :-[

…and as soon as I posted that, I figured it out.

Program was crashing without USB because I still had the USBSerial debug code enabled. Once I commented that stuff out, it worked fine on power into the 5V pin.

Sometimes, it’s the obvious solution that works. :slight_smile:

Your request has been granted!

Let me know how it goes for you…

3 Likes

OK, now that I’ve published my code, here’s a question for those with more experience with HD44780-based displays.

When I run the program on mBuino via USB connected to my PC, the text always comes out correct. However, if I run the program by powering mBuino via the 5V in pin, the first run always results in garbled text (some of the text comes out OK, but shifted right, and some characters are missing or garbled). If I reset the mBuino several times, eventually the text comes out right.

I also get a flashing cursor, shows up every time on power up, but only occasionally after a reset.

The code is super-simple, so I’m thinking it must have something to do with power. I’ve tried powering both from a 9V battery with a barrel jack adapter, plugged into the USB Client DP module, as well as with a large rechargeable battery pack (4x 3.7V 3300 mAh), and also gave it a shot with my wall wart at 9V 1A, so I’d be surprised if the issue is voltage drop or lack of current.

Any ideas why I’m seeing this behavior? Is there something I’m not doing at startup that I should be? I see that the Roulette code uses putc to write text character by character…is that a more reliable means of using the TextLCD library?

Sigh…once again, as soon as I’ve posted the question, I figure out the answer. ::slight_smile:

Apparently, according to this thread:

http://developer.mbed.org/forum/mbed/topic/607/?page=1#comment-3065

the issue is that some displays are slower to initialize, so I changed line 34 in the constructor in TextLCD.cpp from:



to:


```cpp]wait_ms(45);        // Wait 45ms to ensure powered up[/code


and the text now displays correctly each time, even on external power.

UPDATE: Spoke too soon...if I turn the power off, and then back on again, display shows the text correctly. But if I leave the power off for several minutes, and try again, I get the garbled text on the first run, along with the blinking cursor. A couple of presses of the reset button, and it displays properly.

Another test I ran was powering up everything but the mBuino first, and then powering up the mBuino after, and that always seems to give me the proper text the first time, even after a few minutes with the power off.

So...still seems like it might be a power issue. Perhaps the backlight is drawing enough current to corrupt the program on the initial run?