Testing the new Honeywell Particulate sensor for a project with local schools. Has advantage over some other sensors of returning a pre-calculated PM2.5 reading, has an on board fan, and only 15ug variance so perfectly good enough for doing a low/med/high/v high assessment.
Full datasheet is here.
Connected it to Arduino Uno via SoftwareSerial.
The datasheet customer use protocol has codes I'm sending to the sensor to request a reading, and I am getting a stream of readings back through the serial monitor. (code is at bottom of post). The protocol also says the format I receive back should be in format:
HEAD (0x40)
LEN (0x05)
CMD (0x04)
DF1
DF2
DF3
DF4
CS (MOD((65536-(HEAD+LEN+CMD+DATA)),256)
With the PM2.5 calculated as DF1*256 + DF2 (and PM10 using DF3 and DF4 via the same)
Data in the monitor looks like this when I run it at present;
66, 77, 0, 28, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255,
0, 0, 81, 0, 0, 255, 66, 77, 0, 28, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 81, 0, 0, 255, 66, 77, 0, 28, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255,
66, 77, 0, 28, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 81, 0, 0, 255,
There's an obvious sequence, and by wafting a candle, I know that the numbers highlighted in red and blue are DF2 and DF4 reads. I don't know which fields have the DF1 and DF3 data in. However, as you can see, the stream doesn't reliably start at the same point, and there are lots of stray zeros. Also, I can't see the HEAD/LEN/CMD in the stream, and am worried by this.
Would be grateful for help with helping me align the data I'm receiving with what I should be getting, so I can reliably extract DF1 and DF2 to put into the output I subsequently have planned.
I am new to extracting data from the serial flow like this (my // notes show my attempts to understand), so apologies that I suspect I am making some rookie serial/byte type errors. I know this sensor will pick up a library in due course, but can't find anything at present, and I can't quite work out the string listening etc. to make it work.
Thanks in advance for help.
Chris
#include "SoftwareSerial.h"
SoftwareSerial mySerial(12,13); //Using pin 12 for Rx and pin 13 for Tx
byte readpart[] = {0x68, 0x01, 0x04, 0x93}; //Listed command to read particle data
byte readstart[] = {0x68, 0x01, 0x04, 0x96}; //Listed command to start particle measurement
byte response[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //32 byte array to store returned data
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600); //Opens the main serial port to communicate with the computer
mySerial.begin(9600); //Opens the virtual serial port with a baud of 9600
delay(2000); //Wait for serial to have started
Serial.println("Sending particle start reading code"); //Update user that autosend code sent
mySerial.write(readstart,8); //Request sensor starts particle reading
delay(6000); //Allow 6 seconds for sensor response time
Serial.println("Sensor started"); //Confirm end of setup code
}
void loop()
{ sendRequest(readpart); //Send the read code request
delay(1000);
Serial.println(" "); //New line on serial monitor
for(int i = 0; i < 32; i++) //Print out the data obtained
{ Serial.print(response[i]);
Serial.print(", ");
}}
//Sub command that runs inside the main loop
void sendRequest(byte packet[])
{
while(!mySerial.available()) //keep sending request until we start to get a response
{ //mySerial.write(readpart,4); //send command for a reading
delay(50);
}
int timeout=0; //set a timeout counter
while(mySerial.available() < 32) //Hold in this loop until we get a 32 bit response
{ timeout++;
if(timeout > 10) //wait 10ms to check if we're happy, else reset and wait again
{ while(mySerial.available())
mySerial.read(); //read everything out the buffer to empty it
break; //exit and try again
}
delay(50);
}
for (int i=0; i < 32; i++)
{ response[i] = mySerial.read(); //Read data out the buffer into into the response array
}}
honeywell-sensing-particle-sensors-hpm-series-datasheet-32322550-b-en.pdf (393 KB)