Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created January 29, 2024 12:47
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 maxpromer/25483bc3f3b1942fa0892c970cce6447 to your computer and use it in GitHub Desktop.
Save maxpromer/25483bc3f3b1942fa0892c970cce6447 to your computer and use it in GitHub Desktop.
ATD3.5-S3 x PMS7003
#include <Arduino.h>
#include <lvgl.h>
#include <ATD3.5-S3.h>
#include "gui/ui.h"
#include <PMS.h>
PMS pms(Serial2);
PMS::DATA data;
bool pms_ok = false;
void pm_update() {
if (pms_ok) {
lv_label_set_text_fmt(ui_pm25_value, "%d", data.PM_AE_UG_2_5);
lv_label_set_text_fmt(ui_pm10_value, "%d", data.PM_AE_UG_1_0);
lv_label_set_text_fmt(ui_pm100_value, "%d", data.PM_AE_UG_10_0);
} else {
lv_label_set_text(ui_pm25_value, "");
lv_label_set_text(ui_pm10_value, "");
lv_label_set_text(ui_pm100_value, "");
}
}
void setup() {
Serial.begin(115200);
// Setup peripherals
Display.begin(0); // rotation number 0
Touch.begin();
Sound.begin();
Serial2.begin(9600, SERIAL_8N1, 1); // RX = IO1
// Map peripheral to LVGL
Display.useLVGL(); // Map display to LVGL
Touch.useLVGL(); // Map touch screen to LVGL
Sound.useLVGL(); // Map speaker to LVGL
// Add load your UI function
ui_init();
// Add sensor read and update to UI
pm_update();
}
void loop() {
Display.loop();
{ // PMS7003
static unsigned long last_work = 0;
if (pms.read(data)) {
pms_ok = true;
pm_update();
last_work = millis();
} else {
if ((millis() - last_work) > 2000) {
pms_ok = false;
pm_update();
}
}
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment