Go Down

Topic: LCD Display does not show the right figures (Read 250 times) previous topic - next topic

Chelvind

Hi,

I have installed an LCD display to my Arduino, and it appears to be working fine, but:

When trying to create a procedure for displaying integer values read from an analog output pin (generated by at pot-meter), the display shows readings between 1 and 9000, when I can see on the Serial Monitor, that the output from the pin is actually between 1 and 1024 (as expected).

The value is defined using the command 'int potValue = analogRead(A0);
The value is read using the command 'potValue = analogRead(A0);
The value should be displayed using the command 'lcd.print(potValue);

The pin is also used to control the speed of a DC motor which works fine. Output on pin A0 is shown on the Serial Monitor as 1-1024, but the display shows values between approx. 1 and 9000.

The commands are part of a loop. It appears as if the initial readings are correct, but hereafter values below 1024 are displayed as 10 times the actual value (just guessing).

Anybody has a piece of sound advice for me?

Thx!

artisticforge

Hi,

I have installed an LCD display to my Arduino, and it appears to be working fine, but:

When trying to create a procedure for displaying integer values read from an analog output pin (generated by at pot-meter), the display shows readings between 1 and 9000, when I can see on the Serial Monitor, that the output from the pin is actually between 1 and 1024 (as expected).

The value is defined using the command 'int potValue = analogRead(A0);
The value is read using the command 'potValue = analogRead(A0);
The value should be displayed using the command 'lcd.print(potValue);

The pin is also used to control the speed of a DC motor which works fine. Output on pin A0 is shown on the Serial Monitor as 1-1024, but the display shows values between approx. 1 and 9000.

The commands are part of a loop. It appears as if the initial readings are correct, but hereafter values below 1024 are displayed as 10 times the actual value (just guessing).

Anybody has a piece of sound advice for me?

Thx!
WE need the standard information.
Which Arduino board are you using?
Which operating system are you using? Linux, MacOSX or Windows
Which version of the Arduino IDE?

The Make and model of the LCD?

The sketch that you are using. Please use the code tags for the code.

Chelvind

Sorry,

I am using an Arduino Uno board, Windows 10 for programming, Arduino IDE ver 1.8.5 and the display is a 1602A LCD display - make unknown.

The code of the entire sketch is given below. The Arduino board is connected to a potmeter (pin A0), a photocell (pin A1) and gives output to a transistor (on pin 3) which controls a DC motor.

Hope you can help.

int potPin = A0;                         // Analog pin 0 connected to the potentiometer
int photocellPin = A1;                    //Analog pin 1 to photocell Out 1
int transistorPin = 3;                  // connected from digital pin 3 to the base of the transistor
int potValue = 0;                       // value returned from the potentiometer.
int photocellValue = 0;               //value returned from photocell Out 1

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);
void setup() {                         
  Serial.begin(9600);
  pinMode(transistorPin, OUTPUT);       // set  the transistor pin as an output.
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.write("POT: ");
}

void loop() {                           
 
  potValue = analogRead(potPin) / 4;    // read the potentiometer, convert it to between 0 - 255
                                        // for the value accepted by the digital pin.
  analogWrite(3, potValue);             // potValue alters the supply from pin 3 which in turn
                                        //controls the power running through the transistor.
  photocellValue = analogRead(photocellPin);
  Serial.println(potValue);
  lcd.setCursor(7,0);
  lcd.print(potValue, DEC);             //shows values above 1015 as 10 x the actual value?
  delay(1000);
}

floresta

#3
Dec 07, 2017, 03:29 pm Last Edit: Dec 07, 2017, 03:32 pm by floresta
Try this.

After you set the cursor you should print a bunch of spaces, enough to cover up the longest previous number, then reset the cursor and print your results.

Code: [Select]
  Serial.println(potValue);
  lcd.setCursor(7,0);
  lcd.print("      ");
  lcd.setCursor(7,0);
  lcd.print(potValue, DEC);             //shows values correctly?
  delay(1000);


Also - use 'code tags' when displaying code in a forum post.

Don

Chelvind

Hi Don,

I'll try that. I cannot quite follow the logic, but if it works there's free beer anytime you pass through Copenhagen!

floresta

Here's the logic.

Any characters that you send to the LCD remain there until they are overwritten (or until you remove the power).

Let's say you initially display a reading of 1020 and that your next reading is 987.

In this case the 9 will replace the 1, the 8 will replace the first 0, and the 7 will replace the 2.  The problem is that the second 0 will still be displayed so your LCD will show 9870.

If you replace the 1020 with blanks before displaying the 987 then the display will be as you expect.

Don

Go Up