XBeeArduino
is an Arduino-friendly C++ wrapper for the xbee_c_library, providing a simplified interface for integrating XBee modules into Arduino projects.
xbee_c_library
as a submoduleClone the repository with its submodule:
git clone --recurse-submodules https://github.com/your-username/XBeeArduino.git
Include the XBeeArduino
header and source files in your Arduino project.
Check out the examples/xbee_lr/xbee_lr.ino
for a basic usage example with the XBee LR.
This project is licensed under the MIT License - see the LICENSE file for details.
XBeeArduino Class MethodsThe XBeeArduino
class provides several methods to interact with XBee modules:
bool begin()
: Initializes the XBee module. Returns true
if initialization is successful.bool connect()
: Establishes a connection with the XBee module. Returns true
if the connection is successful.void process()
: Continuously processes incoming data from the XBee module.bool disconnect()
: Disconnects from the XBee module. Returns true
if the disconnection is successful.bool sendData(const T& data)
: Sends data through the XBee module. The data type T
can vary depending on the use case.bool isConnected()
: Checks if the XBee module is currently connected. Returns true
if connected.void reset()
: Resets the XBee module to its default state.bool setLoRaApiOptions(const uint8_t options)
: Configures specific options for LoRa communication using the provided options
.bool getLoRaDevEUI(uint8_t* devEUI, uint8_t length)
: Retrieves the LoRa Device EUI into the provided devEUI
array.void (*onReceiveCallback_)
: Function pointer for a callback when data is received.void (*onSendCallback_)
: Function pointer for a callback when data is sent.void onReceiveWrapper(XBee* xbee, void* data)
: Internal method to wrap the receive callback.void onSendWrapper(XBee* xbee, void* data)
: Internal method to wrap the send callback.#include <XBeeArduino.h> XBeeArduino xbee; void setup() { Serial.begin(9600); if (xbee.begin()) { Serial.println("XBee initialized successfully."); } else { Serial.println("Failed to initialize XBee."); } if (xbee.connect()) { Serial.println("XBee connected."); } else { Serial.println("Failed to connect XBee."); } } void loop() { xbee.process(); if (xbee.isConnected()) { String data = "Hello, XBee!"; if (xbee.sendData(data)) { Serial.println("Data sent successfully."); } else { Serial.println("Failed to send data."); } } else { Serial.println("XBee not connected."); } delay(1000); }
This example demonstrates how to initialize, connect, send data, and process incoming data with the XBeeArduino library.
The XBeeArduino
class constructor allows you to initialize the XBee module with either HardwareSerial
or SoftwareSerial
.
XBeeArduino(HardwareSerial* serial, int baudRate); XBeeArduino(SoftwareSerial* serial, int baudRate);
serial
: Pointer to either HardwareSerial
or SoftwareSerial
. This determines the serial interface used for communication.baudRate
: The baud rate for serial communication, typically 9600
or 115200
.#include <XBeeArduino.h> XBeeArduino xbee(&Serial, 9600); void setup() { Serial.begin(9600); if (xbee.begin()) { Serial.println("XBee initialized with HardwareSerial."); } } void loop() { xbee.process(); }
#include <XBeeArduino.h> #include <SoftwareSerial.h> SoftwareSerial mySerial(10, 11); // RX, TX XBeeArduino xbee(&mySerial, 9600); void setup() { mySerial.begin(9600); if (xbee.begin()) { Serial.println("XBee initialized with SoftwareSerial."); } } void loop() { xbee.process(); }Using XBeeArduino Library in Arduino IDE
To use the XBeeArduino
library in the Arduino IDE:
Install the Library:
XBeeArduino
library repository.Documents/Arduino/libraries/
).Include the Library in Your Sketch:
#include <XBeeArduino.h>
.Compile and Upload:
XBeeArduino
library.Here’s an example of how to use the XBeeArduino
library in an Arduino sketch:
#include <XBeeArduino.h> #include <SoftwareSerial.h> SoftwareSerial mySerial(10, 11); // RX, TX XBeeArduino xbee(&mySerial, 9600); void setup() { Serial.begin(9600); mySerial.begin(9600); if (xbee.begin()) { Serial.println("XBee initialized."); } } void loop() { xbee.process(); if (xbee.isConnected()) { String data = "Hello, XBee!"; if (xbee.sendData(data)) { Serial.println("Data sent successfully."); } else { Serial.println("Failed to send data."); } } else { Serial.println("XBee not connected."); } delay(1000); }
This example demonstrates setting up the XBee module, processing incoming data, and sending data using the XBeeArduino
library in the Arduino IDE.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4