So I’ve been doing some experimenting and I’ll put it here for anyone looking to convert a voltage signal into SmartThings. The ESP32 is very inaccurate at the top and bottom of the scale and not great in between. For example my humidity sensor was putting out 0 - 3.3v and we had rain today. So the sensor was reading around 96% and the ESP saw 3.23 volts but was reading 4095 (100%). Same issue on the low range, 0 - 5% humidity didn’t register (not that we’d ever see that low). I’m also having the same issue with my temperature. For example:
Actual temperature reading: 64.4*
Actual voltage output: 1.922 v
Temperature reading from ESP32: 54.3*
The scaling is -40 to 140 for the 0 - 3.3v input. So at 64.3* the voltage should be, based on the slope, about 1.912 and I’m at 1.922. I’ll call that close enough. Yet I’m getting a reading of 54.3* which is way more then a 0.01v difference.
After some searching I found some articles that showed the ESP32’s ADC wasn’t very good at the extremes of either end (https://www.esp32.com/viewtopic.php?t=1045). So based on that I changed the voltage output on both sensors to 0.52v - 2.85v and the ADC inputs to 512-3584. Once I made this change I got the following results:
Actual temperature: 63.7* (1.882v) - ESP temperature: 54.7
Actual humidity: 97.8% (2.815v) - ESP humidity: 95.8%
The voltage measurements * slope plus offset are within 1% so the issue appears to be with the ESP32 ADC’s. So I figured each ESP might be different. I reset the mapping and pushed a even .250v signal to each input and got the following:
Temperature input: 129
Humidity input: 128
Well they are almost the same…thats promising. I then pushed a 3.0v signal to each:
Temperature input: 3889
Humidity input: 3863
Not as promising but ok. As I watch it however my voltage didn’t change but the inputs jumped around from 3860 - 3900. So I backed it down to 2.9v:
Temperature input: 3667
Humidity input: 3671
and they weren’t bouncing as much. So based on that I setup my scaling for temperature as 128 - 3670 = -40 - 140* and for humidity 128 - 3670 = 0 - 100% and got this:
Actual temperature: 63.7* - ESP temperature: 56.1*
Actual humidity: 97.8% - ESP humidity: 96.1%
Double checking the voltage I have 1.80 which based on that slope (0.25v - 2.9v = -40 - 140*) I should have 1.78v, a degree or so off but not 8* which leads me to believe the ESP32 is not very linear at all and wont work for my current project. Hopefully there will be firmware updates to fix this but for now I wouldn’t recommend it for highly accurate analog inputs.
It is working just fine for binary inputs. Haven’t tried the outputs…don’t really have anything I need to but I might just for testing. Also will try a smaller range and see if thats more accurate along with checking about firmware updates.
-Allan