PMS5003 giving out garbage values #13650
Replies: 2 comments
-
Pleas use lines with three backticks to enclose your code. The easiest way to get that is to highlight all code lines and push Ctrl-E. |
Beta Was this translation helpful? Give feedback.
-
I would start by printing out the value of Also, when you get garbage, try checking And, definitely do as @robert-hh suggests. It is not possible to be sure I understand your code correctly. Click on the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using ESP32 WROOM DEVKIT to collect data from PMS5003 sensor. The sensor does send around 9-10 valid data before sending random garbage values. can y'all please review the code and suggest any improvements or it could just be a sensor issue??
from machine import Pin, UART
import time
Configure UART for PMS5003 sensor
uart = UART(2, 9600, tx=Pin(17), rx=Pin(16))
def read_pm25():
while True:
time.sleep(3)
data = uart.read(32) ##read 32 bytes of data
if data is None:
print("False")
else:
print("True")
if len(data) == 32 and data[0]==0x42 and data[1]== 0x4d:
print("Collecting data")
data_new=data[12] << 8 | data[13]
return data_new
else:
print("Garbage data collected")
#if data[0] == 0x42 and data[1] == 0x4d:
Calculate PM2.5 concentration
time.sleep(30)
while True:
pm25 = read_pm25()
print(pm25, "ug/m3")
Beta Was this translation helpful? Give feedback.
All reactions