Hypfer / esp8266-vindriktning-particle-sensor

Wifi MQTT Data Logging via an esp8266 for the Ikea VINDRIKTNING PM2.5 air quality sensor
Apache License 2.0
1.18k stars 128 forks source link

Seeing odd values on sensor UART #59

Open kieran opened 2 years ago

kieran commented 2 years ago

I'm getting really bizarre readings from the UART...

I've tried 2 different ESP8266s (d1 mini clones) and an ESP32 (a mini32) and see the same behaviour on each. The IKEA unit appears to work normally, and the LEDs on it light up as you would expect in different atmospheres.

Have also de/re-soldered the wires a few times, powered the ESP via either 5V pin or USB. Same deal each time.

Code modifications (for logging):

bool isValidHeader() {
  Serial.printf("Expected header: %02X %02X %02X\n", 0x16, 0x11, 0x0B);
  Serial.printf("Received header: %02X %02X %02X\n", serialRxBuf[0], serialRxBuf[1], serialRxBuf[2]);
  bool headerValid = serialRxBuf[0] == 0x16 && serialRxBuf[1] == 0x11 && serialRxBuf[2] == 0x0B;
  // ...
void handleUart(particleSensorState_t& state) {
  // ...
  Serial.print("Receiving: ");
  while (sensorSerial.available()) {
    serialRxBuf[rxBufIdx] = sensorSerial.read();
    Serial.printf("%02X ", serialRxBuf[rxBufIdx]);
    rxBufIdx++;
  // ...

Serial output

Receiving: F7 Done.
Expected header: 16 11 0B
Received header: F7 00 00
Received message with invalid header.

Receiving: FF Done.
Expected header: 16 11 0B
Received header: FF 00 00
Received message with invalid header.

Receiving: 7F FB Done.
Expected header: 16 11 0B
Received header: 7F FB 00
Received message with invalid header.

Receiving: EB FF FF Done.
Expected header: 16 11 0B
Received header: EB FF FF
Received message with invalid header.

Receiving: F7 FF FF Done.
Expected header: 16 11 0B
Received header: F7 FF FF
Received message with invalid header. 

I'm somewhat new to C++ / Arduino, would appreciate any tips re: where to look next!