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
Blog Arduino Due w/LCD 20 x 4 cursor location
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 19 Jun 2013 7:51 PM Date Created
  • Views 778 views
  • Likes 0 likes
  • Comments 2 comments
Related
Recommended

Arduino Due w/LCD 20 x 4 cursor location

Former Member
Former Member
19 Jun 2013

I have an Arduino Due interfeced to an LCD (4 line x 20 char).

Its a standard connection scheme using all 8 data bits in this case.

Here is my issue:

I have a program that prints values from 7 analog inputs A0-A6.

I write to A0-A3 in char position 0, lines 0-3 and A4-A6 in char position 01, lines 0-2 in a continuos loop.

My problem is the postion of each value start out as ok but after a little while the items bounce around in

location and it all gets messed up.  Im puzzled.  Can anyone offer ideas?  Ive tried quite a bit to fix it.

Here is my code that Im running in the Arduino Due.

Thanks.

 

Ken

 

 

/****************************************************************************/
#include <LiquidCrystal.h>
/****************************************************************************/
int led = 13;
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd(12, 11, 9, 8, 7, 6, 5, 4, 3, 2);

/****************************************************************************/
void setup()
{
  // put your setup code here, to run once:
      
pinMode(led, OUTPUT); // initialize the digital pin as an output.
 
Serial1.begin(9600); // initialize serial communication at 9600 bits per second:
lcd.begin(20,4);
lcd.clear();
lcd.home();
lcd.noCursor();

}

void loop() {
   // read the input on analog inputs A0-A6:

      analogReadResolution(12);   // sat analog read resolution to 12 bit, 0-4095
      int sensor0 = analogRead(A0);int sensor1 = analogRead(A1);int sensor2 = analogRead(A2);int sensor3 = analogRead(A3);int sensor4 = analogRead(A4);int sensor5 = analogRead(A5);int sensor6 = analogRead(A6);
        
   // Convert the analog reading (which goes from 0 - 4095) to a voltage (0 - 3.3V):
  
    float sensorV0 = sensor0 * (3.3 / 4095.0);
    float sensorV1 = sensor1 * (3.3 / 4095.0);
    float sensorV2 = sensor2 * (3.3 / 4095.0);
    float sensorV3 = sensor3 * (3.3 / 4095.0);
    float sensorV4 = sensor4 * (3.3 / 4095.0);
    float sensorV5 = sensor5 * (3.3 / 4095.0);
    float sensorV6 = sensor6 * (3.3 / 4095.0);

   // print out tthe (7) analog values
Serial1.print("A0=");Serial1.print(sensorV0,3); Serial1.print("\t");
Serial1.print("A1="); Serial1.print(sensorV1,3);Serial1.print("\t");
Serial1.print("A2=");Serial1.print(sensorV2,3); Serial1.print("\t");
Serial1.print("A3="); Serial1.print(sensorV3,3); Serial1.print("\t");
Serial1.print("A4=");Serial1.print(sensorV4,3); Serial1.print("\t");
Serial1.print("A5="); Serial1.print(sensorV5,3);Serial1.print("\t");
Serial1.print("A6=");Serial1.println(sensorV6,3);

//lcd.setCursor(0,0);
//lcd.print("A6=");lcd.print(sensorV6,3);
lcd.clear();
//lcd.setCursor(0,0);
lcd.print("A0= ");lcd.print(sensorV0,3);
lcd.setCursor(0,1);lcd.print("A1= ");lcd.print(sensorV1,3);
lcd.setCursor(0,2);lcd.print("A2= ");lcd.print(sensorV2,3);
lcd.setCursor(0,3);lcd.print("A3= ");lcd.print(sensorV3,3);
lcd.setCursor(11,0);lcd.print("A4= ");lcd.print(sensorV4,3);
lcd.setCursor(11,1);lcd.print("A5= ");lcd.print(sensorV5,3);
lcd.setCursor(11,2);lcd.print("A6= ");lcd.print(sensorV6,3);

 
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
delay(250);               // wait for a second
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

  
delay(500); // a little delay to not hog serial monitor
   // bottom of loop
}

  • Sign in to reply
  • neilk
    neilk over 12 years ago

    I tried (some of) your code on a UNO, driving a 16 x 2 LCD and I was surprised to find that it behaved perfectly without the lcd.setCursor(0,0)

     

    Like David Shaddock, I would have assumed that it was necessary to reset the cursor to (0,0) each time you go round the loop. Apparently not on a 16 x 2, but maybe it is necessary on a 20 x 4.

     

    Best wishes

     

    Neil

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

    Just under the lcd.clear(); line, you have commented out the lcd.setCursor command.  So analog voltage A0 is going to print pretty much wherever the cursor happens to be.  It seems to me that clearing the lcd doesn't restore the cursor to a fixed position, but I haven't worked with the 20X4 display yet; it all depends on what the lcd library says to do.  It may leave the cursor in a random place, or it may remain where it landed last.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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