Go Down

Topic: Extracting PM2.5 data from new Honeywell HPM Particle Sensor via serial UART (Read 1 time) previous topic - next topic

ralphvn86

Thanks - will try and get hold of one from family. I've continued tinkering in the meantime, and radically simplified my code (see bottom) to start always reading at the 66..77.. point, as this consistently comes up in the code. Tried with second sensor not exposed to 5v Rx/Tx and getting exactly same output, and also set up smoke chamber to get particles high enough to trip past the 256 figure.

Output is pasted below. My working hypothesis is PM2.5 = (line 105*256) + line 106, as this aligns with the experiments I'm doing. PM10 would be 107*256 and 108

Having been looking at other sketches pinging these kind of sensors, there seems to be some interesting mixing between uint8_t and uint16_t in the libraries.

Am I missing something silly here around how I'm reading the data into the array? Tried changing the 8_t to 16_t, but that breaks the readbytes function.

100:  77
101:  0
102:  28
103:  0
104:  0
105:  1
106:  192
107:  1
108:  199
109:  0
110:  0
111:  0
112:  0
113:  0
114:  0
115:  0
116:  0
117:  0
118:  0
119:  0
120:  0
121:  0
122:  0
123:  0
124:  0
125:  0
126:  0
127:  81
128:  0
129:  2
130:  133
131:  66 (the first reading, but confirming I've closed the loop)

Wondering if chunking anything into 16 not 8 would get it to look like more like the datasheet, as at the moment, I feel I'm getting a reliable output, but that it doesn't resemble the datasheet one bit (or byte).

Thanks

Code: [Select]
#include "SoftwareSerial.h"
SoftwareSerial mySerial(12,13);  //Using pin 12 for Rx and pin 13 for Tx
byte autosend[] = {0x68, 0x01, 0x40, 0x57};
 
#define LENG 32   
uint8_t buf[LENG];
int PM2_5Value=0;         //define PM2.5 value

void setup()
{ Serial.begin(9600);       
  mySerial.begin(9600);   
  mySerial.setTimeout(6000);
  delay(2000);
  mySerial.write(autosend,4); 
}

void loop()
{ Serial.println(" ");
 // mySerial.write(readpart,4);
  if(mySerial.find(66)){   
  if(buf[1] = 77){mySerial.readBytes(buf,LENG);
  PM2_5Value=((buf[5]*256) + buf[6]);}
} delay(2000);

  Serial.print("PM2.5 = ");
  Serial.println(PM2_5Value);
for(int i = 0; i < 32; i++)
{ Serial.print(i+100);
  Serial.print(":  ");
  Serial.println(buf[i],DEC);
}}

 

Your code looks okay, 66 is the first byte followed by 77 for the header, 101 and 102 is the MSB and LSB for the length (always 28 at the moment).

You have to take the sum off al the bytes, header + length + 26 data bytes what should correspond with byte 129 (MSB) and 130 (LSB) as an uint16_t.

jonselfphoto

Has anyone gotten this working yet? I'm having trouble with mine as well. The datasheet on Honeywell's website says it will work with either 5V or 3.3V, I'm not sure why people are saying this isn't the case...

john_m0ers

The way I read the datasheet, it has its own on board regulator with 5v being the input. It also quite clearly states that the uart levels are 3.3v. If 5v is applied here I would imagine it would destroy the pin driver.
john

Go Up