Hi guys I;m having this problem trying to display the received data from xbee im just trying it using the serial coms for now just to get something working.
If i send Data like this
<23,67,13>
I would like the the reviver to send this to the serial coms like this
Data1: 23
Data2: 67
Data3: 13
Here is code i have been trying but no luck if i send <23,67,13> i get this in the serial
Data1: 50
Data2: 51
Data3: 44
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
int Count = 0;
int Apos = 0, Bpos = 0, Cpos = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
int inChar = Serial.read();
if(inChar == SOP)
{
Count = 0;
inData[Count] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
inData[Count] = inChar;
Count++;
inData[Count] = '\0';
}
}
if(started && ended)
{
Apos = inData[0];
Bpos = inData[1];
Cpos = inData[2];
Serial.print("Data1:" );
Serial.println(Apos);
Serial.print("Data2:" );
Serial.println(Bpos);
Serial.print("Data3:" );
Serial.println(Cpos);
started = false;
ended = false;
Count = 0;
inData[Count] = '\0';
}
}
And here is another code but same thing on output to serial
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
int Apos = 0, Bpos = 0, Cpos = 0;
char inData[80];
byte index;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
if(started && ended)
{
Apos = inData[0];
inData[0] = ' ';
int A1 = atoi(inData);
Serial.print("Data1:" );
Serial.println(Apos);
Bpos = inData[1];
inData[1] = ' ';
int A2 = atoi(inData);
Serial.print("Data2:" );
Serial.println(Bpos);
Cpos = inData[2];
inData[2] = ' ';
int A3 = atoi(inData);
Serial.print("Data3:" );
Serial.println(Cpos);
//Reset
started = false;
ended= false;
index = 0;
inData[index]='\0';
}
}