Go Down

Topic: send array of integers via xBee s1 (Read 3 times) previous topic - next topic

PaulS

Quote
does it need some time to delete the readen data or is it immediate?

It happens before the read() method returns.

Quote
I've had some trouble because as I send something like 1,2,3 with the code you gave me I receive 1111,,,,2222,,,,3333

What are you sending from? It looks to me like the problem is on the sending end.

Quote
and I'm wondering if it's a problem with some delay() I should use.

Let me see if I can express this in a way that you can understand.
N
delay(3)
o
delay(3)
i
delay(3)
s
delay(3)
n
delay(3)
e
delay(3)
e
delay(3)
d
delay(3)
e
delay(3)
d

Period. Anywhere.

propilot01

I send a string from the other arduino. It's like c=<1,123,123,200> and in the code I wrote Serial.print(c). So in the end do I have to give some delay somewhere? Or should I send the data I want not as a string?

PaulS

Quote
I send a string from the other arduino. It's like c=<1,123,123,200> and in the code I wrote Serial.print(c). So in the end do I have to give some delay somewhere? Or should I send the data I want not as a string?

How about C) post your code.

propilot01

the sending code:
Code: [Select]
#include <SoftwareSerial.h>

const int x=2;
const int y=1;
const int z=0;
int sx=0;
int sy=0;
int sz=0;
String datapac="";
SoftwareSerial mySerial(10, 11);

void setup()
{
 Serial.begin(9600);
 mySerial.begin(9600);
 pinMode(x,INPUT);
 pinMode(y,INPUT);
 pinMode(z,INPUT);
 pinMode(10, INPUT);
 pinMode(11, OUTPUT);
}

void loop()
{
 sx=analogRead(x);
 sy=analogRead(y);
 sz=analogRead(z);
 sx=map(sx,0,1023,0,255);
 sy=map(sy,0,1023,0,255);
 sz=map(sz,0,1023,0,1);
 delay(10);
 datapac += "<";
 datapac += String(sz);
 datapac += ",";
 datapac += String(sx);
 datapac += ",";
 datapac += String(sy);
 datapac += ",";
 datapac += String(200);
 datapac += ">";
 /*if(Serial.available()>0)
 {*/
   Serial.print(datapac);
   mySerial.print(datapac);
 /*}*/
 delay(20);
 datapac="";
}

the reading/control code:
attached to the post.

PaulS

Code: [Select]
String datapac="";
  datapac += "<";
  datapac += String(sz);
  datapac += ",";
  datapac += String(sx);
  datapac += ",";
  datapac += String(sy);
  datapac += ",";
  datapac += String(200);
  datapac += ">";

Why? All those Strings are unnecessary.


Go Up