lord_alan wrote:I have flashed one of these with a new build of nodeMCU and am trying to read the LDR using LUA butCode: Select allalways returns 65535print(adc.read(0))
I don't know if you went any further with this but I was playing with ADC and the LDR last night and had some strange results.
You probably already know this but the docs at http://nodemcu.readthedocs.org/en/dev/en/modules/adc/ say...
Depending on the setting in the "esp init data" (byte 107) one can either use the ADC to read an external voltage, or to read the system voltage, but not both.
I initially tried...
print(adc.read(0))
...as you did and also got a consistent 65535 but then I decided to try...
print(adc.readvdc33())
...to see what happened.
According to the docs the return value of this is...
system voltage in millivolts (number)
If the ESP8266 has been configured to use the ADC for sampling the external pin, this function will always return 65535. This is a hardware and/or SDK limitation.
...but my initial reading was something like 1738 (decimal) which didn't make much sense for system voltage.
I then tried covering the LDR with a piece of card and the next reading was 232. Similarly, if I used a torch shining directly on the LDR I got readings of just over 4000. This seemed consistent with card / torch / casting shadows with my hand - all varying the return value.
This definitely doesn't tally - if, as the docs (above) say, the ADC is configured for external sampling (which I'd assume was the case for the LDR) then it SHOULD be returning a consistent 65535 but if it's NOT configured for external sampling I'd expect a fairly consistent value relating to system volage in millivolts instead of a variable value that is clearly affected by the light on the LDR. Totally confused.
Cheers,
Brian