0

I want to read sensor values from 4x AM2302 to an Arduino UNO, and then pass those values for data logging to Raspberry Pi via Serial communication over USB cable. The sensors are installed at 4x locations in an indoor plant growing system at difficult to access locations. In the same script is a program that runs HVAC fans and a water pump using timers and relays. The problem I encounter is that after working for several readings, eventually the AM2302 fails to read and continuously sends NaN value. If I intervene and power down/repower up, and also reupload the script, then the AM2302 begin reading again, but only for a few readings then fail again.

In the sample read-out table below, the 4x AM2302 sensor read-outs are sensor 1 : (HA01 - humidity, TA01 - temp) sensor 2 : (HA02, TA02) etc.. There is another read-out CT01 which is a DS18B20, which also fails after some-time and reports a value "no more address" which is reported as -127C by the Dallas Library.

I setup a breadboard and ran the same script with 2x AM2302 and no DS18B20 attached and was unable to replicate the problem.

I have chosen to use json string as a way to pass the readings from Arduino to Raspberry Pi, and notice that sometimes the string gets corrupted - in particular the date timestamp.

I would appreciate any help / tips on diagnostics ideas to pinpoint the issue.

Code for Arduino and Raspberry Pi is available on GitHub. https://github.com/footprintzero/plantlab

enter image description here

Updated info 2019/05/21 18:42 I re-ran the program with a modified script and so far the sensors are continuously sending a reading (AM2302).This modified script version has the HVAC control timers with the relays commented out in HVAC.ino at line 97. So its only reading the sensors and not controlling the relays.

// timer_mainloop();
  • I guess that HVAC.ino is the sketch you are talking about. Without having read all the code (since it is a lot of code): You very often use the String class to construct the json data string. This will cause heap fragmentation and may be the reason for your problem (Though I'm not sure). You should avoid using String, especially in a project, that should run for a long time continuesly. Use char buffers with a constant length instead. – chrisl May 21 at 10:26
  • Thanks for having a look! The String class is one of the suspicions I have. – Taylor Hickem May 21 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.