Hi,
I was trying to communicate several ZB modules between them. There was several routers and one coordinator, but I couldn’t, so instead I try to make a P2P communication.
I tried to used two modules in API mode (2, with escaped character), they associated right, but I don’t receive anything. I couldn’t find the problem.
After that, I tried the most simple example, with two modules in AT mode (transparent), one send, another receive, so I write down my codes because the coordinator, the one which receives the data, didn’t show it well. It only shows wrong data.
I don’t know what is going wrong with this, because if I use x-ctu’s terminal it works fine!!
Can someone help me??
SEND
char *str = {"HOLA"};
int statusLed = 13;
int errorLed = 13;
unsigned long start = millis();
//___________________________________________________________________________________________
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
//___________________________________________________________________________________________
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
Serial.begin(57600);
Serial.println("
... XBee - ZB ...
");
flashLed(statusLed, 1, 500);
}
//___________________________________________________________________________________________
void loop() {
// Serial.flush();
Serial.println(str);
delay(2000); //wait 2 seconds
Serial.flush();
// delay(5000);
}
RECEIVE
int statusLed = 13;
int errorLed = 13;
int dataLed = 13;
char *str;
//___________________________________________________________________________________________
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
//___________________________________________________________________________________________
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
pinMode(dataLed, OUTPUT);
Serial.begin(57600);
Serial.println("
... XBee - ZB ...
");
flashLed(statusLed, 1, 500);
}
//___________________________________________________________________________________________
void loop() {
int i=0;
/*if*/while (Serial.available()) { //If there is data in the Serial Line
// int dataByte = Serial.read(); //save data into integer variable dataByte
str[i] = Serial.read();
i++;
//Serial.print(dataByte,BYTE); //Print to screen the variable received
flashLed(statusLed, 12, 1000);
Serial.print(i,DEC);
Serial.print(". ");
Serial.println(str);
}
Serial.flush();
// delay(5000);
}