Go Down

Topic: Serial.println and lcd.print not identical (Read 1 time) previous topic - next topic


I am still on pulse measuring. I have a strange problem.

Serial.println and lcd.print are not identical

For lcd.print the first digit is always zero, and sometimes it adds one trailing digit.

Code source:  https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-18/recipe-18-8

My change from above code:

Code: [Select]

        Serial.println(duration / 1000);  // output i.e. : 1707
        lcd.setCursor(0, 1);     
        lcd.print(duration / 1000);    // output i.e. : 0707

The same code in the Arduino LCD sample code works perfectly as expected.


Strange as both derive from the print class . O no that is an assumption. Which LCD class do you use?

can you insert this, to see if there is a pattern in the values where it happens
Code: [Select]

for (int i=1; i< 32000; i= i*3)
  lcd.setCursor(0, 1);     

note: println  adds a CR/LF pair,  print does not.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


May 23, 2013, 09:08 am Last Edit: May 23, 2013, 12:08 pm by flameproof Reason: 1
I use the standard LCD library:

#include <LiquidCrystal.h>

Your code seems identical in the serial mon and on the LCD. However, it seems not to clear the LCD
Last two serials are:


Last LCD display:

105157 - obviously the 7 was 'leftover'

I found this out, look at:


When I change:

const int numberOfEntries  = 64;    // the max number of pulses to measure


const int numberOfEntries  = 2;    // the max number of pulses to measure

Then I do get an accurate readings, mostly. But when the times get shorter, around 5ms, then the calculations get again wrong. Could the hardware interrupt disturb the software operation?


Generally it's a good idea to stick to simpler code that one can understand. Now I use the pulseIn() function and so far it works better:


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131