Read data from LCD (4-bit mode)

Hi everyone! Let’s see if you can help me in something!
This is the situation:

  • I’ ve got an electronic device, which I want to copy the data that is printed on the display to an Arduino Due.
    I haven’t got any kind of control with this device, I just can connect the wires from the LCD to the Arduino. The LCD is a 16x2char working in 4-bit mode.

I’ ve started using the Serial Monitor just to watch the D4-D7, E, RS, RW.. bits and it seems that the Arduino gets that bits. So, know I need to convert them I guess using any ASCII library or code and much more.

I’ve been searching on the web and I didn’t find any project similar to this, so, I come here to see if anyone can help me. Do you know any library to do this or any piece of code? I just want to save some time if I have to write the entire algorithm.

If you know which controller is on the LCD, you can download the datasheet; that should make things quite clear.

sterretje:
If you know which controller is on the LCD, you can download the datasheet; that should make things quite clear.

Thanks for your reply. This is another problem, I can't confirm which controller has, but I guess (watching the bits secuence) that it's the Hitachi HD44780 or similar.

You are not likely to find a library to do what you are contemplating.

In order to write your own code you will have to completely understand the syntax of the information that is being sent to the LCD controller.

The best way to learn that syntax is to write your own code and the best way to learn how to do that is to study some well documented code that already exists. The need for documented code pretty much rules out the Arduino libraries.

You might want to look at the LCD Programming Examples at http://web.alfredstate.edu/weimandn .

Don

Don, thanks for that link (bookmark). I was going to suggest to reverse engineer the LiquidCrystal Library.

floresta:
You are not likely to find a library to do what you are contemplating.

In order to write your own code you will have to completely understand the syntax of the information that is being sent to the LCD controller.

The best way to learn that syntax is to write your own code and the best way to learn how to do that is to study some well documented code that already exists. The need for documented code pretty much rules out the Arduino libraries.

You might want to look at the LCD Programming Examples at http://web.alfredstate.edu/weimandn .

Don

Thank you Don! I' ll consider that.

Sounds like you are wanting to snoop the hd44780 signals and attempt to recreate the display information.
While it sounds seductively simple, it can actually be quite challenging to nearly impossible depending on the host behavior and the data pin signals validity timing given the potential timing of the E signal and how fast the host is updating the LCD.

I have seen a few people on the forum attempt to do this unsuccessfully.

The RS, and RW signals are only valid while E is high but.... the data signals d4-d7 are not guaranteed to be valid when E first goes high - there is no requirement for the data signals to be stable when E is raised.

So you can't just look for E rising or to be high and grab the signals since there is no way to know when the data signals are valid.

All the signals (control and data) are valid when E falls from high to low, but they are not guaranteed to be valid for more than a few tens of nanoseconds after E goes low.

This can potentially make it impossible to snoop the hd44780 signals using only s/w that monitors the pins.
It is definitely impossible using Ardino digital i/o functions like digitalRead().
Even using raw port i/o can be quite difficult depending on the host behavior and its timing.

If you are very lucky, the host is slow and it either sets up the data signals before raising E, or leaves them valid for quite some time after dropping E to allow time for the signals to easily snooped.

The safest thing to do would be use some sort of latch that latches the signals when E is lowered (just like what the hd44780 chip is doing), and then use the falling E to also send an interrupt to the AVR and then read the signals and very quickly save it to get ready for the next nibble.

And I would highly recommend that you have a logic analyser so you can look at the signals to see how the host behaves before you go too far down any particular path.
By knowing how the host behaves and controls the signals, you will know the timing and know if it is possible to poll the signals directly if you will need additional latching hardware.

--- bill

I agree with everything that Bill has pointed out.

The statement "the data signals d4-d7 are not guaranteed to be valid when E first goes high" is absolutely correct and bears some further explanation.

Although the data sheet shows the data lines being set up after E is high an examination of the timing information shows that it is permissible to set them up while E is still low.

As it turns out it is common practice to set up the data lines along with RS and RW and then 'pulse' E, so you are very likely to find that this is the case when you examine your device.

Don

floresta:
As it turns out it is common practice to set up the data lines along with RS and RW and then 'pulse' E, so you are very likely to find that this is the case when you examine your device.

Where it can get really tough is if you are trying to decode an interface where the host is doing reads as well as writes.

In this situation, you can't look at R/W until E is high to decide if it is a read or a write.

If it is read, then the data bus is not guaranteed to valid until after tDDR and then it is only valid until E goes low + tDHR (5ns)
and E is only guaranteed to be high for for PWEH.
So worst case you only have PWEH - tDDR + tDHR to look at the data lines after E goes high.

In the wide range voltage timing: (page 49 of spec)
tDDR is 360ns
PWEH is 450 ns
so worst case you only have 450 - 360 + 5 = 95ns

In the 4.5v voltage timing: (page 52 of spec)
tDDR is 230ns
PWEH is 160 ns
so worst case you only have 230 - 160 + 5 = 75ns

Snooping reads can be really tough and could likely require hardware assist depending on the actual timing of the host.

There is a old thread from a few years ago about doing this type of snooping.
It was for snooping a coffee pot display in an attempt to give the information off to some type of home automation.
Unfortunately the Arduino site does not have any type of search capability so finding it can be difficult.
This is the only forum I've ever used that does not have a search.
(using an external google search doesn't count)

But there is a lengthy discussion, about it between Crossroads and myself.
I think he ended up trying to use some external h/w and even posted some schematics.
I can't remember if it ever worked.

--- bill

Ok,
So after having to do some google searches because there is no search on this forum:
the thread with CrossRoads was for a ks0108 glcd.
It has similar issues since the host interface is similar, but it is much more difficult than an hd44780 display as there is much more data and the clocking of the interface is typically much faster given the amount of data needed to be transferred.
http://forum.arduino.cc/index.php?topic=87027

--- bill

Thank you very much Bill and Don! I' ll study all you said here. We'll see if I can do something...

Unfortunately the Arduino site does not have any type of search capability so finding it can be difficult.
This is the only forum I've ever used that does not have a search.

The search function is cleverly concealed at the upper right. It's green on green (both the same shade of green) and not immediately apparent.

Don

floresta:
The search function is cleverly concealed at the upper right. It's green on green (both the same shade of green) and not immediately apparent.

Don

Let me be more specific.
While the Arduino forum does have a "search" capability, it is not handled internally by the forum s/w, like every other forum out there - standard forum s/w packages include a real search capability.
Yeah you can do searches using that little search function, but it sucks since it is based on a google search and hence has no knowledge of forum attributes.
The forum used to have a real search back when it ran standard forum s/w, but then
a few years ago, the Arduino team, decided that they would abandon the standard off the shelf forum s/w and modify it with their changes and "enhancements".
For MANY months the forum was very broken, and ever since that time, the search capability was removed and it was turned into a google search.
This makes finding things more difficult since there are many things that you simply cannot do with a google search that you can with a real forum search.

To this day I have no idea why the Arduino team decided to spend their resources re-writing forum code that seems to be working ok for everyone else.

--- bill

Hi guys!

I've great news (for me)! I succeed! Thanks a lot for your info and expertise, it helped me a lot to understand how the controller works.

After some tries, I realized that is better to directly read the DDR/PORT/PIN registers instead of using digitalRead(). And it seems there is no problem about the Enable times, because I've used it as an interrupt and it works great.

I just connect the DB4-DB7, EN and RS to the digital pins (PORTD), declare them as inputs, use an attachInterrupt to check the EN and read the data pins. Then in the loop it checks on the ASCII table and print it to Serial.

Thank you very much!

Adrià.

Good job! Thanks for letting us know how you made out.

Don

Hi adriamartinez
I'm looking to do what you have done.
Is it possible to get a copy of your code?
Thank you.

Mikkel

Hi adriamartinez,

I too am very interested in a copy of your code.
I have a similar situation, a 4x20 LCD connected to a old machine that i would love to get the data off of.
The poor thing is running off of a 65C02 (6502 variant). I can't change the programming of it, though i wish i knew enough too.

My ultimate goal is to post it to either a webpage served from an Arduino or ESP8266, or as a terminal/telnet.
I basically just want to replicate whats on the display and be able to see that from a terminal or telnet or webpage.

Thanks for your help and hard work!!
-Ian

Hi
Can you show the drawing ?

Hi, I've been reading and googling this for quite a bit, no luck finding something useful. Since you said you got it to work, can you post some of the code and a schematic of how you got it? Thank you. I'm trying to intercept data from an lcd connected to this microcontroller from Texas Instruments

Thank you

Hi adriamartinez,
Can you share what you have done?