Skip to content

Commit b75fff7

Browse files
Fix compiler issues due to SofwareSerial
When SerialFirmata was extracted from StandardFirmataPlus to a separate class it broke the ability to compile Firmata with versions of the Arduino IDE older than 1.6.6. This is because prior to 1.6.6 Arduino did not allow libraries to include other libraries unless the other library was included in the sketch. In this particular case that was not possible because SerialFirmata is compiled before the sketch is compiled. There were a couple of potential work arounds: 1. Only include SoftwareSerial when compiling in Arduino 1.6.6 or higher. 2. Split SerialFirmata into SoftwareSerialFirmata and HardwareSerialFirmata and then include SoftwareSerial in the sketch if SoftwareSerialFirmata is included. However this requires the user to modify the sketch. I opted for option 1. If users really need to use software serial with SerialFirmata in Arduino 1.6.5 or older, I can reconsider option 2 at a later time.
1 parent 6ac21c6 commit b75fff7

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

examples/StandardFirmataBLE/StandardFirmataBLE.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* Uncomment the following include to enable interfacing
3535
* with Serial devices via hardware or software serial.
3636
*/
37+
// In order to use software serial, you will need to compile this sketch with
38+
// Arduino IDE v1.6.6 or higher. Hardware serial should work back to Arduino 1.0.
3739
//#include "utility/SerialFirmata.h"
3840

3941
// follow the instructions in bleConfig.h to configure your BLE hardware

examples/StandardFirmataEthernet/StandardFirmataEthernet.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
* remaining to reliably run Firmata. Arduino Yun is okay because it doesn't import the Ethernet
7979
* libraries.
8080
*/
81+
// In order to use software serial, you will need to compile this sketch with
82+
// Arduino IDE v1.6.6 or higher. Hardware serial should work back to Arduino 1.0.
8183
//#include "utility/SerialFirmata.h"
8284

8385
#define I2C_WRITE B00000000

examples/StandardFirmataPlus/StandardFirmataPlus.ino

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
See file LICENSE.txt for further informations on licensing terms.
2222
23-
Last updated by Jeff Hoefs: January 10th, 2016
23+
Last updated October 16th, 2016
2424
*/
2525

2626
/*
@@ -36,6 +36,9 @@
3636
- Ability to interface with serial devices using UART, USART, or SoftwareSerial
3737
depending on the capatilities of the board.
3838
39+
NOTE: In order to use SoftwareSerial with the Firmata Serial feature,
40+
StandardFirmataPlus must be compiled with Arduino v1.6.6 or newer.
41+
3942
At the time of this writing, StandardFirmataPlus will still compile and run
4043
on ATMega328p and ATMega32u4-based boards, but future versions of this sketch
4144
may not as new features are added.
@@ -45,6 +48,8 @@
4548
#include <Wire.h>
4649
#include <Firmata.h>
4750

51+
// In order to use software serial, you will need to compile this sketch with
52+
// Arduino IDE v1.6.6 or higher. Hardware serial should work back to Arduino 1.0.
4853
#include "utility/SerialFirmata.h"
4954

5055
#define I2C_WRITE B00000000

examples/StandardFirmataWiFi/StandardFirmataWiFi.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
* Uncomment the following include to enable interfacing with Serial devices via hardware or
9090
* software serial.
9191
*/
92+
// In order to use software serial, you will need to compile this sketch with
93+
// Arduino IDE v1.6.6 or higher. Hardware serial should work back to Arduino 1.0.
9294
//#include "utility/SerialFirmata.h"
9395

9496
// follow the instructions in wifiConfig.h to configure your particular hardware

utility/SerialFirmata.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414
1515
- handlePinMode calls Firmata::setPinMode
1616
17-
Last updated by Jeff Hoefs: January 10th, 2016
17+
Last updated October 16th, 2016
1818
*/
1919

2020
#include "SerialFirmata.h"
2121

2222
SerialFirmata::SerialFirmata()
2323
{
24+
#if defined(SoftwareSerial_h)
2425
swSerial0 = NULL;
2526
swSerial1 = NULL;
2627
swSerial2 = NULL;
2728
swSerial3 = NULL;
29+
#endif
2830

2931
serialIndex = -1;
3032
}

utility/SerialFirmata.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
- Defines FIRMATA_SERIAL_FEATURE (could add to Configurable version as well)
1616
- Imports Firmata.h rather than ConfigurableFirmata.h
1717
18-
Last updated by Jeff Hoefs: January 10th, 2016
18+
Last updated October 16th, 2016
1919
*/
2020

2121
#ifndef SerialFirmata_h
2222
#define SerialFirmata_h
2323

2424
#include <Firmata.h>
2525
#include "FirmataFeature.h"
26-
// SoftwareSerial is currently only supported for AVR-based boards and the Arduino 101
27-
// The third condition checks if the IDE is in the 1.0.x series, if so, include SoftwareSerial
28-
// since it should be available to all boards in that IDE.
29-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ARC32) || (ARDUINO >= 100 && ARDUINO < 10500)
26+
// SoftwareSerial is currently only supported for AVR-based boards and the Arduino 101.
27+
// Limited to Arduino 1.6.6 or higher because Arduino builder cannot find SoftwareSerial
28+
// prior to this release.
29+
#if (ARDUINO > 10605) && (defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ARC32))
3030
#include <SoftwareSerial.h>
3131
#endif
3232

@@ -155,10 +155,12 @@ class SerialFirmata: public FirmataFeature
155155
int serialBytesToRead[SERIAL_READ_ARR_LEN];
156156
signed char serialIndex;
157157

158+
#if defined(SoftwareSerial_h)
158159
Stream *swSerial0;
159160
Stream *swSerial1;
160161
Stream *swSerial2;
161162
Stream *swSerial3;
163+
#endif
162164

163165
Stream* getPortFromId(byte portId);
164166

0 commit comments

Comments
 (0)