Teensy 3.6 + Xbee Issue

Status
Not open for further replies.
Hello.
I'm having a project that connects Teensy 3.6 with XBee.

the coordinator is:
teensy+xbee
3.3v=>3.3v
grd=>grd
pin7=>pin3 //Rx pin
pin8=>pin2 //Tx pin

1node is:
teensy+xbee
3.3v=>3.3v
grd=>grd
pin7=>pin3 //Rx pin
pin8=>pin2 //Tx pin

2 node are notebook+xbees via XCTU.
My problem is that the coordinator cannot receive any data from node.
I using XCTU to scan the mesh. and it sees the coordinator, and the node connected to the notebook, but it cannot see the teensy node.
I use XCTU to send a packet to coordinator, coordinator cannot receive it.
I use teensy node to send a packet to coordinator, coordinator cannot receive it. The Pan ID of all the xbee is same. API mode 2.
Could you please to figure out what is the wrong point of my code. The code and the serial print is below.

Thank you very much.



The code for the coordinator is:


Code:
#include <XBee.h>
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16Response rx16 = Rx16Response();
Rx64Response rx64 = Rx64Response();

int statusLed = 11;
int errorLed = 12;
int dataLed = 10;

uint8_t option = 0;
uint8_t data = 0;

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);
  
  // start serial
  Serial.begin(115200);
  while(!Serial)
  {    
  }
  Serial3.begin(9600);
  xbee.setSerial(Serial3);  
  flashLed(statusLed, 3, 50);
}

void loop() {
    Serial.println("start loop");
    xbee.readPacket(500);    
    if (xbee.getResponse().isAvailable()) {
      if (xbee.getResponse().getApiId() == RX_16_RESPONSE || xbee.getResponse().getApiId() == RX_64_RESPONSE) {
        if (xbee.getResponse().getApiId() == RX_16_RESPONSE) {
                xbee.getResponse().getRx16Response(rx16);
        	option = rx16.getOption();
        	data = rx16.getData(0);
        } else {
                xbee.getResponse().getRx64Response(rx64);
        	option = rx64.getOption();
        	data = rx64.getData(0);
        }   
        flashLed(statusLed, 1, 10);
        analogWrite(dataLed, data);
      } else {
        flashLed(errorLed, 1, 25);    
      }
    } else if (xbee.getResponse().isError()) {
      Serial.println("error");
    } 
    else
    {
      Serial.println("no data");
    }
}

The teensy node is:



Code:
#include  <XBee.h>
XBee  xbee  = XBee();
unsigned  long  start = millis();
uint8_t payload[] = { 0,  0 };
XBeeAddress64 addr64  = XBeeAddress64(0x0013A200, 0x4179cc95); //coordinator address
Tx64Request tx  = Tx64Request(addr64, payload,  sizeof(payload));
TxStatusResponse  txStatus  = TxStatusResponse();
int pin5  = 0;
int statusLed = 11;
int errorLed  = 12;

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(115200);
    Serial3.begin(9600);
    xbee.setSerial(Serial3);
}

void  loop()  { 
        if  (millis() - start > 15000)  {
            //  break down  10-bit  reading into  two bytes and place in  payload
            pin5  = analogRead(5);
            payload[0]  = pin5  >>  8 & 0xff;
            payload[1]  = pin5  & 0xff;            
            xbee.send(tx);
            Serial.print("A5=");
            Serial.print(pin5);
            Serial.println(". Data  was sent");
            flashLed(statusLed, 1,  100);
        }
        if  (xbee.readPacket(5000)) {                 
            if  (xbee.getResponse().getApiId()  ==  TX_STATUS_RESPONSE) {
                  xbee.getResponse().getTxStatusResponse(txStatus);
                      if  (txStatus.getStatus() ==  SUCCESS)  {
                            flashLed(statusLed, 5,  50);
                            Serial.println("ACK was received");
                      } else  {
                            flashLed(errorLed,  3,  500);
                            Serial.println("ACK was not received");
                      }
                }           
        } else  if  (xbee.getResponse().isError())  {
            Serial.println("error");
        } else  {
            flashLed(errorLed,  2,  50);
            Serial.println("No response");
        }        
        delay(1000);
}

The result of coordinator is:
start loop
no data
start loop
no data
....

The result of node is
A5=565. Data was sent
No response
A5=614. Data was sent
No response
....
 
Last edited by a moderator:
Hello.
I'm having a project that connects Teensy 3.6 with XBee.

the coordinator is:
teensy+xbee
3.3v=>3.3v
grd=>grd
pin7=>pin3 //Rx pin
pin8=>pin2 //Tx pin

1node is:
teensy+xbee
3.3v=>3.3v
grd=>grd
pin7=>pin3 //Rx pin
pin8=>pin2 //Tx pin


....

I think you have a basic error configuration there - the connections are Tx to Tx and Rx to Rx instead of Tx to Rx and Rx to Tx :p.

They should read:
pin7 //Rx pin => pin2 //Tx pin
pin8 //Tx pin => pin3 //Rx pin
 
I think you have a basic error configuration there - the connections are Tx to Tx and Rx to Rx instead of Tx to Rx and Rx to Tx :p.

They should read:
pin7 //Rx pin => pin2 //Tx pin
pin8 //Tx pin => pin3 //Rx pin

I don't really get it. You mean i should wire like this, aren't you?
pin7 //Rx pin => pin2 //Tx pin
pin8 //Tx pin => pin3 //Rx pin

I feel so confused. :(
 
Exactly so.
Tx to Rx and vice versa
As I learn so far, Tx to Rx pin is used when you connect 2 Arduino directly.
In my case, I use XBee as the transmitter, so tx to tx. That is what I learned.
BTW I already tried to wire as you said, no thing happen. still struggling in it. :(
 
Status
Not open for further replies.
Back
Top