Pages: [1]   Go Down
Author Topic: Zigbee communication synchronization  (Read 652 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
#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?
Logged

New River, Arizona
Offline Offline
God Member
*****
Karma: 19
Posts: 936
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Trying to keep my house under control http://www.desert-home.com/

Pages: [1]   Go Up
Jump to: