Hello, I am using the dust sensor pms5003, I ran it first with a particle photon and everything was fine, it sent me correct data but later I connected it to the Boron particle and it no longer sent me any value, the connection I made in both particles is the same, yes someone could help me I would appreciate it, this is the code I am using:
long pm10 = 0;
long pm25 = 0;
long pm100 = 0;
long filter = 0;
uint8_t wake[] = { 0x42, 0x4D, 0xE4, 0x00, 0x01, 0x01, 0x74 };
uint8_t sleep1[] = { 0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73 };
//uint8_t sleep[] = { 0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73 };
void setup() {
Serial.begin(9600);
Serial1.begin(115200);
}
void loop() {
// digitalWrite(SLEEPLED, HIGH);
delay(10000);
Serial1.write(wake, sizeof(wake));
Serial.print("Awake");
delay(20000);
int index = 0;
char value;
char previousValue;
while (Serial1.available()) {
value = Serial1.read();
if ((index == 0 && value != 0x42) || (index == 1 && value != 0x4d)){
Serial.println("Cannot find the data header.");
break;
}
if (index == 4 || index == 6 || index == 8 || index == 10 || index == 12 || index == 14) {
previousValue = value;
}
else if (index == 5){
pm10 = 256 * previousValue + value;
Serial.print("{ ");
Serial.print("\"pm10\": ");
Serial.print(pm10);// return pm10;
Serial.print(", ");
}
else if (index == 7){
pm25 = 256 * previousValue + value;
Serial.print("\"pm25\": ");
Serial.print(pm25);//return pm25
Serial.print(", ");
}
else if (index == 9){
pm100 = 256 * previousValue + value;
Serial.print("\"pm100\": ");
Serial.print(pm100);
} else if (index > 15) {
break;
}
index++;
}
while(Serial1.available()) Serial1.read();
Serial.println(" }");
// Publish data
Particle.publish("pm25", String(pm25) + " ug/m3");
delay(2000);
Particle.publish("pm1", String(pm10) + " ug/m3");
delay(2000);
Particle.publish("pm10", String(pm100) + " ug/m3");
delay(2000);
delay(2000);
if (pm25 > 15 && filter == 0) {
filter = 1;
Particle.publish("filter", String(filter));}
if (pm25 < 10 && filter == 1) {
filter = 0;
Particle.publish("filter", String(filter));
}
uint8_t sleep[] = { 0x42, 0x4D, 0xE4, 0x00, 0x00, 0x01, 0x73 };
Serial1.write(sleep, sizeof(sleep));
delay(3000);
// digitalWrite(SLEEPLED, LOW);
Serial.print("Asleep");
delay(12000);
}