A0 is undefined

Posted on
  • I have an NODEMCU and installed the chrome extension for espruino - but when I try and run this code:

    setInterval(function() {
      console.log(analogRead(A0));
    }, 100);
    

    I get this:

    in function called from system
    23
    Uncaught ReferenceError: "A0" is not defined
     at line 1 col 24
    console.log(analogRead(A0));
    

    What's going on?

  • I also get the same problem (adc is undefined) with this code:

    print(adc.read(0))
    
  • Try analogRead(D0), but I'm not sure anyone has tested the ADC functionality. The docs don't match reality, we need help from Gordon to define the A0 pin for the esp8266...

  • Ah, that did it, thank you.

  • @tve is there actually a separate A0 pin, or is it the same as D0? I wouldn't duplicate pin names - that'd just get confusing.

  • Agreed. If you could add an appropriate definition to the board file that defines an A0 pin, I would appreciate. I tried and failed.

  • any update on this? I'm getting A0 undefined (v 1.87)

    thx
    David

  • @davem - not as far as I know - use analogRead() works fine for me

  • I think analogRead() ignores the argument you pass to it on the ESP8266... there's only one pin for which analogRead() is meaningful.

  • 1v87.223 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 4MB:512/512, manuf 0xe0 chip 0x4016
    

    NodeMCU v3 + Espruino
    analogRead();
    Do not working.


    1 Attachment

    • 20160928_173010_resized.jpg
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

A0 is undefined

Posted by Avatar for user59035 @user59035

Actions