Go Down

Topic: LCD Help. (Read 1 time) previous topic - next topic


And if I type 123 it says  

I received: 1
I received: 2
I received: 3

How do I fix this????

Well, what do you WANT it to do?  You'll have to do some sort of parsing of the data you read from the serial port, and that can get sort of arbitrarily complex.  For a first try you can do something like:
Code: [Select]
if (Serial.available() > 0) {
// read the incoming byte:
 incomingByte = Serial.read();
 if (incomingByte < '0' || incomingByte > '9') {
  Serial.println(' ', BYTE);  //newline        
  Serial.print("I received: ");  // new "header"
 } else {
  Serial.print(incomingByte, BYTE);


I wanted it to say:

I Received: 123. Sorry, I should of said that.

However I changed some stuff, and now all I want it to say is:


And then if it type 456 it will clear the screen and say:




Like it does now. Here is my code:
Code: [Select]
byte incomingByte = 0;      // for incoming serial data

void setup() {
     Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
       clearLCD(); //Command 1

void loop() {
   //clearLCD(); //Command 2

     // send data only when you receive data:
     if (Serial.available()) { // read the incoming byte:

               //clearLCD(); // Command 3
           incomingByte = Serial.read(); // say what you got:


void clearLCD(){
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(0x01, BYTE);   //clear command.

If I uncomment the second clearLCD (Command 2) as soon as I try to use a serial connection it starts printing all of these odd characters. And If I uncomment the third  clearLCD (Command 3) it will only print the last character.

Just pull the ATmega168 chip out of the Arduino and it will work fine. Smiley
You'd be 'borrowing' the serial circuitry.

Really? Are you serious? I don't know that much about electronics, but it doesn't seem good to be pulling off chips. ;)

Thank you for all your help!



You are almost there - cool.

What you have to do is when you check with serial.available that there is data then you should use a loop to read all the data one byte at a time until serial.available returns false. Put these data together to make a string, send that string to the LCD, and then use a small delay in your main loop to allow all the data the PC is sending in "the next batch" to be recieved before checking with seriel.available again.

The problem is that serial.available will return true as soon as there is one byte available, so if your main loop is very fast you run the risk of checking for available data before all the data is recieved, reading only one byte (digit), sending that  to the LCD, and start over.

You should not let the PC send to frequently,  give the Arduino board time to read and process all data before sending again.

Normally it would be smart to have some kind if two way communication, leting the Arduino board signal back to the PC, "got that, i'm ready for more". In your case that would be difficult since you don't have anything on the PC to listen for that.



I can't figure this out.

Here is what I want it to do:

if Serial.available is > 1, then save data to a val called test until Serial.available = < 1 .
if Serial.available is < 1, then do nothing.

How do I this???????

I just don't know how to save data to a val.

Sorry for all the questions, but this is my first time in C/C++.

Thank you for all your help!


This should get you pretty close to what you want.

Code: [Select]
int val[10];               // variable used to store data from serial port
int ByteCount = 0;

void setup() {
 Serial.begin(9600);         // connect to the serial port
 Serial.println("Arduio Online");

void loop() {
 if (Serial.available() > 0) {
   while (Serial.available() > 0) {
     ByteCount ++;
     val[ByteCount] = Serial.read();
 if (ByteCount > 0) {
   for (int i = 1; i <= ByteCount; i++) {
     if (val[i] >= '0' && val[i] <= '9' ) {
       val[i]= val[i] - '0';
   ByteCount = 0;

Go Up