Pages: 1 [2]   Go Down
Author Topic: Parsing serial data sent to an arduino  (Read 16999 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again PaulS,

I did verify the lcd again with another sketch. And the only way i can be sure it is receiving serial data is the rx light blinking. The program sending the serial data may be overwhelming the arduino though with the amount of data it is sending. Is that possible?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The program sending the serial data may be overwhelming the arduino though with the amount of data it is sending. Is that possible?
Not really. The Arduino has a serial receive buffer that may fill up. The extra data is silently discarded, though.

If the rx light is blinking, the Arduino should be receiving data. However, I just noticed that you do not have a Serial.begin statement in setup() of the last sketch you posted. That would explain why the Arduino never gets the serial data.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah you are right. But in the initial sketch i did have it but no luck. That sketch is here:

Code:
#include <LiquidCrystal.h>
#include <string.h>
char inData[80];
char flightdata[80];
byte index = 0;
LiquidCrystal lcd(12, 11, 2, 3, 4, 5);

void setup()
{
Serial.begin(115200);
lcd.begin(20, 4);
}

void loop()
{
   while(Serial.available() > 0)
   {
      char aChar = Serial.read();
      if(aChar == '\n')
      {
            char *p = inData; //point to *p to the string in inData
            char *str;        //declaring *str
            int counter = 0; //initialise the counter

            while (str = strtok_r(p, ",", &p)) // delimiter is the comma
            {
                  flightdata[counter] = *str; //use the counter as an index to add each value to the array
                  counter++; //increment the counter

               p = NULL;
            }
            lcd.setCursor(0, 0);
            lcd.print("Speed: "); lcd.print(flightdata[0]); //print out the data stored in the value storage array index '0'
            //set cursor to next line using appropiate commands again
            lcd.setCursor(0, 1);
            lcd.print("Altitude: "); lcd.print(flightdata[1]); //ditto



         index = 0;
         inData[index] = NULL;
          
      }
      else
      {
         inData[index] = aChar;
         index++;
         inData[index] = '\0'; // Keep the string NULL terminated
      }
   }
}
« Last Edit: August 10, 2010, 01:37:22 pm by juerujin » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This code does nothing until the incoming serial data contains a \n. Since nothing happens, I'm forced to assume that the incoming serial data does not actually contain a carriage return.

Just for giggles, change this:
Code:
if(aChar == '\n')
to this:
Code:
if(aChar == '\n' || index == 20)
Logged

Pages: 1 [2]   Go Up
Jump to: