2

I get the following error message from nodeMCU on esp8266 : attempt to call field "adc.force_init_mode" (a nil value). Can somebody point out the mistake please?

if adc.force_init_mode(adc.INIT_ADC) 
  then
    node.restart()
  return
end
val = adc.read(0)
print("Input number:", val )
val2 = 5000000 - (val*5000000/1023)
print("R (ohm):", val2 )
hoody
  • 43
  • 4

1 Answers1

2

Your firmware does either not have the ADC module compiled in or it's got an ADC module without the force_init_mode function.

Therefore, build a recent firmware and flash it to upgrade your current firmware.

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
  • wouldn't you get an error for indexing adc then? adc obviously is a table in his version. Maybe some old version of the adc module that does not implement force_init_mode? Fix is the same of course. – Piglet Sep 10 '16 at 17:54
  • Yes, but I doubt the error message in the description above is 100% accurate. `http.foo()` yields "attempt to call field 'foo'..." while `bar.foo()` yields "attempt to index global 'bar'". Note that in the OP's question it says "...field 'adc.force_init_mode'" (extra 'adc.'). I'll update the answer anyway. – Marcel Stör Sep 10 '16 at 18:37
  • oh totally missed that :) – Piglet Sep 10 '16 at 18:57
  • Thank you! I have problem in uploading built firmware...I'm working on that! – hoody Sep 17 '16 at 08:07