lewapek / sds-dust-sensors-arduino-library

Library for Nova Fitness SDS dust sensors family (SDS011, SDS021)
MIT License
64 stars 19 forks source link

Issue when waking up #6

Closed mvrueden closed 6 years ago

mvrueden commented 6 years ago

Hello @lewapek, thank you very much for your library.

I tried to use it, but run into a weird issue. If using the continous mode without sleeping everything works fine. But as soon as I put the sensor into sleep mode and wake it up I get weird responses, leading the sds-dust-sensors-arduino-library to return an InvalidHead response.

For debugging purposes I implemented my own "library" to investigate further. Putting my sensor to sleep works. Waking it up returns seemingly random 5 bytes, for example, when waking the sensor up after a 30 seconds sleep, this is what the sensor responds:

0: ad
0: 50
0: 10
0: 5e
0: dd

The 0: is indicating the index. As the AA is missing, no new message is identified and thus the index is 0 all the time.

From this point on all communication works as specified, e.g. sending another wake up, returns the following bytes

0: aa
1: c5
2: 6
3: 1
4: 1
5: 0
6: ec
7: e1
8: d5
9: ab
=> Message received: AA C5 6 1 1 0 EC E1 D5 AB 

Did you observe a similar behaviour or do you have any idea what might be wrong with my sensor?

lewapek commented 6 years ago

Hi, I've checked this problem and it seems that 'continuous mode' and 'wakeup' don't work as expected. Did you encounter similar problem when using query reporting mode? I will investigate it more deeply later.

mvrueden commented 6 years ago

My findings are related to query reporting mode, as it is easier to debug. I never tested continous mode. If you want, I can provide you with my debugging code (for Arduino Nano, though) and how I set up the sensor.

What I did: setup()

loop()

Everything is returning a valid message. Only waking up sends 5 random wrong bytes. Sending it twice though, will generate at least 1 valid response message.

lewapek commented 6 years ago

Thanks for your response! I've implemented double wakeup (#7) to avoid such issue. It seems that wakeup works ok - sensor fan starts working but sensor sends random bytes or doesn't send anything at all... You can use wakeup when you want to read and check response or wakeupSingle which may result in incorrect response (however seems to awake sensor).

7 also handles automatic retries

lewapek commented 6 years ago

@mvrueden You can now try 1.3.0 release https://github.com/lewapek/sds-dust-sensors-arduino-library/releases/tag/1.3.0