I am trying to read temperature and light levels using a TMP36 and TDR connected to pins 5 & 7 on an IMP. I have been getting inconsistent results (light and temperature readings significantly too high) under certain conditions and have been unable to resolve the issue.
The device is fairly complex including a (dynamic) high level rules engine interpreting rules stored in a 2 dimensional array, and based on ON/OFF times, ALARM times, Light and Temperature levels controlling 8 Solid State Relay outputs connected to fans, lights, chargers etc.
In the course of my research I came across a similar problem on the Spark Core ( see discussion at https://community.sparkdevices.com/t/odd-analog-readings/906 ) with the general conclusion pointing towards very short but significant variations (ripples) in the 3.3V supply (as a reference) due to the fluctuating current draw during WiFi transmission.
The voltages are measured using a sampler configured at 3kHz for 2 channels and supplied with 3 x 6kByte buffers. The 1500 samples/channel returned in a buffer is averaged and used to calculate the voltage (using hardware.voltage()) as reference.
On a hunch I added server.disconnect() & imp.sleep(0.020) statement immediately before starting the sampler and a server.connect immediately after stopping the sampler. The results were immediate and consistent.
The temperature reading immediately dropped from 40C to 34C and the light readings from 80% to 72%, and remained there consistently over a 2 hour period. The 34C, although still fairly high for a summers day in sunny South Africa, is a lot closer to the reality which should be about 30C
Any chance that the theory is correct since practically it has been proved?