I am sending a string with exactly 32 characters to the Arduino. This is to be displayed on a 16x2 LCD.
Using the substring method I decompose the string into 2 parts of 16 characters each.
As long as the data is being transmitted, the display is blank. When the sending program closes the com port, the last sent data suddenly appears correctly.
This code for a 16x1 display that I wrote has worked perfectly. I had used it as a template for the 16x2.
Not sure of why you want to use String instead of a C string. Your code takes 4936 bytes. This code:
#include <LiquidCrystal.h>
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2); I like to leave 2 & 3 free for interrupts
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
// String readString; // Why? Get rid of it.
}
void loop() {
char readString[33]; // 1 extra for NULL
int charsRead;
if (Serial.available() > 0) {
charsRead = Serial.readBytesUntil('\n', readString, 32);
readString[charsRead] = NULL;
lcd.setCursor(0, 0);
lcd.print(readString);
readString[0] = NULL;
}
}
takes 3236 bytes. I'm assuming that the VB program uses a newline character ('\n') to terminate the output stream. I think the second setCursor() isn't needed, because most LCD I've used wrap automatically to the next line.
This code is untested, as I don't have your VB program, nor do I have an LCD at the moment.
Skino:
"...I am sending a string with exactly 32 characters to the Arduino..."
But as you have found there is a difference between your VB program and a terminal program sending 32 characters.
How were we meant to test your code, if we didn't know you were using a customized program?
Good that you got it solved.
Please now edit the subject of this thread and ad [SOLVED] to it.