-
Notifications
You must be signed in to change notification settings - Fork 13.3k
ADC Values Inaccurate and different from NodeMCU #2672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you try adding the following line somewhere before your
|
I added it and it didn't result in any noticeable change. Measuring the pin at 1.03 still results in around 1002 in Arduino and 1024 in nodemcu (what I would expect if the range is 0-1v) Let me know if there is anything else I should look at. |
How are you doing to measure in Arduino side? In NodeMCU: int val = analogRead(A0); In Arduino: int val = analogRead(A0); |
lrmoreno007, The repro process is pretty basic Now flash with Nodemcu Lua and read the ADC = you get 1024 as expected Not a huge difference in this example but doing the same test at other levels shows larger discrepancies between the analog reads. Whatever Nodemcu Lua does seems to provide more accurate numbers Not exactly relevant but if you use a real arduino board with the same code (and use the Aref pin and connect to the 3.3v rail) and run the same code you also get 1024 as expected. So it doesn't seem to be the hardware or a problem inherent in the Arduino core itself - but something in the ESP Arduino port. |
Also interesting that Issue #338 while not focused on this component noted the same thing in the initial report - that person was getting 909 in the arduino port and 1024 in nodemcu. The issue focused more on why the grounded value was wrong but it seems they were also seeing the general discrepency. |
OK, I understood that you were measuring with a Arduino Hardware. I didn't read you was using NodeMcu Lua firmware. #338 are solved. |
Can you do the following? And tell us the result.
|
32.71 <--- Must be 33 |
In Vcc reading mode everything seems fine and the applied voltage is adequate. Sorry to disagree with Igrr but the line before setup should not be? ... Or ADC_MODE(ADC_TOUT_3V3); Or ADC_MODE(33); From Esp.h: #define ADC_MODE(mode) int __get_adc_mode(void) { return (int) (mode); }' |
So I tried both ADC_MODE(33) and ADC_MODE(255) So is this something with only my boards - since it such an easy test does the max value on the pin result in 1024 as expected for everyone else? |
Sorry but so far I have not had any NodeMCU free. I have tested with NodeMCU firmware and Arduino firmware and both give me the same result, with 3.3v in A0. NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
Arduino with last git version: Result: |
Well your Lua code agrees with mine but when I run that same arduino code (with a direct jumper between A0 and 3.3v) and I get I have tried 4 different nodemcu boards so far, all similar. |
Followed the GIT instructions to load the latest and still get 1001.00. |
Reproduced on another system - using ESParduino 2.3.0 the top value is 1002 or so, replaced the contents of the 2.3.0 folder with the latest from this repo and recompiled and the top is now 1024 so one problem is fixed. The midpoint value is still off Arduino and LUA both read the exact midpoint (validated with meter on the pin as .501v) as 530 instead of 512. If I take a real arduino add to the same circuit (using nodemcu board power rails) and use the 3.3v off nodemuc as external VREF on the real arduino it measures the same point as 510 (which would be basically correct as 1024/2 = 512) So better but still oddly off ...since its present in both LUA and ESPArduino probably something in the underyling SDK, so I guess this can be closed |
maximum voltage is 1.06 not 1.01 about this PS |
jourjine - I read through that article but I don't think it explains what I am seeing on my modules. The original problem was that the ESPArduino Analog read seemed to top out at around 1000 even when the same circuit in LUA measured 1024. According to the datasheet the range is 0-1v so it should have been 1023/1024 like LUA. This issues is resolved by using the GIT version of the ESP arduino code and now I have a top of 1024. From measurement it seems though that this top is reached now at around .97 volts - so it has gone too far the other way. What I did was use a pot to adjust voltage on the pin for every .1 v from 0-1v. After a bit of math dividing the ADC value by 1055 seems to correct it to reflect reality in volts. So if my ADC reads 800 that translates to .76 volts. If it reads 1023 that translates to .97 volts. This seems to give me nice results that work across the 3 boards i have. If yours is working - be careful about compiling or changing your code - you could find the behavior changes more than you would expect. |
Hi I can confirm that this problem exists with the 1.5.3 SDK and is gone with the GIT version of Arduino with SDK 1.54! |
I too am having issues with inaccurate ADC values on my ESP board and Arduino. Looking in the board manager in the Arduino IDE it seems I also have version 2.3.0. So I updated to the 2.4.0-rc2 and while 3.3V on the ADC (pin A0) now reads the full 1024, when I put the Vout from a 100K/100K voltage divider (that reads exactly 1.65 on my multimeter) I'm only reading 485 on A0 rather than the 512 it should be. |
I would open a new issue (this one is closed), if you can get better results using NodeMCU Lua firmware that might help get attention |
@lawrence-jeff Much thanks. I already did. #4009. :-)
That would be interesting for sure. But this is all pretty new to me. I jumped immediately to using Arduino with it. Any docs/guides/advise you can give about how I would test this with NodeMDU Lua firmware now? |
Hardware: Multiple NodeMCU boards (Amico and Lolin) (with ESP-12 AIThinker module)
Core Version: 2.3.0
Description
The ADC Results via analogread (TOUT) don't seem to be correct, not wildly inaccurate but enough to throw some sensors.
Without changes to the setup they are also different than what is reported by the nodemcu lua firmware (which seems more accurate)
Even simple tests show it
Compare
Measured/Calculated values on Tout pin (factoring in voltage divider in nodemcu boards) and measured by a decent meter
1.02v (Pin fed via 3.32 source) - Nodemcu reads 1024 Arduino 1002
.502v - Nodemcu reads 530, Arduino 485
0 v - Both read 1
I can replace devices and reflash and reboot and the measurements are consistent. I never see the Arduino go to 1024 even when it has over 1 volt on the pin which seems very odd. Nodemcu firmware reports the correct value of 1024 consistently
Any ideas?
Example connect A0 on nodemcu to 3.3 volt pin then run both:
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
float reading;
reading = analogRead(A0);
Serial.print("Analog reading ");
Serial.println(reading);
}
in lua
print(adc.read(0))
The text was updated successfully, but these errors were encountered: