Hi, i’m currently working with the Laser PM2.5 Sensor (HM3301), i use an ESP32-C3 with the Shield Grove XIAO 103020312 (where my sensor is connected). I used the PlatformIO library manager in order to make it work and measure the concentration content and also followed this : GitHub - Seeed-Studio/Seeed_PM2_5_sensor_HM3301.
Everything seems to work when i upload, no problem but when i press monitor in order to get my measurements, i don’t receive any datas in my terminal. Which was not a problem with the asair AM2302 (temperature and humidity sensor), everything worked perfectly.
This is my platformio.ini file :
[env:seeed_xiao_esp32c3]
platform = espressif32
board = seeed_xiao_esp32c3
framework = arduino
monitor_port = COM5
monitor_speed = 115200
lib_deps =
seeed-studio/Grove - Laser PM2.5 Sensor HM3301 @ ^1.0.3
This is my main.cpp :
#include <Seeed_HM330X.h>
#include <Wire.h>
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL_OUTPUT SerialUSB
#else
#define SERIAL_OUTPUT Serial
#endif
HM330X sensor;
uint8_t buf[30];
const char str[] = {"sensor num: ", "PM1.0 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
"PM2.5 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
"PM10 concentration(CF=1,Standard particulate matter,unit:ug/m3): ",
"PM1.0 concentration(Atmospheric environment,unit:ug/m3): ",
"PM2.5 concentration(Atmospheric environment,unit:ug/m3): ",
"PM10 concentration(Atmospheric environment,unit:ug/m3): ",
};
HM330XErrorCode print_result(const charstr, uint16_t value) {
if (NULL == str) {
return ERROR_PARAM;
}
Serial.print(str);
Serial.println(value);
return NO_ERROR;
}
/parse buf with 29 uint8_t-data/
HM330XErrorCode parse_result(uint8_t data) {
uint16_t value = 0;
if (NULL == data)
return ERROR_PARAM;
for (int i = 1; i < 8; i++) {
value = (uint16_t) data[i 2] << 8 | data[i * 2 + 1];
print_result(str[i - 1], value);
}
return NO_ERROR;
}
HM330XErrorCode parse_result_value(uint8_t *data) {
if (NULL == data) {
return ERROR_PARAM;
}
for (int i = 0; i < 28; i++) {
Serial.print(data[i], HEX);
Serial.print(" ");
if ((0 == (i) % 5) || (0 == i)) {
Serial.println("");
}
}
uint8_t sum = 0;
for (int i = 0; i < 28; i++) {
sum += data[i];
}
if (sum != data[28]) {
Serial.println("wrong checkSum");
}
Serial.println("");
return NO_ERROR;
}
/30s/
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("Serial start");
if (sensor.init()) {
Serial.println("HM330X init failed");
while (1);
}
}
void loop() {
if (sensor.read_sensor_value(buf, 29)) {
Serial.println("HM330X read result failed");
}
parse_result_value(buf);
parse_result(buf);
Serial.println("");
delay(5000);
}
And this is what shows up in the terminal when i click on monitor :
--- Terminal on COM5 | 115200 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable,
send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
I didn’t change anything except adding some lines in the platformio.ini
Thank you in advance !