Serial communication Arduino Micro + XBee

Hello,

I use Andrew Rapp XBee library with Arduino Uno and works fine.

Now I have Arduino Micro but not works to me with the same code.

Is there any difference in Serial communications between the UNO (ATmega328p) and the Micro (MEGA32U4)?

Best regards

What Serial are you using?

Plus a schematic of your circuit would be helpful as some pins are not usable as Serial on the Micro

Thank you for the reply,

#include <Keypad.h>
#include <XBee.h>
#include <stdlib.h>     /* atoi */


//Objeto XBee
XBee xbee = XBee();





void setup()
{
  Serial.begin(9600);
  xbee.setSerial(Serial);
  ......
}

XBeeAddress64 addr64;
addr64 = XBeeAddress64(0x0013A200, 0x40A29256);
              uint8_t d0Cmd[] = { 'D', '0' };
              uint8_t d0Value[] = { 0x5 };
              RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(addr64, d0Cmd, d0Value, sizeof(d0Value));
              xbee.send(remoteAtRequest);

Arduino Micro – XBEE PRO

1/TX – Din (pin 3)
0/RX – Dout (pin 2)

XBee is supply from battery directly, with a fixed linear regulator 5V to 3V3 600mA, but share GND with Arduino Micro. I have so with Arduino UNO and works fine.

I just made another code and I tried it with another Arduino Micro and another XBee (both different) but it does not work.

#include <Arduino.h>
#include <XBee.h>

XBee xbee = XBee();
XBeeAddress64  addr64 = XBeeAddress64();
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest();


void setup() {
  Serial.begin(9600);
  xbee.setSerial(Serial);

  addr64 = XBeeAddress64(0x0013A200, 0x40A29289);
}

void loop() {
  uint8_t d9Cmd[] = { 'D', '9' };
  
  // ON remote LED
  uint8_t onValue[] = { 0x5 };
  remoteAtRequest = RemoteAtCommandRequest(addr64, d9Cmd, onValue, sizeof(onValue));
  xbee.send(remoteAtRequest);

  delay(900);

  // OFF remote LED  
  uint8_t offValue[] = { 0x4 };
  remoteAtRequest = RemoteAtCommandRequest(addr64, d9Cmd, offValue, sizeof(offValue));
  xbee.send(remoteAtRequest);
}

As far as I know Serial() is the USB port on the Micro. To access the pins 1/Tx and 0/Rx use Serial1()

Thank you!

I have tried so but not works to me.

Regards

#include <XBee.h>

XBee xbee = XBee();

void setup() {
Serial.begin(9600); // USB serial port.
Serial1.begin(9600); // Arduino Micro 1-0 TX-RX
xbee.setSerial(Serial1);
}

void loop() {
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40A29260);
uint8_t d9Cmd = { ‘D’, ‘9’ };

// ON remote LED
uint8_t onValue = { 0x5 };
RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(addr64, d9Cmd, onValue, sizeof(onValue));
xbee.send(remoteAtRequest);

delay(900);

// OFF remote LED
uint8_t offValue = { 0x4 };
remoteAtRequest = RemoteAtCommandRequest(addr64, d9Cmd, offValue, sizeof(offValue));
xbee.send(remoteAtRequest);
}