Author Topic: Arduino / LCD Serial and Parallel Communications Questions  (Read 8343 times)

0 Members and 1 Guest are viewing this topic.

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Arduino / LCD Serial and Parallel Communications Questions
« on: October 02, 2015, 07:45:25 pm »
I'm trying to understand how LCDs (such as the Hitachi HD44780) and the Arduino Uno play together.  I'm also trying to learn/experiment with the tradeoffs between serial and parallel communications. (I have a digital scope and a logic analyzer and I'd like to observe the signals in the process of learning; both the scope and the LA can decode basic protocols.)

I've made a simple project with the Uno and the HD44780 as follows:
https://blog.adafruit.com/2012/12/14/tutorial-arduino-lesson-11-lcd-displays-part-1-2/
I can change the text and upload the text to the LCD, no problem.

On the other hand, I found this (very helpful) tutorial on the LCD pins and their functions:

- in this video it says that LCD pins 7-14 receive parallel bits D0-D8. 

In the Adafruit project LCD pins 7-10 are not used - which leads me to believe that the text from the Uno is sent via some other route (serially?).

So, a couple questions:

1. What are pins/routes/techniques that are used for sending the text (any associated clocking) from the Uno to the LCD in the Adafruit project?  (I'd be especially interested to learn to use I2C and/or SPI).

- I've spent a fair amount of time probing the pins with my scope (and researching web articles) and the answers seem to be just beyond my reach.  I think I get some of the concepts, but I need a few more specifics and some guidance, no doubt.  |O :palm:

2. What is an easy way - either with the Uno or without the Uno - to send text to the LCD via the LCD's 8 parallel pins?

If anyone has any explanations or links to relevant info please post any suggestions.  Thanks!
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #1 on: October 02, 2015, 08:09:55 pm »
The Arduino site has a reference section that contains many of the more popular support libraries. The one supporting HD44780/LCD display is in there. Basically an arduino can operate the display controller in either a 4 bit mode or 8 bit mode. That is a basic design decision a user makes depending on if pins are available or speed more important.


https://www.arduino.cc/en/Reference/LiquidCrystalConstructor

https://www.arduino.cc/en/Reference/LiquidCrystal
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #2 on: October 02, 2015, 08:10:18 pm »
1. What are pins/routes/techniques that are used for sending the text (any associated clocking) from the Uno to the LCD in the Adafruit project?  (I'd be especially interested to learn to use I2C and/or SPI).

- I've spent a fair amount of time probing the pins with my scope (and researching web articles) and the answers seem to be just beyond my reach.  I think I get some of the concepts, but I need a few more specifics and some guidance, no doubt.  |O :palm:

It's fun to experiment (in safety), but when something is not clear it's good to refer to datasheets.
Since you know the LCD controller chip is 44780, why not check one and trying to understand why you can make do without 4 bits of the data bus?

The data sheet is, 1st hit on google, at: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf.

I don't want to spoil the pleasure of discovery, so I'll just give you a hint  >:D: look at instruction code (B7-0): 0 0 1 DL N F - - on page 24, and read from the beginning of the chapter. Not a masterwork of clarity, but can be understood...
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline kolbep

  • Frequent Contributor
  • **
  • Posts: 598
  • Country: za
    • ShoutingElectronics.com
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #3 on: October 02, 2015, 08:14:50 pm »
it sends the data as 2 4 bit nibbles one after the other

Good info on intelligent LCDs :
http://www.epemag.wimborne.co.uk/lcd1.pdf

http://www.epemag.wimborne.co.uk/lcd2.pdf
====================================
www.ShoutingElectronics.com Don't just talk about Electronics, SHOUT ABOUT IT! Electronics Blog Site and Youtube Channel
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #4 on: October 02, 2015, 08:34:24 pm »
Look at page 45 and 46 of the datasheet. The way you initialize the display is different for 8-bits or 4-bits data operation. Also take note of the delay times between each initialization step - you have to give the controller on the display time to get things sorted.

There are also little boards you can buy that let you clock in the data bits for each line over I2C.
http://www.ebay.com/itm/IIC-I2C-TWI-SPI-Serial-Interface-Board-Module-Port-for-Arduino-1602LCD-Display-/161245616356

Saves a lot of pins should you run out.

[2c]
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #5 on: October 02, 2015, 09:08:58 pm »
1. What are pins/routes/techniques that are used for sending the text (any associated clocking) from the Uno to the LCD in the Adafruit project?  (I'd be especially interested to learn to use I2C and/or SPI).

- I've spent a fair amount of time probing the pins with my scope (and researching web articles) and the answers seem to be just beyond my reach.  I think I get some of the concepts, but I need a few more specifics and some guidance, no doubt.  |O :palm:

It's fun to experiment (in safety), but when something is not clear it's good to refer to datasheets.
Since you know the LCD controller chip is 44780, why not check one and trying to understand why you can make do without 4 bits of the data bus?

The data sheet is, 1st hit on google, at: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf.

I don't want to spoil the pleasure of discovery, so I'll just give you a hint  >:D: look at instruction code (B7-0): 0 0 1 DL N F - - on page 24, and read from the beginning of the chapter. Not a masterwork of clarity, but can be understood...

DL = 1: 8 bits, DL = 0: 4 bits
N = 1: 2 lines, N = 0: 1 line
F = 1: 5 ´ 10 dots, F = 0: 5 ´ 8 dots

Ok, so it looks like the LCD is set for 4 bit DataLengths instead of 8.  I probably should of/could of figured this out because I could see what looked like data Bytes when I probed LCD pins 7-10.  (And it does seem that much advice throughout all the EEV forums is Read The Fine (Manual, Spec Sheet, etc). Lesson learned....maybe  |O :palm:).

BTW, I appreciate you being concerned about not spoiling the pleasure of discovery - such pleasure is a tremendous intrinsic incentive in the study of EE, I am certain.  Having recognized that, it's somewhat like not wanting to hear the ending of a particular episode of a good TV series before watching all the way to the end - and I'd certainly not want to fast forward through each of the episodes and get to the end of the season without savoring all the episodes, but at the rate I'm going I might need about a million seasons to get somewhere - so an occasional episode on fast forward is probably A-OK :), no worries.  Thanks!
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #6 on: October 02, 2015, 09:18:18 pm »
it sends the data as 2 4 bit nibbles one after the other

Good info on intelligent LCDs :
http://www.epemag.wimborne.co.uk/lcd1.pdf

http://www.epemag.wimborne.co.uk/lcd2.pdf

http://www.epemag.wimborne.co.uk/lcd1.pdf
- Thanks.  The layout in Figure 2 looks like a very good way to experiment/learn with the LCD sans the microcontroller.  I've seen some similar projects for shift registers - you can do them with a microcontroller of course, but without the microcontroller seems to be a good first step.  Thx again.
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #7 on: October 02, 2015, 09:24:59 pm »
Look at page 45 and 46 of the datasheet. The way you initialize the display is different for 8-bits or 4-bits data operation. Also take note of the delay times between each initialization step - you have to give the controller on the display time to get things sorted.

There are also little boards you can buy that let you clock in the data bits for each line over I2C.
http://www.ebay.com/itm/IIC-I2C-TWI-SPI-Serial-Interface-Board-Module-Port-for-Arduino-1602LCD-Display-/161245616356

Saves a lot of pins should you run out.

[2c]

Thanks.

I was looking at this:
http://www.ebay.com/itm/USB-to-SPI-I2C-UART-TTL-ISP-Multifunction-USB-serial-communication-RS232-/290928293979?hash=item43bcad785b

Earlier it was listed as including a cable (I'm sure the cable could be made).

Seems like something along these lines would be a good test bed for learning I2C and SPI.
 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #9 on: October 02, 2015, 11:01:03 pm »
http://nerdralph.blogspot.ca/2014/07/controlling-hd44780-displays.html

Wow, Ralph - Hitachi should hire you.
Thanks for the excellent work and for sharing here. :-+ :-+
EF
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #10 on: October 03, 2015, 01:04:26 am »
Ok, new question:  is it possible that the four signals are operating at different frequencies? 
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #11 on: October 03, 2015, 02:29:02 am »
What four signals? Are you talking about the four (or eight) data signals again? In which case it's a strange question -- but we are used to them by now :)

They are data signals... if the display is just sitting there displaying something and you don't send anything to it, the data doesn't change, the signals don't change either, and there is no "frequency".

When you are sending something, you are in full control over them. They are not operating on their own at different frequencies. They have to all be set up before you toggle the E line to clock in the data. If you were to measure them, the result would depend on what is being sent and how often.


Regarding the ebay item: If you can read chinese and want to rely on boards that can "Various brush Airport together" (their words), it's your choice. Good luck!
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #12 on: October 03, 2015, 03:13:34 am »
What four signals? Are you talking about the four (or eight) data signals again? In which case it's a strange question -- but we are used to them by now :)

They are data signals... if the display is just sitting there displaying something and you don't send anything to it, the data doesn't change, the signals don't change either, and there is no "frequency".

When you are sending something, you are in full control over them. They are not operating on their own at different frequencies. They have to all be set up before you toggle the E line to clock in the data. If you were to measure them, the result would depend on what is being sent and how often.


Regarding the ebay item: If you can read chinese and want to rely on boards that can "Various brush Airport together" (their words), it's your choice. Good luck!

Hi Hideki,

Ok, first things first.

Regarding "Various brush Airport together" I am glad to learn where that came from.  I'd seen that referenced around here and I didn't understand it - but now I get it, I think.  All I know is that the folks I've bought stuff from in China speak a lot better English than I speak Chinese.

Next up, regarding my strange questions - I resemble that remark  :-DD.  Seriously, I saw your :) face and I know it was meant with good affection - not to get too weird here. ;)  Seriously, I appreciate you and everyone else putting up with my homemade self-study curriculum and learn a step at a time pace.

On to some content - I simply probed the four pins D4-D7 on the LCD (which I also observed with my LA which lets me see when the four pins/signals go high and low relative to one another).  To be square (no pun intended), I'm not sure what I expected to see on these four pins.  I probed these after having uploaded a sketch from the IDE to the Arduino - which results in some text displayed on the LCD.  After the upload was completed was when I probed the pins with the scope and observed the signals on the pins with the LA.  I assumed that these signals represented four of the eight bits needed to send the characters (text) to the LCD. 

I studied Table 14 on the Hitachi datasheet:
https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
- what it shows is that characters are made up of Upper 4 Bits and Lower 4 Bits.  So, using my LA's ability to aggregate 4 single bit waveforms (with each waveform showing transitions between 1s and 0s), I setup the Group function so that the 4 bits were summed to represent a 4 bit Byte; at that point I tried setting triggers to find any proximities between what might have been Upper Bytes and Lower Bytes in a valiant effort to see if I could detect combined 8 bit Bytes that could possibly be the ASCII characters rendered on the LCD.

I know, crazy, but so far it's been a good day.  I even figured out how to change a fuse on the Atmega (more on that later).

Anyway, back to the 4 signals that I measured at the 4 pins - the frequencies I saw were after the sketch had been uploaded to the Arduino and displayed on the LCD.  Not text was changing - so I don't know why there would be activity or what activity would be on those 4 lines - unless (I thought, perhaps) the text is continually refreshed from the Uno to the LCD.  In the process of trying to figure how the text moves from the Uno to the LCD I measured the frequencies (after the upload from the IDE to the LCD).

That's my story (so far on this project) and I'm sticking to it.  Questions/comments/suggestions all welcome.  Thanks!  EF

PS, there is definitely activity on the 4 LCD (D4-D7) pins - even after the sketch has been sent from the IDE to the Uno to the LCD.  The first image below (from the Logic Analzyer) shows a triggered state but when the trigger is off there are continuous transitions on all 4 pins/lines/bits.  Silly me, but I surmised that since there are 4 pins - each carrying 1 bit (toggling high and low), and since the LCD supposedly combines two 4 bit Bytes into one 8 bit Byte, that perhaps every fourth 4 bit Byte would be the companion Upper and Lower Bytes.  It turns out in the Logic Analyzer screen shot that we happen to have the two 4 bit Byte sequences - 4 Bytes part - that make up the letter "I" which -- happens to be one of the characters from the sketch that is displayed on the LCD.  You can see 1001 at the A cursor and 0100 at the T (trigger).  I know.... "strange".
 
« Last Edit: October 03, 2015, 03:56:56 am by Electro Fan »
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #13 on: October 03, 2015, 02:14:14 pm »
You are missing two important signals to make sense of the data.

* The first is the RS (Register Select) signal, which tells the display if the data you send is a command or data (like text) to be displayed.

* The second is the E (Enable) signal used to clock in the data. If you're not looking at that signal, you will miss any time when two equal 4-bit data is clocked in, because the data will not change.
 

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1440
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #14 on: October 04, 2015, 03:36:44 pm »
Hello there,

The two 4 byte data groups are clocked into the LCD controller chip one at a time, and there is another signal that you will see comes after the data is set up on the 4 data lines.

For true serial comm, there will be a chip between your Uno and the LED pins you are observing now.  That chip will take in 8 bits in sequence from the 328 chip on the Uno and sent them either 4 at a time or all 8 at once.  So your Uno only has to send 1 bit at a time then, which requires less pins.

There are several serial comm protocols however, two of the most common are SPI and I2C.
The 8574 controller chip is a common one, and that converts I2C into parallel to drive the LCD board.

One nice thing about I2C is you can control several LCD displays using not only one microcontroller, but only 2 pins from that microcontroller.  Yes, you read that right :-)
With only two pins you can control 8 LCD display boards.  That's because you can set each of the 8 displays to a different 'address'.  This address is usually jumper selected on each 8574 adapter board and you have to set each address to a different value with these three jumpers.  The program code then addresses whatever LCD display you tell it to, and writes only to that one.  All 8 displays from only 2 pins from the Uno (or 328 chip).  Of course you still have to supply +5 and ground, and be sure to have enough current available to drive all 8 display backlights.

I2C is pretty interesting in itself, but to understand that you should look it up not try to figure it out with the scope.  Scope's are great, but to piece together a complicated protocol could take hours, days, weeks, even months.  Lucky though there are only 2 lines: clock, and data.

I am telling you these things so that you dont have to spend too much time on the mundane but rather can get right into creating a nice project.

Have fun :-)
 

Offline Electro FanTopic starter

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino / LCD Serial and Parallel Communications Questions
« Reply #15 on: October 04, 2015, 08:19:01 pm »
Hideki and Al - Thanks.

Hideki I will pay more attention to RS and E and see if that helps me sort things about better - good tips to pay attention to all the relevant signals, I'm sure :)
I might be back to you with some questions on these  :)

Al, that is very good write-up.

The thing is that I'm not building stuff so much as trying to learn stuff.  I "assemble" a few things here and there on breadboards and with Arduinos, etc. but I try to test and measure because it helps me observe and learn whether what I expect to see is what I actually find, and most importantly to see if any of that correlates to documentation on the web and advice here.  So, it's a process of building, testing, and learning - but most things that get built are just a byproduct of the process and learning is the goal.

Toward that end, I appreciate your comment that piecing together protocols could take a lot of time, no doubt  :palm:
The good news is that I'm enjoying it - but I wouldn't mind going faster.

So.... what I'd really like to understand better is I2C (and also SPI).

Yesterday I put this together: 



It's just a couple Unos talking to each other but it gave me a stable/predictable I2C setup that I can observe on the LA and the scope but if you guys have some better suggestions on ways to get gently/gradually better immersed in I2C I'm up for it.

Thanks, EF

In the meantime, I'm studying this:

« Last Edit: October 04, 2015, 08:27:23 pm by Electro Fan »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf