raspberry-sharp/raspberry-sharp-io

Hd44780 - displaying random characters

Mythandar opened this issue · 1 comments

I've got my 16x2 display setup as it's listed in the test program for it. It basically just displays your mac address and ip address for all your devices connected to the pi, then it repeats. However when I run it I usually get random characters that have nothing to do with what was actually sent to the display. sometimes it'll display the correct characters for part of a line but jibberish after that. I write a test program of my own and if I keep the write short to 3 characters it will usually display it properly. As example expected out put of "did" is usually "did", but sometimes it just displays a "d" on the second line. asking for a "123456789" to be displayed will result in something like "125Y8" or something like that . It's rarely the same jibberish that it displays for each expected output, multiple attempts at the same output give different results.

in Hd44780LcdConnection.cs I had to make the following changes to get things to work.

From:
private void WriteByte4Pins(int bits, bool charMode)
{ pins.RegisterSelect.Write(charMode);
pins.Data[0].Write((bits & 0x10) != 0);
pins.Data[1].Write((bits & 0x20) != 0);
pins.Data[2].Write((bits & 0x40) != 0);
pins.Data[3].Write((bits & 0x80) != 0);
Synchronize();
pins.Data[0].Write((bits & 0x01) != 0);
pins.Data[1].Write((bits & 0x02) != 0);
pins.Data[2].Write((bits & 0x04) != 0);
pins.Data[3].Write((bits & 0x08) != 0);
Synchronize(); }

To:

private void WriteByte4Pins(int bits, bool charMode)
{ pins.RegisterSelect.Write(charMode);
pins.Data[0].Write((bits & 0x10) != 0);
Timer.Sleep(syncDelay);
pins.Data[1].Write((bits & 0x20) != 0);
Timer.Sleep(syncDelay);
pins.Data[2].Write((bits & 0x40) != 0);
Timer.Sleep(syncDelay);
pins.Data[3].Write((bits & 0x80) != 0);
Timer.Sleep(syncDelay);
Synchronize();
pins.Data[0].Write((bits & 0x01) != 0);
Timer.Sleep(syncDelay);
pins.Data[1].Write((bits & 0x02) != 0);
Timer.Sleep(syncDelay);
pins.Data[2].Write((bits & 0x04) != 0);
Timer.Sleep(syncDelay);
pins.Data[3].Write((bits & 0x08) != 0);
Timer.Sleep(syncDelay);
Synchronize(); }

Maybe it was just my lcd screen but the bits didn't seem to get written in the correct order, this just forces a little time between each one. Works fine for me now.