element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum How do I add a Liquid Crystal Display to my current project
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 37 replies
  • Answers 2 answers
  • Subscribers 403 subscribers
  • Views 3547 views
  • Users 0 members are here
  • x
  • 1
  • lcd_display
  • arduino
  • 16
Related

How do I add a Liquid Crystal Display to my current project

Former Member
Former Member over 12 years ago

Hello,

 

I recently completed, with some assistance from Coder27, Bill Abbot, Tony, and Mark Beckett the first part of my project ( http://www.element14.com/community/thread/23967?start=0&tstart=0 )

Now the second part - I am wanting to add a small 16 x 1 LCD to finish up my project (see coding below that I will be using)

I would like the LCD to simply show which direction a servo is pointing (as in degrees, such as 0°, 90°, 180°, 270°, or 360° or anywhere in between 0° to 360°)

Please be advised: I do know that arduino 1.0.4 has the LCD Scroll example, but I am sure I dont need the entire code they have.  Also, my LCD is only 16 x 1, not x 2.

Thanks,

~Anna

 

******** BEGINNING OF CODE *************

#include <Servo.h>

 

const int pan1 = 3;     // first servo

const int tilt1 = 5;    // second servo

const int pan2 = 9;     // third servo

const int tilt2 = 11;    // fourth servo

 

const int potpan1 = A0; // Joystick 1 Vertical signal

int val0;

const int pottilt1 = A1;   // Joystick 1 Horizontal signal

int val1;

const int potpan2 = A5;   // Joystick 1 Select signal

int val2;

const int pottilt2= A3;   // Joystick 2 Vertical signal

int val3;

 

int servoVal[4];        // variable to read the value from the analog pin

 

Servo mypan1;                                  // create servo object to control a servo

Servo mytilt1;    // create servo object to control a servo

Servo mypan2;                                  // create servo object to control a servo

Servo mytilt2;    // create servo object to control a servo

 

void setup()

{

 

  // Servo 

  mypan1.attach(pan1);  // attaches the servo

  mytilt1.attach(tilt1);  // attaches the servo

  mypan2.attach(pan2);  // attaches the servo

  mytilt2.attach(tilt2);  // attaches the servo

 

  // Inizialize Serial

  Serial.begin(57600);

}

 

void loop()

{

 

  outputPotentiometers();           // Read and output joystick values

 

  val0 = analogRead(potpan1);            // reads the value of the potentiometer (value between 0 and 1023)

  val0 = map(val0, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)

  mypan1.write(val0);                  // sets the servo position according to the scaled value

 

  //Serial.print("Value of PWM 3:   ");

  //Serial.println(val0);

  //Serial.print("\t");

 

  val1 = analogRead(pottilt1);            // i added

  val1 = map(val1, 0, 1023, 0, 179);     // i added

  mytilt1.write(val1);                  // i added 

 

  //Serial.print("Value of PWM 5:   ");

  //Serial.println(val1);

  //Serial.print("\t");

 

  val2 = analogRead(potpan2);            // i added

  val2 = map(val2, 0, 1023, 0, 179);     // i added

  mypan2.write(val2);                  // i added

 

  //Serial.print("Value of PWM 6:   ");

  //Serial.println(val2);

  //Serial.print("\t");

 

 

  val3 = analogRead(pottilt2);            // i added

  val3 = map(val3, 0, 1023, 0, 179);     // i added

  mytilt2.write(val3);                  // i added

 

  delay(20);                                      

}

 

void outputPotentiometers()     // Display Joystick Values

{

  Serial.print("Pot Pan 1 on ~3:     ");

  Serial.print(analogRead(potpan1));

  Serial.print("\t");

  Serial.print("     Pot Tilt 1 on ~5:     ");

  Serial.print(analogRead(pottilt1));

  Serial.print("\t");

  Serial.print("     Pot Pan 2 on ~9:     ");

  Serial.print(analogRead(potpan2));

  Serial.print("\t");

  Serial.print("     Pot Tilt 2 on ~11:     ");

  Serial.println(analogRead(pottilt2));

  Serial.print("\t");

 

}

 

 

 

********** END OF CODE *************

  • Sign in to reply
  • Cancel

Top Replies

  • ntewinkel
    ntewinkel over 12 years ago +1 suggested
    Here's a good example to start with: http://arduino.cc/en/Tutorial/LiquidCrystal You'd have to change the setup line to be lcd.begin(16,1) for your smaller display (and assuming the lcd lib supports it…
  • mcb1
    mcb1 over 12 years ago in reply to billabott +1 verified
    Annasta Your explanation does give us some clues where your learnng lies, and how you have come to be involved, so thanks. You may have noticed that there are many people asking for help, and a lot are…
  • Former Member
    Former Member over 12 years ago in reply to billabott +1
    If I might add a bit to WATB's reply, we get all sorts of questions here, and the kind of answer you want to give differs based on the motivation for the question. If someone is asking for help with what…
Parents
  • billabott
    0 billabott over 12 years ago

    @Anna

    My user name is billabott.  My full name is William Alan Thomas Bottger.  Attention to details is a fairly important part of this field of study.  One detail that I am curious about is: What in the world is your motivation for doing this project?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    Well William Alan Thomas Bottger image

    The motivation for my project is very simply, I want to do it.  A friend of mine has a son who is on a robotics team at school.  She invited me a few months back to go with her and visit an open house the team / students setup.  I wasnt doing anything so I accepted the invite, and glad I did.  I understood from their teacher that anyone can build things with Arduino boards, so with that I had an idea (funny how life works sometimes)

    If you remember from a previous post, I was doing a photoshoot for some students this past saturday ( http://www.element14.com/community/thread/23967?start=48&tstart=0 )

    Photography is something I like to do; the project, which I dont want to give away just yet, will assist me with doing a special shoot configuration.  Thats really all I will elaborate on at this time.

    The lcd portion, well it would be nice to have with the project, but if it is not able to be done, then I wont bother with it.

     

    Hope I answered your question.

    Now my question to you is, why do you ask? image

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to Former Member

    Yes, Anna, you did. Thank you.

     

    I have an abundance of curiosity and often a complete lack of restraint.  I wish you great success with all your Arduino endevours.

     

    There is an important philosophical movement that makes the Arduino community what it is.  It is called Open Source.  I hope you and every new person will take the opportunity to learn, adopt, and practice its principles.

     

    Some OS folks will say that if you ask for free help then you should not expect to have secrets about what the project's big picture is.  Some, but not all, are unwilling to assist someone who insists on compartmentalization.  The choice is yours.

     

    Until we meet again, happy trails to you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to billabott

    Annasta

    Your explanation does give us some clues where your learnng lies, and how you have come to be involved, so thanks.

     

    You may have noticed that there are many people asking for help, and a lot are just wanting someone else to do their assignment for them.

    In our experience (we have long years and lots) it doesn't really teach you as much as learning yourself, with the occasional push in the right direction.

     

    May we suggest some very good tutorials.

     

    I like

    Adafruit             http://www.ladyada.net/learn/arduino/index.html

    John Boxall       http://tronixstuff.wordpress.com/tutorials/

     

    Nico likes Oomlout     http://www.oomlout.com/a/products/ardx/

     

    and of course the official one    http://arduino.cc/en/Tutorial/HomePage

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    If I might add a bit to WATB's reply, we get all sorts of questions here,

    and the kind of answer you want to give differs based on the motivation

    for the question. 

     

    If someone is asking for help with what appears to be a homework problem,

    then you don't want to hand them the full solution, you just want to give them

    some clues or pointers to reading material.

     

    We have had people asking for help for example building a system that

    can read license plates, where we're not sure what legitimate purpose

    they have in mind.

     

    Sometimes it's clear from variable names in the code what the project

    is trying to do, but your first version used generic names rather than

    meaningful names, which could either indicate a beginner who didn't

    recognize the usefulness of meaningful names, or someone who was

    trying to be secretive.  Being secretive arouses curiosity.

     

    Sometimes when the purpose of the project is clear, a much better solution

    can be given, based on an entirely different approach to the problem.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to mcb1

    Thanks Mark for that added information.

    I guess where my confusion comes in is best explained this way.

    So I have the coding working thanks to those in the previous post, and starting with the first coding, rev A all the way up to rev J (I named them that so I didnt overwrite samples of the same coding)

     

    #include <Servo.h>   // when I enter this, it allows the Servo.h library to load up for the servos,

    #include <LiquidCrystal.h> // am I able, after the Servo.h library, place this library directly after it?  Or can I add this #include statement at the end of the first coding?

     

    So in a nutshell, that is really what the question should have been...........How should the layout of my coding be listed.  Should it be mixed, or should the LCD library coding come after the servo coding.

     

    As far as wiring, there are only 6 connections on my lcd panel (its a 16 x 1) and it looks as though I can use the following coding from the examples:

    ********************************************************
    http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll

    */

    // include the library code:
    #include <LiquidCrystal.h>

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Since I am already using ~3, ~5, ~6, & ~9 on the servo project, I am giong to use: 12, 11, 8, 7, 4, & 2 in lieu of the pins listed in the coding

    void setup() {
      // set up the LCD's number of columns and rows:
      lcd.begin(16,2); // this I will change to (16,1) simply because that is the design of the LCD panel I have.

    }

    void loop() {
      // set the cursor to (0,0):
      lcd.setCursor(0, 0);
      // print from 0 to 9:
      for (int thisChar = 0; thisChar < 10; thisChar++) {
       lcd.print(thisChar);
       delay(500);
      }

      // set the cursor to (16,1):
      lcd.setCursor(16,1);
      // set the display to automatically scroll:
      lcd.autoscroll();
      // print from 0 to 9:
      for (int thisChar = 0; thisChar < 10; thisChar++) {
        lcd.print(thisChar);
        delay(500);
      }
      // turn off automatic scrolling
      lcd.noAutoscroll();
     
      // clear screen for the next loop:
      lcd.clear();
    }

    ********************************************************

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    @Bill -

    I understand exactly where your coming from, and I do apologize if what I stated came out the wrong way.  As you can see I am not really holding back, I have should mulitple Frizting diagrams, and also posted the coding I am using.

    The actual project is to be able to turn small light fixtures to a desired location so I dont have to constantly move away from the camera to see how the lighting is with regards to filtering out the shadows.  So you see its not that big of a deal to have the lcd, but it would be nice.

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 12 years ago in reply to billabott

    @Bill -

    I understand exactly where your coming from, and I do apologize if what I stated came out the wrong way.  As you can see I am not really holding back, I have should mulitple Frizting diagrams, and also posted the coding I am using.

    The actual project is to be able to turn small light fixtures to a desired location so I dont have to constantly move away from the camera to see how the lighting is with regards to filtering out the shadows.  So you see its not that big of a deal to have the lcd, but it would be nice.

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • mcb1
    0 mcb1 over 12 years ago in reply to Former Member

    Annasta

     

    Your comments are correct.

    The Arduino IDE comes with a set of libraries already built in.

     

    Adding #include <Servo.h> tells the 'sketch' to use this and the servo.cpp file (and any others it calls itself.)

    The library is just code and if you open this file, you'll probably be able to read and understand it, and the servo.cpp file.

     

    You can add them in any order, as long as they are above the setup.

     

    You will need to change

    // set the cursor to (16,1):

      lcd.setCursor(16,1);

     

    to 16,0 as the first line is 0 (not 1).

     

     

    Your pin change should work. The order is important, so just swap the Arduino pin, ie

     

    • LCD RS pin to digital pin 12
    • LCD Enable pin to digital pin 11
    • LCD D4 pin to digital pin 8
    • LCD D5 pin to digital pin 7
    • LCD D6 pin to digital pin 4
    • LCD D7 pin to digital pin 2

     

    You may need to adjust the scroll speed, depending on the LCD. I found the white on blue needed to be slower as you got 'ghosting' compared to the others.

     

    One small word of caution.

    The LCD has a controller onboard, and needs the setup from the Arduino to operate correctly.

    So if you depower the display or corrupt it, then restart the sketch to ensure it gets initialised correctly.

     

     

    Otherwise you are off to a flying start.

     

    mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to mcb1

    @ Mark -

    Thank you...going to hit the bed now...will go further tomorrow, today, later this afternoon image

     

    ~Anna

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to mcb1

    @Mark

    What is the best way to provide clean power to the LCD?  My guess is with its own BB power supply.  My concern is the EM noise the motors will be creating when moving.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to billabott

    William

     

    I haven't experienced this, mainly because I have't tried the combination of motors and LCD ...yet.

     

    The LCD is powered from the same 5v line as the Arduino, and the LCD's I have played with are all 5v.

    I did receive an oddball once with an extra chip and it turns out it was a 3v3 version...the chip generated the extra 1.7v to drive the crystal bits.

     

    Since they work using a full 5v (or 3v3) signalling, any noise is unlikely to be a major issue.

     

     

    Having said that, any time you have motors, you will get noise, and the 1000uF cap is easy, cheap insurance.

    Actually its worth adding anytime you have a wallwart type power supply.

    This will tend to stop the dip in voltage as the motor starts, which if bad enough could cause the controller chip on the LCD to reset.

     

    It would be nice to think that the manufacturer has also added a 0.1uF cap from each brush to the motors metal body, thereby either grounding it, or at least bypassing the higher frequency noise.

     

    For this project, Annasta has added the extra power supply, and made the gound go directly to the supply.

    Rerouting the ground also stops any motor current from travelling on the same path as the voltage from the pots.

    (Think of a highway for pushbikes, and a seperate highway for trucks, if at some point they made one lane common, there would be problems for the bikes).

     

    As an extra precaution, I would be adding a 0.1 (or even a 1-10uF) across the pot centre pin to earth.

    The pots are there to move the lights, so speed/lag isn't an issue, and it helps to ensure noise spikes are reduced, which in turn limits the motor movement causing the noise.

     

    For the other readers.

    The pins that the centre of the pots feed are detecting the voltage in 1024 steps or levels, which range from 0v = 0 and 5v = 1023.

    If you do the math, that means it can detect a voltage of 0.00488v (or 4.9mV) so if the voltage increases by 4.9mV the ADC reading will increase by 1.

    Any ripple/noise on these lines may affect the input reading.

     

    You can add hardware filtering (capacitor) or take 10 samples and average them, to help eliminate the false reading, but removing the problem at its source is always the most useful way  ... first.

     

    Hope this helps

    mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 12 years ago in reply to mcb1

    @mark

    Does using LCD D7 pin to digital pin 2 (TX) preclude the use of the serial monitor?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to billabott

    William

    Serial uses pins 0 an 1.

     

    Reference http://www.element14.com/community/thread/21999

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube