Skip to content

Commit 5df16f1

Browse files
committed
chore: Refactor after on-device test
1 parent 20d6d77 commit 5df16f1

File tree

8 files changed

+46
-21
lines changed

8 files changed

+46
-21
lines changed

examples/Example0_LibrarylessCommunication/Example0_LibrarylessCommunication.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void setup()
6262
delay(250);
6363

6464
// This command (required) causes the data to be delivered to the Project on
65-
// notehub.io that has claimed this Product ID. (see above)
65+
// notehub.io that has claimed this Product ID (see above).
6666
if (myProductID[0])
6767
{
6868
txRxPinsSerial.println("{\"cmd\":\"hub.set\",\"product\":\"" myProductID "\"}");
@@ -88,7 +88,7 @@ void loop()
8888
// Count the simulated measurements that we send to the cloud, and stop the
8989
// demo before long.
9090
static unsigned eventCounter = 0;
91-
if (eventCounter++ > 25)
91+
if (++eventCounter > 25)
9292
{
9393
return;
9494
}

examples/Example1_NotecardBasics/Example1_NotecardBasics.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ void setup()
6565
#ifdef usbSerial
6666
// If you open Arduino's serial terminal window, you'll be able to watch
6767
// JSON objects being transferred to and from the Notecard for each request.
68+
usbSerial.begin(115200);
6869
const size_t usb_timeout_ms = 3000;
6970
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
7071
;
71-
usbSerial.begin(115200);
7272
notecard.setDebugOutputStream(usbSerial);
7373
#endif
7474

@@ -125,7 +125,7 @@ void loop()
125125
// Count the simulated measurements that we send to the cloud, and stop the
126126
// demo before long.
127127
static unsigned eventCounter = 0;
128-
if (eventCounter++ > 25)
128+
if (++eventCounter > 25)
129129
{
130130
return;
131131
}

examples/Example2_PeriodicCommunications/Example2_PeriodicCommunications.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ void setup()
8484
#ifdef usbSerial
8585
// If you open Arduino's serial terminal window, you'll be able to watch
8686
// JSON objects being transferred to and from the Notecard for each request.
87+
usbSerial.begin(115200);
8788
const size_t usb_timeout_ms = 3000;
8889
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
8990
;
90-
usbSerial.begin(115200);
9191
notecard.setDebugOutputStream(usbSerial);
9292
#endif
9393

@@ -171,7 +171,7 @@ void loop()
171171
// Count the simulated measurements that we send to the cloud, and stop the
172172
// demo before long.
173173
static unsigned eventCounter = 0;
174-
if (eventCounter++ > 25)
174+
if (++eventCounter > 25)
175175
{
176176
return;
177177
}

examples/Example3_InboundPolling/Example3_InboundPolling.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ void setup()
5454
#ifdef usbSerial
5555
// If you open Arduino's serial terminal window, you'll be able to watch
5656
// JSON objects being transferred to and from the Notecard for each request.
57+
usbSerial.begin(115200);
5758
const size_t usb_timeout_ms = 3000;
5859
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
5960
;
60-
usbSerial.begin(115200);
6161
notecard.setDebugOutputStream(usbSerial);
6262
#endif
6363

examples/Example4_InboundInterrupts/Example4_InboundInterrupts.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ void setup()
6767
#ifdef usbSerial
6868
// If you open Arduino's serial terminal window, you'll be able to watch
6969
// JSON objects being transferred to and from the Notecard for each request.
70+
usbSerial.begin(115200);
7071
const size_t usb_timeout_ms = 3000;
7172
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
7273
;
73-
usbSerial.begin(115200);
7474
notecard.setDebugOutputStream(usbSerial);
7575
#endif
7676

examples/Example5_UsingTemplates/Example5_UsingTemplates.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ void setup()
7272
#ifdef usbSerial
7373
// If you open Arduino's serial terminal window, you'll be able to watch
7474
// JSON objects being transferred to and from the Notecard for each request.
75+
usbSerial.begin(115200);
7576
const size_t usb_timeout_ms = 3000;
7677
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
7778
;
78-
usbSerial.begin(115200);
7979
notecard.setDebugOutputStream(usbSerial);
8080
#endif
8181

@@ -151,13 +151,13 @@ void setup()
151151
}
152152

153153
// In the Arduino main loop which is called repeatedly, add outbound data every
154-
// 5 seconds
154+
// 15 seconds
155155
void loop()
156156
{
157157
// Count the simulated measurements that we send to the cloud, and stop the
158158
// demo before long.
159159
static unsigned eventCounter = 0;
160-
if (eventCounter++ > 25)
160+
if (++eventCounter > 25)
161161
{
162162
return;
163163
}
@@ -213,5 +213,5 @@ void loop()
213213
}
214214

215215
// Delay between measurements
216-
delay(5 * 1000); // 5 seconds
216+
delay(15 * 1000); // 5 seconds
217217
}

examples/Example6_SensorTutorial/Example6_SensorTutorial.ino

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ void setup()
3434
#ifdef usbSerial
3535
// If you open Arduino's serial terminal window, you'll be able to watch
3636
// JSON objects being transferred to and from the Notecard for each request.
37+
usbSerial.begin(115200);
3738
const size_t usb_timeout_ms = 3000;
3839
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
3940
;
40-
usbSerial.begin(115200);
4141
notecard.setDebugOutputStream(usbSerial);
4242
#endif
4343

@@ -57,8 +57,18 @@ void setup()
5757
notecard.sendRequestWithRetry(req, 5); // 5 seconds
5858
}
5959

60+
// In the Arduino main loop which is called repeatedly, add outbound data every
61+
// 15 seconds
6062
void loop()
6163
{
64+
// Count the simulated measurements that we send to the cloud, and stop the
65+
// demo before long.
66+
static unsigned eventCounter = 0;
67+
if (++eventCounter > 25)
68+
{
69+
return;
70+
}
71+
6272
float temperature = sensor.temp();
6373
float humidity = sensor.humidity();
6474

examples/Example7_PowerControl/Example7_PowerControl.ino

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66
// This tutorial requires a Notecarrier-F (or equivalently-wired carrier board)
77
// designed enable the Notecard's ATTN pin to control a host MCU's power supply.
8-
//
98

109
#include <Notecard.h>
1110

@@ -20,8 +19,21 @@
2019
#define notehubUploadPeriodMins 10
2120
#define hostSleepSeconds 60
2221

23-
// Arduino serial debug monitor port definitions
24-
#define usbSerial Serial
22+
// Arduino serial debug monitor port definitions.
23+
// Note this is using the TX/RX pins for logging and not the USB connector. An
24+
// FTDI cable is required to read the logs produced by this sketch. Power is
25+
// delivered over USB, which interferes with the way the Notecard puts the
26+
// Feather MCU to sleep. As a result, USB cannot be used to capture logs.
27+
#ifdef ARDUINO_AVR_UNO
28+
#define txRxSerial Serial
29+
#elif ARDUINO_FEATHER_F405
30+
// https://github.com/stm32duino/Arduino_Core_STM32/issues/1990
31+
#define txRxSerial Serial3
32+
#elif ARDUINO_NUCLEO_L432KC
33+
#define txRxSerial Serial2
34+
#else
35+
#define txRxSerial Serial1
36+
#endif
2537

2638
// Notecard I2C port definitions
2739
Notecard notecard;
@@ -52,14 +64,14 @@ const char voltSensorSegmentID[] = "VOLT";
5264
void setup()
5365
{
5466
// Set up for debug output (if available).
55-
#ifdef usbSerial
67+
#ifdef txRxSerial
5668
// If you open Arduino's serial terminal window, you'll be able to watch
5769
// JSON objects being transferred to and from the Notecard for each request.
70+
txRxSerial.begin(115200);
5871
const size_t usb_timeout_ms = 3000;
59-
for (const size_t start_ms = millis(); !usbSerial && (millis() - start_ms) < usb_timeout_ms;)
72+
for (const size_t start_ms = millis(); !txRxSerial && (millis() - start_ms) < usb_timeout_ms;)
6073
;
61-
usbSerial.begin(115200);
62-
notecard.setDebugOutputStream(usbSerial);
74+
notecard.setDebugOutputStream(txRxSerial);
6375
#endif
6476

6577
// Initialize the physical I2C I/O channel to the Notecard
@@ -120,7 +132,10 @@ void setup()
120132
void loop()
121133
{
122134
// Bump the number of cycles
123-
globalState.cycles++;
135+
if (++globalState.cycles > 25)
136+
{
137+
return;
138+
}
124139

125140
// Simulation of a device taking a measurement of a temperature sensor.
126141
// Because we don't have an actual external hardware sensor in this example,

0 commit comments

Comments
 (0)