Go Down

Topic: Zigbee communication synchronization (Read 736 times) previous topic - next topic

viz_90

I am trying to control Stepper motor from Arduino. One node acts as a coordinator which sends no of rotation to another node which controls the motor. The communication happens through Digi international XBee S2 radios configured in AT mode
Following is the code at sender node

Code: [Select]
void setup()
{
  Serial.begin(9600);
 
}

void loop()
{
Serial.print(006);
    delay(1000);
Serial.print(007);
delay(1000);
}


Following is the code at receiver end

#include <Stepper.h>
byte byteRead;
Stepper stepper(200, 8, 9, 10, 11);

void setup() {               
// Turn the Serial Protocol ON
stepper.setSpeed(30);
  Serial.begin(9600);
}

V
Code: [Select]
oid loop() {
   /*  check if data has been sent from the computer: */
  if (Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read();
Serial.write(byteRead);
for(int i=1;i<=byteRead;i++)
{
stepper.step(200);
delay(1000);
}
}
}




When sender initially receives 6 as no of rotation,The receiver node receives it and rotates the motor 6 times. When the receiver is executing the program to rotate 6 times,the sender sends another data to rotate 7 times. But this data is not received by the receiver.

What must I do to receive every information sent by the sender node? Should I configure radios in API mode?

viz_90

I am trying to control Stepper motor from Arduino. One node acts as a coordinator which sends no of rotation to another node which controls the motor. The communication happens through Digi international XBee S2 radios configured in AT mode
Following is the code at sender node

Code: [Select]
void setup()
{
  Serial.begin(9600);
 
}

void loop()
{
Serial.print(006);
    delay(1000);
Serial.print(007);
delay(1000);
}


Following is the code at receiver end

Code: [Select]
#include <Stepper.h>
byte byteRead;
Stepper stepper(200, 8, 9, 10, 11);

void setup() {               
// Turn the Serial Protocol ON
stepper.setSpeed(30);
  Serial.begin(9600);
}
void loop() {
   /*  check if data has been sent from the computer: */
  if (Serial.available()) {
    /* read the most recent byte */
    byteRead = Serial.read();
Serial.write(byteRead);
for(int i=1;i<=byteRead;i++)
{
stepper.step(200);
delay(1000);
}
}
}




When sender initially receives 6 as no of rotation,The receiver node receives it and rotates the motor 6 times. When the receiver is executing the program to rotate 6 times,the sender sends another data to rotate 7 times. But this data is not received by the receiver.

What must I do to receive every information sent by the sender node? Should I configure radios in API mode?

draythomp

Yep, to guarantee that the data gets there intact, you'll have to use API mode.  The second data byte will get there eventually, but not when you want it to; transparent (AT) mode is buffered and only sent periodically or after a timeout.
Trying to keep my house under control http://www.desert-home.com/

Go Up