Author Topic: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting  (Read 19111 times)

MJLorton

  • Administrator
  • Hero Member
  • *****
  • Posts: 817
Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« on: September 20, 2013, 09:42:31 AM »
A tutorial on interfacing LCDs (liquid crystal displays) with Arduino. We take a look at libraries and the role they play...and the potential issues, errors and troubleshooting involved.
We look at several types of displays but concentrate on the 4x20 Sparkfun serial enabled LCD display.

Link to the video: https://www.youtube.com/watch?v=X1BCvjxIDHM

I've attached the SparkSoftLCD library by C. A. Church - fixes issue with float variables on serial enabled LCD displays. I've added the change that avoids the compiling errors / issues in the later versions of the Arduino software / IDE.


SparkFun kit from my Amazon Store:
http://astore.amazon.com/m0711-20?_encoding=UTF8&node=33


Link to new Arduino software /  IDE 1.0.5:
http://arduino.cc/en/main/software

Link to the LiquidCrystal library with examples and wiring:
http://arduino.cc/en/Tutorial/LiquidCrystal

Link to the SparkFun SerLCD 2.5 datasheet:
https://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.PDF

Link to the Hitachi HD44780U dot-matrix liquid crystal display controller datasheet:
https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

SparkFun LCD displays:
https://www.sparkfun.com/categories/76?page=all

How to install Arduino libraries / Installing Additional Arduino Libraries:
http://arduino.cc/en/Guide/Libraries

How to create a library for Arduino / Writing a Library for Arduino:
http://arduino.cc/en/Hacking/LibraryTutorial

Troubleshooting compiling errors:
error: WConstants.h: No such file or directory
error: Wires.h: No such file or directory
Change / point library to Arduino.h
Play, discover, learn and enjoy! (and don't be scared to make mistakes along the way!)

tynemouthsoftware

  • Newbie
  • *
  • Posts: 2
  • blog.tynemouthsoftware.co.uk
    • Tynemouth Software Blog
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #1 on: September 20, 2013, 10:37:38 AM »
Excellent tutorial Martin, it's good to cover the pitfalls as many of the tutorials assume that everything works first time.

If you want a bit more than 16x2 characters on an LCD, I'm currently working on an Arduino Library and shield which generates 80x25 text display on a TV or video monitor.


I based it on a project by Grant Searle (http://searle.hostei.com/grant/MonitorKeyboard/index.html) which used an ATMega328P to generate the video, under the control of an ATMega88. I've written an Arduino library which replaces the ATMega88 in that circuit with an Arduino, and allows you to write to the TV screen as easily as you would an LCD. You still need a separate ATMega328p (the same chip as used in the Arduino) and a shift register to send the bits to the screen.

The initial version used an 8 bit parallel interface with the video processor, Grant has since updated that to allow a smaller 4 bit interface (like the HD44780). I then added an I2C option which Grant has now added to the main version.

More details on my blog:
http://blog.tynemouthsoftware.co.uk

I'm currently working on updating the library and producing a shield. And watch this space for double width and double height character options coming soon.

Thanks,

Dave
« Last Edit: September 22, 2013, 03:44:33 AM by tynemouthsoftware »
blog.tynemouthsoftware.co.uk

mariush

  • Newbie
  • *
  • Posts: 42
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #2 on: September 20, 2013, 12:44:17 PM »
While the video was nice production wise, and you describe everything well, I could only watch it until the 20 minute mark.

I personally really don't like these types of tutorials, where someone basically tells viewers to buy a lcd screen, plug it in the arduino and download 10 libraries and try each one until something shows up on the screen.

I feel that it really doesn't teach people useful things and just like Arduino, it hides away a lot of things that may be hard to understand at first, but which people should really understand.

And the Sparkfun lcd display.. in my humble opinion it's really a poor choice for a tutorial .. they basically took a cheap 2$ lcd display and added a PIC microcontroller in the back which translates the i2c messages to the 8 bit parallel connection.  There are proper i2c /serial displays which work with different commands and messages.

Libraries hide everything from users and stupidify everything.. if the viewer gets a lcd display with slightly different controller he's stuck because he doesn't understand how the lcd display actually works and what the libraries actually do.  Be honest... how many people will actually go and open libraries and try to read the source code (and how many arduino viewers actually know how to do anything outside the arduino ide) ?

When I started working with microcontrollers, I've learned much more from videos like this one:

http://www.youtube.com/watch?v=7-DK8kNHvlA  (watch esp. from about 16:00 onwards to see how nice it explains how the controller on the back of the display works)

and by simply opening the datasheet first and making my own code to start the lcd display and just print a character on the screen, then making my own functions to clear the display, show the cursor or hide it and so on. And it was much more satisfying than using libraries.
« Last Edit: September 20, 2013, 12:46:22 PM by mariush »

tynemouthsoftware

  • Newbie
  • *
  • Posts: 2
  • blog.tynemouthsoftware.co.uk
    • Tynemouth Software Blog
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #3 on: September 22, 2013, 03:43:02 AM »
Whilst I agree that a more standard 8 bit or 4 bit interfaced LCD would probably have been a better choice, I think libraries and the Arduino definitely have a place.

For someone starting out, it can be quite daunting staring at the ATMeag328P datasheet and the HD44780 datasheet. I remember doing it myself 20 years ago with the same displays and a PIC16C84.

Something like the Arduino and these kits and libraries allows anyone to quickly get something up and running, and that's what a lot of people want. Put too many obstacles in the way, and it's easy to get frustrated. Once you get past the initial stages, you can then gain more experience, and look inside these libraries and think 'I can adapt that to do X Y or Z' or 'hey, I can do better than that'. But on day one, you really need to see the LED flashing or Hello World on the display or a lot of people don't make it to day two.

Without using the arduino and libraries, the alternatives are googling around for source code samples and trying 10 of those until you get one for the right chip and then getting that to work. At least the library framework provides something that should, and often does, work. It's by no means perfect, but I think it's a great platform. I know many people who have used things like the Arduino and a few libraries to get simple projects working who wouldn't have even got started trying to sort of development environments, programmers, and sample code from all over the web.
blog.tynemouthsoftware.co.uk

Mr Eastwood

  • Sr. Member
  • ****
  • Posts: 274
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #4 on: September 24, 2013, 08:29:09 AM »
I quite liked the video and thought it was a nice beginners introduction to LCD's with Arduino.
Hey! Frisbee! Far out!

MJLorton

  • Administrator
  • Hero Member
  • *****
  • Posts: 817
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #5 on: September 25, 2013, 12:41:11 PM »
Thanks for the interesting post tynemouthsoftware! I think you sum up my thoughts on the subject in your second post too!

Jucole...thanks for your post.

mariush, I appreciate you posting your point of view.

Cheers,
Martin.
Play, discover, learn and enjoy! (and don't be scared to make mistakes along the way!)

Suhail

  • Newbie
  • *
  • Posts: 3
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #6 on: August 22, 2014, 06:35:24 PM »
Thanks Martin for the post. Very helpful.
I know it is an old topic. but I need some help for this device:
I got the 20x4 LCD from sparkfun, I connected it to the arduino mega and it is only showing black squares in the 1st and 3rd row of the screen.
 I have searched the web looking for a solution, but nothing.
Have you encountered this problem? can you advise me what to do?

THanks,
Suhail

Mr Eastwood

  • Sr. Member
  • ****
  • Posts: 274
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #7 on: August 22, 2014, 07:40:45 PM »
Thanks Martin for the post. Very helpful.
I know it is an old topic. but I need some help for this device:
I got the 20x4 LCD from sparkfun, I connected it to the arduino mega and it is only showing black squares in the 1st and 3rd row of the screen.
 I have searched the web looking for a solution, but nothing.
Have you encountered this problem? can you advise me what to do?

THanks,
Suhail

Hi,  I'd check and double check your connections;  also maybe it's the contrast pot not adjusted correctly?
Hey! Frisbee! Far out!

Suhail

  • Newbie
  • *
  • Posts: 3
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #8 on: August 24, 2014, 01:47:29 PM »
Mr Eastwood, I've checked again, still not working. I searched for a solution in many forums,  and no one could give a solution for this issue.
I will be happy to hear more ideas.
« Last Edit: August 24, 2014, 01:49:24 PM by Suhail »

bobcat

  • Newbie
  • *
  • Posts: 7
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #9 on: August 24, 2014, 04:08:54 PM »
If you are using the Arduino library, you must change the begin() call in setup.
The library as shipped includes this line in setup:
lcd.begin(16, 2);

Change it to:
lcd.begin(20, 4);
Dev Circus -- Breakout boards, Arduino compatible products- Check Us Out! www.devcircus.com

dr_p

  • Jr. Member
  • **
  • Posts: 64
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #10 on: August 25, 2014, 03:57:36 AM »
is the LCD's Read/Write (R/W) pin grounded?

Suhail

  • Newbie
  • *
  • Posts: 3
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #11 on: August 26, 2014, 05:28:44 AM »
Bobcat, I am using the sparkfun library which I have downloaded from this forum.
I also used the example code that is in the library and I got the same result.
I will try your suggestion though.

Dr_p, n, it's not grounded. I've connected the wires according to the datasheet and according to the video posted by martin.



bobcat

  • Newbie
  • *
  • Posts: 7
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #12 on: August 26, 2014, 07:46:40 AM »
Are you using the Sparkfun display with the SerLCD board on the back of the display? If so, that is a unique setup. You should email Sparkfun tech support for help. https://www.sparkfun.com/static/customer_service
Dev Circus -- Breakout boards, Arduino compatible products- Check Us Out! www.devcircus.com

Mac26

  • Newbie
  • *
  • Posts: 1
Re: Arduino Tutorial #4 - LCD displays, Libraries and Troubleshooting
« Reply #13 on: September 02, 2014, 05:19:00 AM »
HI! I´m lookingo for a LCD Screen  but I dont sure that this is right for me. I want to make a control for my robot. must be one meter away from arduino, so i dont know if its possible with the Serial LCD
And other question... is it not necesary to add a resistor o something like this? żAnd i can conect to the same supply than the arduino and the robot?
thanks!