From 08dff8bbc18359cd7627506a9483ab82a12e7a9a Mon Sep 17 00:00:00 2001 From: Yannick van Etten Date: Wed, 13 Nov 2024 14:37:14 +0100 Subject: [PATCH] changed test code for the m5stack sensor --- src/C++/Driver/src/TestM5/TestM5.ino | 52 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/C++/Driver/src/TestM5/TestM5.ino b/src/C++/Driver/src/TestM5/TestM5.ino index 32dee8a..7c99993 100644 --- a/src/C++/Driver/src/TestM5/TestM5.ino +++ b/src/C++/Driver/src/TestM5/TestM5.ino @@ -1,31 +1,39 @@ -#include -#include -#include "Adafruit_SGP30.h" +#include +#include "Adafruit_SGP30.h" Adafruit_SGP30 sgp; -void setup() { - M5.begin(); - Serial.begin(9600); +#define SDA_PIN 10 +#define SCL_PIN 11 - - if (!sgp.begin()) { - Serial.println("SGP30 sensor niet gevonden :("); - while (1); - } - Serial.println("SGP30 sensor gevonden!"); +void setup() { + Serial.begin(115200); + while (!Serial) { delay(10); } + + Wire.begin(SDA_PIN, SCL_PIN); + + Serial.println("SGP30 test"); + + if (!sgp.begin()) { + Serial.println("SGP30 sensor not found :("); + while (1); + } + Serial.print("Found SGP30 serial #"); + + // Start measurements (initialize baseline) + if (! sgp.IAQinit()) { + Serial.println("SGP30 IAQinit failed!"); + while (1); + } } void loop() { - delay(1000); + if (! sgp.IAQmeasure()) { + Serial.println("Measurement failed"); + return; + } + Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t"); + Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm"); - if (!sgp.IAQmeasure()) { - Serial.println("Error bij meting!"); - return; - } - Serial.print("eCO2: "); - Serial.print(sgp.eCO2); - Serial.print(" ppm\tTVOC: "); - Serial.print(sgp.TVOC); - Serial.println(" ppb"); + delay(1000); // 1 second delay } \ No newline at end of file