ESP32 GPIO ADC Channel Error

Posted on
  • I've been running into some issues since moving away from working in the Arduino IDE/PlatformIO to developing in Espruino for the ESP32.

    The goal is to read 16 GPIO pins [GPIO's 0, 2, 4, 12, 13, 14, 15, 25, 26, 27, 32, 33, 34, 35, 36, 39] all of which can be read using the ESP32 libraries in either Arduino or PlatformIO but I receive the following ADC Channel Err if I try doing the same in Espruino IDE. I attached a js file of the code I used to test this out.

    Please let me know if you have either had the same issue and/or have resolved this already. If you've resolved it, please let me know how you did it (I might be missing something critical here).


    2 Attachments

  • Thr 2019.07.18

    Hello @ukaton and welcome to the world of Espruino! Over time, I believe you will find the shortened debug times with Espruino will far surpass that of Arduino development. Thank you for posting your code.

    I'm not an ESP32 wiz, but the code appears to be attempting to read using an analog read on every pin.

    Is it possible that the pins attempted to be read should be using digitalRead() ?

    Heading DESCRIPTION 'However only pins connected to an ADC will work (see the datasheet)'
    http://www.espruino.com/Reference#l__glo­bal_analogRead

    http://www.espruino.com/Reference#l__glo­bal_digitalRead
    http://www.espruino.com/Reference#l__glo­bal_getPinMode

    It should be possible to determine either using the source:

    https://github.com/espruino/Espruino/blo­b/master/boards/ESP32.py

    See note on line L135   unknown if that is significant



    Curiosity got the better of me, what is the GPIO config for ESP32?

    https://randomnerdtutorials.com/esp32-pi­nout-reference-gpios/

    This link may be needed also

    http://www.espruino.com/Software+PWM

  • I guess it's multiple things:
    The page Robin linked says you can't use ADC2 when Wifi is active, and Wifi is active on Espruino & ESP32 by default.
    Also, I don't think you should set the pins to output.

    This code works for me (ok, just pulled the pins to 3v3 with a resistor, but results were around 0.999, when pulled to 3v3, so seems to be ok).

    var pins = [D36,D37,D38,D39,D32,D33,D34,D35]
    function readSensors(pins) {  
      pins.forEach(function(pin) {
        console.log(pin, ' -> ', analogRead(pin));
      });
    }
    
    readSensors(pins)
    

    Prints something like this (D34 is pulled to 3v3, the rest is just floating):

    D36  ->  0.576171875
    D37  ->  0
    D38  ->  0
    D39  ->  0
    D32  ->  0.10400390625
    D33  ->  0.15966796875
    D34  ->  0.99975585937
    D35  ->  0.52758789062
    

    Just multiply the results with 3.3 to get the voltage in volts, if you don't have any voltage divider.

  • Thanks for the help! (I work with @ukaton) You've been very helpful!

    We were able to access the motion sensor and some of the pressure sensors and make a simple demo we posted over on Twitter:

    https://twitter.com/ConcreteSciFi/status­/1152324107427442688

    However, due to the lack of support for the ESP32 atm, we think it's best to switch to another platform. We'd like to use a lot more features on the ESP32, and we'll definitely switch back to Espruino in the future when appropriate. We love what your platform stands for.

  • I would be interesting to hear why you switched from Arduino/PlatformIO to Espruino.

    I'd say you could integrate the ESP32 in your PCB design.

  • Nice & thanks for getting back!
    There is ESP32.enableWifi(false) to disable Wifi. But still didn't got a proper ADC value :(
    If you are willing to dig deeper into the datasheet, I think you can use peek 8/16/32 poke 8/16/32 to directly read and write memory addresses / registers. So theoretically you can initialize the other ADC without recompiling the firmware.
    If you have time, you can contribute to improve Espruino's ESP32 support (it's 100% community driven).

    (edit: after some digging into the Espressif's SDK & ADC2 issues, the ESP32 feels like a dual core trainwreck...)

  • check this for getting better analog read quality
    http://forum.espruino.com/comments/14366­198/

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ESP32 GPIO ADC Channel Error

Posted by Avatar for ukaton @ukaton

Actions