Unexpected WiPy ADC values



  • I'm getting an unexpected reading from the ADC.
    When I connect the ADC input to GND and read it I see a count of 0 and a voltage of 54mV (with 0dB attenuation) or a voltage of 110mV with an attenuation of 11dB.

    import pycom
    import machine
    pycom.heartbeat(False)
    
    adc = machine.ADC()
    apin = adc.channel(pin='P13',attn=adc.ATTN_11DB)
    
    print ("Count:",apin(),"  Voltage:",apin.voltage())
    

    This prints:
    Count: 0 Voltage: 110

    The displayed voltage varies with different attenuation. viz:
    54mV for 0dB, 60mV for 2.5 dB, 82mV for 6dB and 110mV for 11dB. In all cases the count is 0.
    Why is the voltage not also 0mV in all cases?



  • @Jonno That conversion is the heart of the adc.voltage() code. But consider that the adc.value() will return 0 for any input voltage below ~60mV. So if you read 0, you only know that it's below 60mV. And Vref is slightly different for each device.



  • Thanks @robert-hh . OK I see that the ESP32 ADC is less than perfect but not sure I understand why a count of 0 would give a adc.voltage() reading of non-zero.
    Perhaps I should just read the count and do the conversion to voltage myself with

    count * Vref / 4096
    

    and not use the
    adc.voltage() option.



  • @Jonno Below ~60 mV, the reading is 0. Therefore, all 0 values are mapped to that value. About the ESP32/WiPy ADC you may look at that analysis: https://github.com/bboser/IoT49/blob/master/doc/analog_io.md


Log in to reply
 

Pycom on Twitter