Arduino / LCD Serial and Parallel Communications Questions - Page 1
Forum section: electronics / general

author: Electro Fan
author_rank: Super Contributor
timestamp: October 02, 2015, 07:45:25 pm
content: 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.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!

author: retrolefty
author_rank: Super Contributor
timestamp: October 02, 2015, 08:09:55 pm
content: 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/LiquidCrystalConstructorhttps://www.arduino.cc/en/Reference/LiquidCrystal

author: newbrain
author_rank: Super Contributor
timestamp: October 02, 2015, 08:10:18 pm
content: Quote from: Electro Fan on October 02, 2015, 07:45:25 pmIt'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: 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...

author: kolbep
author_rank: Frequent Contributor
timestamp: October 02, 2015, 08:14:50 pm
content: it sends the data as 2 4 bit nibbles one after the otherGood info on intelligent LCDs :http://www.epemag.wimborne.co.uk/lcd1.pdfhttp://www.epemag.wimborne.co.uk/lcd2.pdf

author: obiwanjacobi
author_rank: Super Contributor
timestamp: October 02, 2015, 08:34:24 pm
content: 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-/161245616356Saves a lot of pins should you run out.

author: Electro Fan
author_rank: Super Contributor
timestamp: October 02, 2015, 09:08:58 pm
content: Quote from: newbrain on October 02, 2015, 08:10:18 pmDL = 1: 8 bits, DL = 0: 4 bitsN = 1: 2 lines, N = 0: 1 lineF = 1: 5 ´ 10 dots, F = 0: 5 ´ 8 dotsOk, 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).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!

author: Electro Fan
author_rank: Super Contributor
timestamp: October 02, 2015, 09:18:18 pm
content: Quote from: kolbep on October 02, 2015, 08:14:50 pmhttp://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.

author: Electro Fan
author_rank: Super Contributor
timestamp: October 02, 2015, 09:24:59 pm
content: Quote from: obiwanjacobi on October 02, 2015, 08:34:24 pmThanks.I was looking at this:http://www.ebay.com/itm/USB-to-SPI-I2C-UART-TTL-ISP-Multifunction-USB-serial-communication-RS232-/290928293979?hash=item43bcad785bEarlier 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.

author: ralphd
author_rank: Frequent Contributor
timestamp: October 02, 2015, 10:22:16 pm
content: http://nerdralph.blogspot.ca/2014/07/controlling-hd44780-displays.html

author: Electro Fan
author_rank: Super Contributor
timestamp: October 02, 2015, 11:01:03 pm
content: Quote from: ralphd on October 02, 2015, 10:22:16 pmWow, Ralph - Hitachi should hire you.Thanks for the excellent work and for sharing here.EF

author: Electro Fan
author_rank: Super Contributor
timestamp: October 03, 2015, 01:04:26 am
content: Ok, new question: is it possible that the four signals are operating at different frequencies?

author: Hideki
author_rank: Frequent Contributor
timestamp: October 03, 2015, 02:29:02 am
content: 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 nowThey 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!

author: Electro Fan
author_rank: Super Contributor
timestamp: October 03, 2015, 03:13:34 am
content: Quote from: Hideki on October 03, 2015, 02:29:02 amHi 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. Seriously, I saw yourface 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! EFPS, 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".

author: Hideki
author_rank: Frequent Contributor
timestamp: October 03, 2015, 02:14:14 pm
content: 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.

author: MrAl
author_rank: Super Contributor
timestamp: October 04, 2015, 03:36:44 pm
content: 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 :-)

author: Electro Fan
author_rank: Super Contributor
timestamp: October 04, 2015, 08:19:01 pm
content: 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 sureI might be back to you with some questions on theseAl, 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 doubtThe 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, EFIn the meantime, I'm studying this: