You are reading a single comment by @AkosLukacs and its replies. Click here to read the full conversation.
  • 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).

  • 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.

About

Avatar for AkosLukacs @AkosLukacs started