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
    About the element14 Community
  • 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 410 subscribers
  • Views 4143 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
  • Former Member
    0 Former Member over 12 years ago

    updated code:

    // SparkFun Serial LCD example 2
    // Format and display fake RPM and temperature data

    // This sketch is for Arduino versions 1.0 and later
    // If you're using an Arduino version older than 1.0, use
    // the other example code available on the tutorial page.

    // Use the softwareserial library to create a new "soft" serial port
    // for the display. This prevents display corruption when uploading code.
    #include <SoftwareSerial.h>

    // Attach the serial display's RX line to digital pin 2
    SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

    void setup()
    {
      mySerial.begin(9600); // set up serial port for 9600 baud
      delay(500); // wait for display to boot up

      mySerial.write(254); // cursor to beginning of first line
      mySerial.write(128);

      //mySerial.write("RPM:            "); // clear display + legends
      //mySerial.write("TEMP:           ");
      mySerial.write("T1:     P1:     "); // clear display + legends
      mySerial.write("T2:     P2:     ");
    }

    //int temp, rpm;
    //char tempstring[10], rpmstring[10]; // create string arrays
    int t1, p1, t2, p2;
    //char t1[8], p1[8], t2[8], p2[8]; // create string arrays
    char t1string[8];
    char p1string[8];
    char t2string[8];
    char p2string[8];
    ;

    void loop()
    {
      //temp = random(1000); // make some fake data
      //rpm = random(10000);
      t1 = random(1000); // make some fake data
      p1 = random(1000);
      t2 = random(1000); // make some fake data
      p2 = random(10000);

      //sprintf(tempstring,"%4d",rpm); // create strings from the numbers
      //sprintf(rpmstring,"%4d",temp); // right-justify to 4 spaces
      sprintf(t1string,"%4d",t1); // create strings from the numbers
      sprintf(p1string,"%4d",p1); // right-justify to 4 spaces
      sprintf(t2string,"%4d",t2); // create strings from the numbers
      sprintf(p2string,"%4d",p2); // right-justify to 4 spaces

      //mySerial.write(254); // cursor to 7th position on first line
      //mySerial.write(134);
      mySerial.write(254); // cursor to 7th position on first line
      mySerial.write(143);

      //mySerial.write(rpmstring); // write out the RPM value
      mySerial.write(t1); // write out the RPM value

      //mySerial.write(254); // cursor to 7th position on second line
      //mySerial.write(198);
      mySerial.write(254); // cursor to 7th position on second line
      mySerial.write(207);

      //mySerial.write(tempstring); // write out the TEMP value
      mySerial.write(p1); // write out the TEMP value
    // lines below have been added to accomidate t2 and p2
      //mySerial.write(254);
      //mySerial.write(134);
      mySerial.write(254); //
      mySerial.write(198);

      //mySerial.write(rpmstring); // write out the RPM value
      mySerial.write(t2); // write out the RPM value

      //mySerial.write(254); // cursor to 7th position on first line
      //mySerial.write(134);
      mySerial.write(254); // cursor to 7th position on first line
      mySerial.write(200);

      //mySerial.write(rpmstring); // write out the RPM value
      mySerial.write(p2); // write out the RPM value

      delay(1000); // short delay
    }

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

    Annasta

    I give up explaining....

     

    Try this then compare it to your original code and see what is different.

     

     

     

    {

      mySerial.begin(9600); // set up serial port for 9600 baud

      delay(500); // wait for display to boot up

     

      mySerial.write(254); // cursor to beginning of first line

      mySerial.write(128);

     

      mySerial.write("T1:     P1:     "); // clear display + legends

      mySerial.write("T2:     P2:     ");

    }

     

    int t1, p1, t2, p2;

     

    char t1string[8];

    char p1string[8];

    char t2string[8];

    char p2string[8];

     

    void loop()

    {

     

      t1 = 90;   //fixed value

      p1 = 45;   //fixed value

      t2 = 45;    //fixed value

      p2 = 180;   //fixed value

     

     

      sprintf(t1string,"%4d",t1); // create strings from the numbers

      sprintf(p1string,"%4d",p1); // right-justify to 4 spaces

      sprintf(t2string,"%4d",t2); // create strings from the numbers

      sprintf(p2string,"%4d",p2); // right-justify to 4 spaces

     

     

      mySerial.write(254); // cursor to 4th position on first line

      mySerial.write(131);

      mySerial.write(t1string); // write out the t1 value AFTER it was made into a string

     

      mySerial.write(254); // cursor to 11th position on first line

      mySerial.write(138);

      mySerial.write(p1string); // write out the p1 value AFTER it was made into a string

     

      mySerial.write(254); // cursor to 4th position on second line

      mySerial.write(195);

      mySerial.write(t2string); // write out the t2 value AFTER it was made into a string

     

      mySerial.write(254); // cursor to 11th position on second line

      mySerial.write(202);

      mySerial.write(p2string); // write out the p2 value AFTER it was made into a string

     

      delay(1000); // short delay

    }

     

     

    mark

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

    I just realized that there is a SerLCD library that might make life easier:

     

    http://playground.arduino.cc/Code/SerLCD

     

    The sample they include is a bit much, but you should be able to run the regular LiquidCrystal example with a minor modification like this:

     

    #include <serLCD.h>

     

    // Set pin to the LCD's rxPin

    int pin = 2;

     

    serLCD lcd(pin);

     

    void setup() {

     

      lcd.clear();

      // Print a message to the LCD.

      lcd.print("hello, world!");

    }

     

    void loop() {

    // set the cursor to column 0, line 1

      // (note: line 1 is the second row, since counting begins with 0):

      lcd.setCursor(0, 1);

      // print the number of seconds since reset:

      lcd.print(millis()/1000);

    }

     

     

    Then you could sprintf into String buffers, and do something like this:

     

      lcd.setCursor(0, 0);

      lcd.print("Top Line");

      lcd.setCursor(0, 1);

      lcd.print("Bottom Line");

     

    I'm sorry I don't have more time to be more detailed - sort of trying to help while getting my own work done!

     

    I recommend trying this as a new separate test sketch - don't change what you already have. That's in case it doesn't work as advertised, plus it also helps to get an understanding of things first.

     

    Cheers,

    -Nico

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

    I just realized that there is a SerLCD library that might make life easier:

     

    http://playground.arduino.cc/Code/SerLCD

     

    The sample they include is a bit much, but you should be able to run the regular LiquidCrystal example with a minor modification like this:

     

    #include <serLCD.h>

     

    // Set pin to the LCD's rxPin

    int pin = 2;

     

    serLCD lcd(pin);

     

    void setup() {

     

      lcd.clear();

      // Print a message to the LCD.

      lcd.print("hello, world!");

    }

     

    void loop() {

    // set the cursor to column 0, line 1

      // (note: line 1 is the second row, since counting begins with 0):

      lcd.setCursor(0, 1);

      // print the number of seconds since reset:

      lcd.print(millis()/1000);

    }

     

     

    Then you could sprintf into String buffers, and do something like this:

     

      lcd.setCursor(0, 0);

      lcd.print("Top Line");

      lcd.setCursor(0, 1);

      lcd.print("Bottom Line");

     

    I'm sorry I don't have more time to be more detailed - sort of trying to help while getting my own work done!

     

    I recommend trying this as a new separate test sketch - don't change what you already have. That's in case it doesn't work as advertised, plus it also helps to get an understanding of things first.

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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 © 2026 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