The example sketch you posted, all your output uses the Print class on the Serial port to format the output so everything printed to the serial port is already in ASCII.
What isn't clear is what you are really wanting to do.
i.e. are you wanting to:
- simply add an LCD to what you already have using a single Arduino
- use one Arduino to print to serial port that is read by a second Arduino which displays the serial data on an LCD
What you need to do varies substantially between the two.
If using a single Arduino, then things are much simpler/easier.
You just wire up the LCD, use the LiquidCrystal library and use lcd.print() instead of Serial print.
However... there would be some changes needed as the LCD doesn't emulate a terminal and does not process line endings so you would have to position the cursor on the LCD each time prior to printing out your information.
Also the LCD display (particularly if you use a 16x2) may have fewer characters than you are currently outputting on the line on the serial port so you would need to alter the output format used on the LCD.
If attempting to use 2 Arduinos and read the serial port using a 2nd Arduino
the key thing to appreciate is what Paul said:
Note that "printing" stuff to the serial monitor is easy in terms of line length and carriage returns. To use the LCD, you have to be very careful about how you format the data.
To appreciate what the means you have to understand how the hd44780 LCD and the LiquidCrystal library works.
The hd44780 LCD is very dumb. While it does have commands to do things like position the cursor, clear the screen, home the cursor and a few others, The display does not understand line endings like and , nor does it understand line wrapping.
The LiquidCrystal library implements and API to talk to the LCD but it only provides API functions that mirror the core functions supported the LCD.
So what the really means is that when using the LiquidCrystal library and Print class, you can't send characters to the LCD the same way you can with the serial monitor.
This is because things like and will not be processed as carriage return or line feed and the characters will not wrap around to the next line on long lines.
So in your case you have this:
Serial.print ("time passed: ");
Serial.print (totalTime);
Serial.println(" (s)");
Which produces output like this on the serial port:
time passed: ### (s)<CR><LF>
The Arduino serial monitor will interpret the character as a carriage return and wrap the cursor, Then interpret the and scroll the screen.
That won't happen on the LCD as neither the LCD nor LiquidCrystal process the and characters that way.
The LiquidCrystal library will send the and characters to the LCD which will interpret them as custom characters which will generally put two unwanted "garbage" characters on the display.
Because of this you can't just read a serial port and send the characters read "as is" to the LiquidCrystal library.
i.e. one Arduino outputs the serial data and another Arduino reading the serial data and sending it to the LiquidCrystal library.
You can simplify things if you can limit the display on the LCD to a single line of output from the serial port.
The reader Arduino could read the data until it sees the line endings and then set the cursor position and send that line (without the line ending characters) to the LCD.
The issue then becomes how to handle the line wrapping for long lines.
If you were to change the serial output to be no larger than your LCD line, then that problem goes away.
If you want to have long line wrapping on the LCD, you could switch to using my hd44780 library as that library will handle line wrapping.
It won't do line scrolling on the LCD but it does support line wrapping.
--- bill