Go Down

Topic: Serial decoding! ints, floats & strings OH My! (Read 445 times) previous topic - next topic

Keshka

I have been looking around the playground and here a bit and have not found any libraries for sending complex information over the serial port. An example would be sending a structure, float values or long text strings.  I could write something....used to do something along these lines by separating the data with the pipe symbol.  Probably the simplest example of what I am looking for would be sending an integer. One must convert it to a string, send the string one char at a time, some ending marker and then the receive side must piece it back together again like first char +=, second * 10 += and so on.

I am just being lazy! Seems like such a routine thing that SOMEBODY has to have done this before. Such is the power of open source  ;)

Keshka

mem

#1
Oct 17, 2009, 09:08 pm Last Edit: Oct 17, 2009, 09:10 pm by mem Reason: 1
Here is a simple example of how to send an array of integers as a comma separated string with a cr/lf terminator

Code: [Select]

const int COUNT = 5;
int values[COUNT] = {3,1,4,1,5};

for(int i=0;i < COUNT; i++)
{
  Serial.print(values[i]);
  if( i < COUNT-1)
    Serial.print(',');    
}
Serial.println();

Go Up