aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2022-02-04 12:51:07 +0000
committerdakkar <dakkar@thenautilus.net>2022-02-04 12:51:07 +0000
commita8241a11bf83c445328a5e6d5be686d339c4afe7 (patch)
tree8915fc6ece8e85a00e7c3bf0d16e4dbf2677dd80
parentshow values on eink display (diff)
downloadenv-sensor-a8241a11bf83c445328a5e6d5be686d339c4afe7.tar.gz
env-sensor-a8241a11bf83c445328a5e6d5be686d339c4afe7.tar.bz2
env-sensor-a8241a11bf83c445328a5e6d5be686d339c4afe7.zip
use SPS30 as well
-rw-r--r--README.md6
-rw-r--r--main.ino82
2 files changed, 72 insertions, 16 deletions
diff --git a/README.md b/README.md
index 2cdf469..7078be3 100644
--- a/README.md
+++ b/README.md
@@ -36,3 +36,9 @@ SCD41:
* 3 VDD white/red
* 4 SDA green
+SPS30:
+* 1 VDD black
+* 2 SDA red
+* 3 SCL white
+* 4 SEL yellow → GND
+* 5 GND orange
diff --git a/main.ino b/main.ino
index 604bdef..cb5d21a 100644
--- a/main.ino
+++ b/main.ino
@@ -1,5 +1,6 @@
#include <Arduino.h>
#include <SensirionI2CScd4x.h>
+#include <sps30.h>
#include <Wire.h>
#define LILYGO_T5_V213 // needed for the display libraries
@@ -7,7 +8,7 @@
#include <boards.h>
#include <GxEPD.h>
#include <GxGDEH0213B73/GxGDEH0213B73.h> // screen model, probably correct
-#include <Fonts/FreeMonoBold12pt7b.h>
+#include <Fonts/FreeMonoBold9pt7b.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
@@ -40,6 +41,7 @@ void setup() {
delay(100);
}
+ // the board's definition says SCL=23, but I have SCL=22
Wire.begin(21,22);
SPI.begin(EPD_SCLK, EPD_MISO, EPD_MOSI);
@@ -47,7 +49,7 @@ void setup() {
display.init();
display.setTextColor(GxEPD_BLACK);
display.setRotation(3);
- display.setFont(&FreeMonoBold12pt7b);
+ display.setFont(&FreeMonoBold9pt7b);
display.fillScreen(GxEPD_WHITE);
display.update();
@@ -84,6 +86,29 @@ void setup() {
Serial.println(errorMessage);
}
+ // this will try to re-init Wire, emit a warning, and carry on
+ sensirion_i2c_init();
+
+ while (sps30_probe() != 0) {
+ Serial.print("SPS sensor probing failed\n");
+ delay(500);
+ }
+
+ int16_t ret;
+ uint8_t auto_clean_days = 4;
+ uint32_t auto_clean;
+
+ ret = sps30_set_fan_auto_cleaning_interval_days(auto_clean_days);
+ if (ret) {
+ Serial.print("error setting the auto-clean interval: ");
+ Serial.println(ret);
+ }
+
+ ret = sps30_start_measurement();
+ if (ret < 0) {
+ Serial.print("error starting measurement\n");
+ }
+
Serial.println("Waiting for first measurement... (5 sec)");
}
@@ -99,23 +124,48 @@ void loop() {
float humidity = 0.0f;
error = scd4x.readMeasurement(co2, temperature, humidity);
+ struct sps30_measurement m;
+ char serial[SPS30_MAX_SERIAL_LEN];
+ uint16_t data_ready;
+ int16_t ret;
+
+ do {
+ ret = sps30_read_data_ready(&data_ready);
+ if (ret < 0) {
+ Serial.print("error reading data-ready flag: ");
+ Serial.println(ret);
+ } else if (!data_ready)
+ Serial.print("data not ready, no new measurement available\n");
+ else
+ break;
+ delay(100); /* retry in 100ms */
+ } while (1);
+
+ ret = sps30_read_measurement(&m);
+
+ if (error || ret <0 || co2 ==0) {
+ return;
+ }
+
display.fillScreen(GxEPD_WHITE);
display.setCursor(0,20);
- if (error) {
- display.print("read error: ");
- errorToString(error, errorMessage, 256);
- display.println(errorMessage);
- } else if (co2 == 0) {
- display.println("Invalid sample detected, skipping.");
- } else {
- display.print("Co2:");
- display.println(co2);
- display.print("Temperature:");
- display.println(temperature);
- display.print("Humidity:");
- display.println(humidity);
- }
+ display.print("Co2:");
+ display.println(co2);
+ display.print("T:");
+ display.print(temperature);
+ display.print(" H:");
+ display.println(humidity);
+
+ display.print("PM 1:");
+ display.print(m.mc_1p0);
+ display.print(" PM 2.5:");
+ display.println(m.mc_2p5);
+
+ display.print("PM 4:");
+ display.print(m.mc_4p0);
+ display.print(" PM 10:");
+ display.println(m.mc_10p0);
display.update();
}