analogRead on M5Atom



  • Hello, I'm trying to make analog readings on pin "G33" and "G23".

    • When I do analogRead(33), I get the same values whatever I send the signal on G33 or G23
    • When I do analogRead(23), I receive no signal on G33 and G23

    What am I missing?

    #if !defined(ARDUINO_M5Stick_C)
    #error Wrong target platform (M5StickC - M5Atom)
    #endif

    #include "M5Atom.h"
    #include "pixelTypes.h"

    uint8_t pinNorth = 33;
    //uint8_t pinSouth = 19;

    void setup()
    {
    M5.begin(false, false, true);
    Serial.begin(115200);
    }

    void loop()
    {
    int readValue;
    int ledValue;

    // Read the North pin
    readValue = analogRead(pinNorth);
    ledValue = map(readValue, 0, 4095, 0, 255);
    Serial.print("- North: ");
    Serial.print(readValue);
    Serial.print(" -> ");
    Serial.println(ledValue);

    M5.dis.drawpix(2, ledValue);
    M5.dis.drawpix(6, ledValue);
    M5.dis.drawpix(7, ledValue);
    M5.dis.drawpix(8, ledValue);

    delay(10);

    // Read the South pin
    // readValue = analogRead(pinSouth);
    // ledValue = map(readValue, 0, 4095, 0, 255);
    //
    // Serial.print("- South: ");
    // Serial.print(readValue);
    // Serial.print(" -> ");
    // Serial.println(ledValue);
    //
    // M5.dis.drawpix(16, ledValue);
    // M5.dis.drawpix(17, ledValue);
    // M5.dis.drawpix(18, ledValue);
    // M5.dis.drawpix(22, ledValue);
    //
    // Serial.println("");
    // delay(10);
    }



  • @sbollaerts

    Are you usiing a gpio that does not have a ADC?

    Ah yes GPIO19 is not an ADC pin.
    here is a picture of the pins of the M5Stack
    https://www.instructables.com/Automation-With-SIM800L-ESP32-M5Stack/
    PINS 35 or 36 are the ADC's

    /



  • Hello @sbollaerts

    there is only one analog input available on the M5Atom Matrix: GPIO34 which is shared with GPIO23.

    Please check out M5AtomMatrix Schematic

    In order to use the analog input you'll need to set GPIO34 as input and disable pullup/pulldown resistors of GPIO23.

    Below code works for me:

    #include <M5Atom.h>
    
    void setup()
    {
      M5.begin(true, false, true);
    
      pinMode(GPIO_NUM_34, INPUT);
      gpio_pulldown_dis(GPIO_NUM_23);
      gpio_pullup_dis(GPIO_NUM_23);
    }
    
    void loop()
    {
      Serial.printf("GPIO34: %d\n", analogRead(GPIO_NUM_34));
      delay(1000);
    }
    

    Update: I just realised that GPIO33 can also be used as analog input.

      pinMode(GPIO_NUM_33, INPUT);
      Serial.printf("GPIO33: %d\n", analogRead(GPIO_NUM_33));
    

    Cheers
    Felix