Skip to content

Instantly share code, notes, and snippets.

@ma2shita
Last active December 24, 2019 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ma2shita/a9f8f5a76248075318ee0c1e913226b5 to your computer and use it in GitHub Desktop.
Save ma2shita/a9f8f5a76248075318ee0c1e913226b5 to your computer and use it in GitHub Desktop.
/* Measurement CO2 by S-300L-3V for Wio LTE JP Version */
/* Output >>
Ready
862
866
871
875
877
*/
#include <WioLTEforArduino.h>
WioLTE Wio;
/* by S-300L: http://doc.switch-science.com/datasheets/ELT/User+Guide+for+U-ART+command+for+Low-Power+ver160719+cdg.pdf */
uint16_t CO2ppm() {
while (!SerialUART.available()); /* wait max 3 seconds by spec (TODO: Timeout) */
String buf = SerialUART.readStringUntil('\n'); /* separete char by spec */
int pos = buf.lastIndexOf(" ppm"); /* Avoiding garbage in buffer */
String v = buf.substring(pos - 6, pos);
return v.toInt();
}
void setup() {
delay(200);
Wio.Init();
SerialUSB.begin(115200);
Wio.PowerSupplyGrove(true);
delay(500);
SerialUART.begin(38400);
SerialUSB.println("Ready");
}
void loop() {
uint16_t ppm = CO2ppm();
SerialUSB.println(ppm);
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment