Skip to content

Commit fd5e924

Browse files
author
andrew.rapp
committed
SoftwareSerial support from Paul Stoffregen
git-svn-id: https://xbee-arduino.googlecode.com/svn/trunk@45 42c8444e-1c8e-11de-a108-cd2f117ce590
1 parent b8e709d commit fd5e924

File tree

13 files changed

+77
-77
lines changed

13 files changed

+77
-77
lines changed

XBee.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,12 @@ uint8_t XBee::getNextFrameId() {
781781
return _nextFrameId;
782782
}
783783

784-
void XBee::begin(long baud) {
785-
_serial->begin(baud);
784+
// Support for SoftwareSerial. Contributed by Paul Stoffregen
785+
void XBee::begin(Stream &serial) {
786+
_serial = &serial;
786787
}
787788

788-
void XBee::setSerial(HardwareSerial &serial) {
789+
void XBee::setSerial(Stream &serial) {
789790
_serial = &serial;
790791
}
791792

XBee.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,9 @@ class XBee {
699699
*/
700700
void readPacketUntilAvailable();
701701
/**
702-
* Starts the serial connection at the supplied baud rate
702+
* Starts the serial connection on the specified serial port
703703
*/
704-
void begin(long baud);
704+
void begin(Stream &serial);
705705
void getResponse(XBeeResponse &response);
706706
/**
707707
* Returns a reference to the current response
@@ -720,7 +720,7 @@ class XBee {
720720
/**
721721
* Specify the serial port. Only relevant for Arduinos that support multiple serial ports (e.g. Mega)
722722
*/
723-
void setSerial(HardwareSerial &serial);
723+
void setSerial(Stream &serial);
724724
private:
725725
bool available();
726726
uint8_t read();
@@ -738,7 +738,7 @@ class XBee {
738738
uint8_t _nextFrameId;
739739
// buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum
740740
uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
741-
HardwareSerial* _serial;
741+
Stream* _serial;
742742
};
743743

744744
/**

build.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project default="dist" name="XBee-Arduino">
33
<property file="build.properties"/>
44
<property name="dist.dir" value="dist"/>
5-
<property name="release" value="0.2.1"/>
5+
<property name="release" value="0.4-softserial-beta"/>
66

77
<target name="init">
88
<mkdir dir="${dist.dir}/XBee"/>
@@ -16,6 +16,7 @@
1616
<fileset dir=".">
1717
<include name="XBee.h"/>
1818
<include name="XBee.cpp"/>
19+
<include name="keywords.txt"/>
1920
<include name="COPYING"/>
2021
</fileset>
2122
</copy>
@@ -27,7 +28,8 @@
2728
<exclude name=".DS_Store"/>
2829
</fileset>
2930
</copy>
30-
31+
32+
3133
<zip basedir="${dist.dir}" destfile="xbee-arduino-${release}.zip"/>
3234
</target>
3335

examples/AtCommand/AtCommand.pde

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
21+
#include <SoftwareSerial.h>
2222

2323
/*
2424
This example is for Series 1 (10C8 or later firmware) or Series 2 XBee radios
2525
Sends a few AT command queries to the radio and checks the status response for success
2626
27-
This example uses the NewSoftSerial library to view the XBee communication. I am using a
27+
This example uses the SoftSerial library to view the XBee communication. I am using a
2828
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
29-
with the Arduino Serial Monitor.
30-
You can obtain the NewSoftSerial library here http://arduiniana.org/libraries/NewSoftSerial/
29+
with the Arduino Serial Monitor.
3130
*/
3231

33-
// Define NewSoftSerial TX/RX pins
34-
// Connect Arduino pin 9 to TX of usb-serial device
35-
uint8_t ssRX = 9;
36-
// Connect Arduino pin 10 to RX of usb-serial device
37-
uint8_t ssTX = 10;
32+
// Define SoftSerial TX/RX pins
33+
// Connect Arduino pin 8 to TX of usb-serial device
34+
uint8_t ssRX = 8;
35+
// Connect Arduino pin 9 to RX of usb-serial device
36+
uint8_t ssTX = 9;
3837
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
39-
NewSoftSerial nss(ssRX, ssTX);
38+
SoftwareSerial nss(ssRX, ssTX);
4039

4140
XBee xbee = XBee();
4241

@@ -52,7 +51,8 @@ AtCommandRequest atRequest = AtCommandRequest(shCmd);
5251
AtCommandResponse atResponse = AtCommandResponse();
5352

5453
void setup() {
55-
xbee.begin(9600);
54+
Serial.begin(9600);
55+
xbee.begin(Serial);
5656
// start soft serial
5757
nss.begin(9600);
5858

examples/RemoteAtCommand/RemoteAtCommand.pde

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
21+
#include <SoftwareSerial.h>
2222

2323
/*
2424
This example is for Series 1 (10C8 or later firmware) or Series 2 XBee
2525
Sends two Remote AT commands to configure the remote radio for I/O line monitoring
2626
27-
This example uses the NewSoftSerial library to view the XBee communication. I am using a
27+
This example uses the SoftSerial library to view the XBee communication. I am using a
2828
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
29-
with the Arduino Serial Monitor.
30-
You can obtain the NewSoftSerial library here http://arduiniana.org/libraries/NewSoftSerial/
29+
with the Arduino Serial Monitor.
3130
*/
3231

33-
// Define NewSoftSerial TX/RX pins
34-
// Connect Arduino pin 9 to TX of usb-serial device
35-
uint8_t ssRX = 9;
36-
// Connect Arduino pin 10 to RX of usb-serial device
37-
uint8_t ssTX = 10;
32+
// Define SoftSerial TX/RX pins
33+
// Connect Arduino pin 8 to TX of usb-serial device
34+
uint8_t ssRX = 8;
35+
// Connect Arduino pin 9 to RX of usb-serial device
36+
uint8_t ssTX = 9;
3837
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
39-
NewSoftSerial nss(ssRX, ssTX);
38+
SoftwareSerial nss(ssRX, ssTX);
4039

4140
XBee xbee = XBee();
4241

@@ -58,7 +57,8 @@ RemoteAtCommandRequest remoteAtRequest = RemoteAtCommandRequest(remoteAddress, i
5857
RemoteAtCommandResponse remoteAtResponse = RemoteAtCommandResponse();
5958

6059
void setup() {
61-
xbee.begin(9600);
60+
Serial.begin(9600);
61+
xbee.begin(Serial);
6262
// start soft serial
6363
nss.begin(9600);
6464

examples/Series1_IoSamples/Series1_IoSamples.pde

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
21+
#include <SoftwareSerial.h>
2222

2323
/*
2424
This example is for Series 1 XBee Radios only
2525
Receives I/O samples from a remote radio with 16-bit addressing.
2626
The remote radio must have IR > 0, at least one digital or analog input enabled
2727
and DL set to the 16-bit address of the receiving XBee (the one connected to the Arduino).
2828
29-
This example uses the NewSoftSerial library to view the XBee communication. I am using a
29+
This example uses the SoftSerial library to view the XBee communication. I am using a
3030
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
3131
with the Arduino Serial Monitor.
32-
You can obtain the NewSoftSerial library here http://arduiniana.org/libraries/NewSoftSerial/
3332
*/
3433

3534
// Define NewSoftSerial TX/RX pins
36-
// Connect Arduino pin 9 to TX of usb-serial device
37-
uint8_t ssRX = 9;
38-
// Connect Arduino pin 10 to RX of usb-serial device
39-
uint8_t ssTX = 10;
35+
// Connect Arduino pin 8 to TX of usb-serial device
36+
uint8_t ssRX = 8;
37+
// Connect Arduino pin 9 to RX of usb-serial device
38+
uint8_t ssTX = 9;
4039
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
41-
NewSoftSerial nss(ssRX, ssTX);
40+
SoftwareSerial nss(ssRX, ssTX);
4241

4342
XBee xbee = XBee();
4443

@@ -47,7 +46,8 @@ Rx16IoSampleResponse ioSample = Rx16IoSampleResponse();
4746
//Rx64IoSampleResponse ioSample = Rx64IoSampleResponse();
4847

4948
void setup() {
50-
xbee.begin(9600);
49+
Serial.begin(9600);
50+
xbee.setSerial(Serial);
5151
// start soft serial
5252
nss.begin(9600);
5353
}

examples/Series1_Rx/Series1_Rx.pde

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
2221

2322
/*
2423
This example is for Series 1 XBee (802.15.4)
@@ -58,7 +57,8 @@ void setup() {
5857
pinMode(dataLed, OUTPUT);
5958

6059
// start serial
61-
xbee.begin(9600);
60+
Serial.begin(9600);
61+
xbee.setSerial(Serial);
6262

6363
flashLed(statusLed, 3, 50);
6464
}

examples/Series1_Tx/Series1_Tx.pde

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
2221

2322
/*
2423
This example is for Series 1 XBee
@@ -66,8 +65,8 @@ void flashLed(int pin, int times, int wait) {
6665
void setup() {
6766
pinMode(statusLed, OUTPUT);
6867
pinMode(errorLed, OUTPUT);
69-
70-
xbee.begin(9600);
68+
Serial.begin(9600);
69+
xbee.setSerial(Serial);
7170
}
7271

7372
void loop() {

examples/Series2_IoSamples/Series2_IoSamples.pde

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
21+
#include <SoftwareSerial.h>
2222

2323
/*
2424
This example is for Series 2 (ZigBee) XBee Radios only
2525
Receives I/O samples from a remote radio.
2626
The remote radio must have IR > 0 and at least one digital or analog input enabled.
2727
The XBee coordinator should be connected to the Arduino.
2828
29-
This example uses the NewSoftSerial library to view the XBee communication. I am using a
29+
This example uses the SoftSerial library to view the XBee communication. I am using a
3030
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
31-
with the Arduino Serial Monitor.
32-
You can obtain the NewSoftSerial library here http://arduiniana.org/libraries/NewSoftSerial/
31+
with the Arduino Serial Monitor.
3332
*/
3433

3534
// Define NewSoftSerial TX/RX pins
36-
// Connect Arduino pin 9 to TX of usb-serial device
37-
uint8_t ssRX = 9;
38-
// Connect Arduino pin 10 to RX of usb-serial device
39-
uint8_t ssTX = 10;
35+
// Connect Arduino pin 8 to TX of usb-serial device
36+
uint8_t ssRX = 8;
37+
// Connect Arduino pin 9 to RX of usb-serial device
38+
uint8_t ssTX = 9;
4039
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
41-
NewSoftSerial nss(ssRX, ssTX);
40+
SoftwareSerial nss(ssRX, ssTX);
4241

4342
XBee xbee = XBee();
4443

@@ -47,7 +46,8 @@ ZBRxIoSampleResponse ioSample = ZBRxIoSampleResponse();
4746
XBeeAddress64 test = XBeeAddress64();
4847

4948
void setup() {
50-
xbee.begin(9600);
49+
Serial.begin(9600);
50+
xbee.setSerial(Serial);
5151
// start soft serial
5252
nss.begin(9600);
5353
}

examples/Series2_Rx/Series2_Rx.pde

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include <XBee.h>
21-
#include <NewSoftSerial.h>
2221

2322
/*
2423
This example is for Series 2 XBee
@@ -55,7 +54,8 @@ void setup() {
5554
pinMode(dataLed, OUTPUT);
5655

5756
// start serial
58-
xbee.begin(9600);
57+
Serial.begin(9600);
58+
xbee.begin(Serial);
5959

6060
flashLed(statusLed, 3, 50);
6161
}

0 commit comments

Comments
 (0)