i've written a program in delphi that sends a string to the COM port, the arduino reads it and sends it
back. I can read the send back data perfectly. What i don't seem to manage is how i can convert
the serial data (they come in trough decimal numbers that represent the ASCII table) and show it
on my lcd. Whatever i try, not works and it keeps outputting me the decimals instead of the string
itself...
Serial speed is both tested on 9600 and 19200 , works the same way to read/write
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4,5,6,7);
int val = 0; // variable to store the data from the serial port
int ledPin1 = 13; // LED connected to digital pin 13
int state = 0;
String content = "";
String character;
void setup() {
pinMode(ledPin1,OUTPUT); // declare the LED's pin as output
Serial.begin(19200); // connect to the serial port
}
void loop () {
val = Serial.read(); // read the serial port
if (val > 0) {
character=String(val);
content.concat(character);
Serial.write(val);
}
lcd.setCursor(0, 1);
lcd.print(content);
}
I thought this was an easy task to get out but i'm kinda stuck in this. Any ideas ?
I'm very new to this myself, but when my LCD was working, I couldn't pass strings to it. It's likely that I was missing something in my code, but, regardless, I think arloG is on to something with bypass the string typing.
Sorry I took so long. To test this, I had to retrieve an LCD from my pile of components and solder leads to it.
I tried to simplify what you had and then test it with the Arduino IDE serial monitor. I assumed that you want to send strings terminated with a null and have these strings displayed starting at the first position on the top row of the LCD. You had lcd.setCursor(0, 1); which I think is the second row.
Since I was using the Arduino serial monitor, I didn't know how to generate a null so I chose "X" as the terminating character. When this program reads an "X", it clears the display and will then start displaying again at first char/top row. Remove these lines if delphi is doing the sending. Otherwise, "X" will cause a mysterious display reset.
There are some other changes. I think you need to set up the LCD in, er, setup. I threw out the led and other stuff that wasn't required for this snippet. And I have a compulsion to dither other people's code.
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4,5,6,7);
char val = 0; // variable to store the data from the serial port
void setup()
{ lcd.begin(16,2); //need to set up LCD characteristics
Serial.begin(9600); //19200 doesn't work for me
}
void loop ()
{ if (Serial.available()) //look for serial data
{ val = Serial.read(); // if it's available, read the serial port
if (val == 0) //I assume that you're using null as the terminator of the Delphi string
lcd.clear();
else if(val=='X') //for debugging from serial monitor
lcd.clear();
else
{ Serial.write(val); //echo char to serial monitor
lcd.print(val); //print char on LCD
}
}
}