Skip to content

Commit 95502b4

Browse files
committed
Remove SoftwareSerial default import to avoid ESP32 compile error
1 parent f14b842 commit 95502b4

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

examples/01_Basic_UART/01_Basic_UART.ino

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
/* **************************************************
2+
*
3+
* Example Code for running ScioSense APC1 on UART
4+
* tested with Arduino UNO and ESP32
5+
*
6+
* **************************************************
7+
*/
8+
19
#include <Arduino.h>
2-
#include <SoftwareSerial.h>
310

411
#include <apc1.h>
512

@@ -10,6 +17,12 @@ using namespace ScioSense;
1017

1118
APC1 apc1;
1219

20+
// If your board only has one hardware serial bus, use SoftwareSerial
21+
#ifndef ESP32
22+
#include <SoftwareSerial.h>
23+
SoftwareSerial softwareSerial = SoftwareSerial(rxPin, txPin);
24+
#endif
25+
1326
void setup()
1427
{
1528
Serial.begin(9600);
@@ -18,13 +31,16 @@ void setup()
1831
// Enable Debug if needed
1932
//apc1.enableDebugging(Serial);
2033

21-
// If your board only has one hardware serial bus use SoftwareSerial (uncomment the following two lines):
22-
//SoftwareSerial softwareSerial = SoftwareSerial(rxPin, txPin);
23-
//apc1.begin(softwareSerial);
24-
25-
// If your board supports a second hardware serial bus (like the ESP32), then use Serial1 or Serial2
26-
Serial2.begin(9600, SERIAL_8N1, rxPin, txPin);
27-
apc1.begin(Serial2);
34+
// If your board supports a second hardware serial bus (like the ESP32)...
35+
#ifdef ESP32
36+
// ...then use Serial1 or Serial2
37+
Serial2.begin(9600, SERIAL_8N1, rxPin, txPin);
38+
apc1.begin(Serial2);
39+
#else
40+
// ...otherwise go for SoftwareSerial
41+
softwareSerial.begin(9600);
42+
apc1.begin(softwareSerial);
43+
#endif
2844

2945
if (apc1.isConnected() == false)
3046
{

src/apc1.h

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <Arduino.h>
77
#include <Stream.h>
8-
#include <SoftwareSerial.h>
98

109
#include "utils.h"
1110

0 commit comments

Comments
 (0)