1
+ /* **************************************************
2
+ *
3
+ * Example Code for running ScioSense APC1 on UART
4
+ * tested with Arduino UNO and ESP32
5
+ *
6
+ * **************************************************
7
+ */
8
+
1
9
#include < Arduino.h>
2
- #include < SoftwareSerial.h>
3
10
4
11
#include < apc1.h>
5
12
@@ -10,6 +17,12 @@ using namespace ScioSense;
10
17
11
18
APC1 apc1;
12
19
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
+
13
26
void setup ()
14
27
{
15
28
Serial.begin (9600 );
@@ -18,13 +31,16 @@ void setup()
18
31
// Enable Debug if needed
19
32
// apc1.enableDebugging(Serial);
20
33
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
28
44
29
45
if (apc1.isConnected () == false )
30
46
{
0 commit comments