Using Xbee S2C with Arduino Nano on SPI

I want to use two Xbee S2C modules with a single Arduino Nano. I have connected one of those Xbees to the Nano via UART and since there are no more UART interfaces, I'm trying to interface the second one using SPI. I'm using the following Xbee library for SPI interfacing. This library is applicable for the AT mode.


I have tried the "basic_tx" example code provided in the repo:

 * File                 basic_tx.ino
 * Synopsis             Simple example sketch to demonstrate transmission of data
 * Author               Chris Bearman
 * Version              2.0
#include <XbeeWifi.h>

// These are the pins that we are using to connect to the Xbee

#define XBEE_ATN 2
#define XBEE_SELECT 10

// These are the configuration parameters we're going to use
#define CONFIG_ENCMODE XBEE_SEC_ENCTYPE_WPA2     // Network type is WPA2 encrypted
#define CONFIG_SSID "Example"                    // SSID
#define CONFIG_KEY "whatever"                    // Password

// Create an xbee object to handle things for us
XbeeWifi xbee;

unsigned long int next_tx;

// Setup routine
void setup()
  // Serial at 57600
  // Initialize the xbee
  bool result = xbee.init(XBEE_SELECT, XBEE_ATN);

  if (result) {
    // Initialization okay so far, send setup parameters - if anything fails, result goes false
    result &= xbee.at_cmd_byte(XBEE_AT_NET_TYPE, XBEE_NET_TYPE_IBSS_INFRASTRUCTURE);
    result &= xbee.at_cmd_str(XBEE_AT_NET_SSID, CONFIG_SSID);
    result &= xbee.at_cmd_byte(XBEE_AT_NET_ADDRMODE, XBEE_NET_ADDRMODE_DHCP);
    result &= xbee.at_cmd_byte(XBEE_AT_SEC_ENCTYPE, CONFIG_ENCMODE);
      result &= xbee.at_cmd_str(XBEE_AT_SEC_KEY, CONFIG_KEY);
  if (!result) {
    // Something failed
    Serial.println("XBee Init Failed");
    while (true) { /* Loop forever - game over */}
  } else {    
    Serial.println("XBee found and configured");
  next_tx = millis();

// Main run loop
// Transmit "Hello World" on UDP, to every 1 minute (using port 12345)
void loop()
  // Just keep calling the process method on the xbee object
  if (millis() > next_tx) {
    if (xbee.last_status != XBEE_MODEM_STATUS_JOINED) {
      Serial.println("Not yet up and running");
    } else {
      Serial.println("Transmitting now");
      // Create an s_txoptions object to describe the port, protocol and behaviors
      s_txoptions txopts;
      txopts.protocol = XBEE_NET_IPPROTO_UDP;

      // Create a binary IP address representation      
      char ip[] = { 192, 168, 1, 150 };
      // Transmit the frame
      if (!xbee.transmit((uint8_t *)ip, &txopts, (uint8_t *)"Hello World", 11)) {
        Serial.println("Transmit failed");
      } else {
        Serial.println("Transmit OK");    
     // Repeat in one minute
     next_tx = millis() + 1000L;

Problem faced:
I just want to communicate with another XBee set to the same PANID as the one connected to the SPI interface on Arduino Nano in AT mode but the code given above is to connect the XBee to a network having a certain IP address.

If someone has experience using this library I would be grateful if you could guide me in establishing a simple connection between the two XBees in AT mode using this library.

Thank you in advance :slight_smile:

XBee S2C doesn't support Wifi or have an SPI interface.

SoftwareSerial might be an option.

Thank you @mikb55 . The issue in my case is that I have another GPS module that requires UART interface as well. I saw that SoftwareSerial library is not very efficient and reliable. I checked for other such libraries and found AltSoftSerial and NeoSWSerial. But I'm apprehensive whether it's advisable to have two devices, one using NeoSWSerial and the other using AltSoftSerial. Could you please suggest a solution?