hii every budy /// im trying to send 2 float numbers via xbee using packet marker () {} ... my problem that i cant find the original arduino code for this method i found several codes for proccessing and bytes but couldent make it work ... so if any one can direct me into asimple arduino code it would be great cus i realy searched alot /// thanks in advance ///
boolean started = false;
boolean ended = false;
char inData[24]; // Size as appropriate
byte index = 0;
#define SOP "{"
#define EOP "}"
void loop()
{
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
started = true;
index = 0;
inData[index] = '\0';
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 24-1) // Array size
{
inData[index++] = inChar;
inData[index] = '\0';
}
}
}
if(started && ended)
{
// Parse the data in inData here...
}
}
thanks alot paul i will try this code cus mine is very very long here :
void setup()
{
Serial.begin(9600);
}
void loop()
{
char charIn = 0;
byte i = 0;
char stringIn[32] = "";
char startchar;
float availableData = Serial.available();
if ( availableData > 0 ) {
startchar = Serial.read();
if ( startchar == '{' ) {
while ( charIn != '}' ) {
if ( Serial.available() > 0 ) {
charIn = Serial.read();
if ( charIn == '}' ) {
break;
}
stringIn = charIn;
- i += 1;*
- }*
- }*
- float lat1= atof(stringIn);*
- Serial.println(lat1,7);*
- delay(3000);*
- }*
if ( startchar == '(' ) {
- while ( charIn != ')' ) {*
- if ( Serial.available() > 0 ) {*
- charIn = Serial.read();*
- if ( charIn == ')' ) {*
- break;*
- }*
_ stringIn = charIn;_
* i += 1;*
* }*
* }*
* float lon= atof(stringIn);*
* Serial.println(lon,7);*
* delay(3000);*
* }*
}
}
float availableData = Serial.available();
Serial.available() can hardly report that there are 3 and half characters to read, now, can it?
char charIn = 0;
byte i = 0;
char stringIn[32] = "";
With these as local variables, an entire packet would need to be available to be read in a single iteration of loop. That seems highly unlikely.