Skip to content

Analog input with string instead of machine.Pin instance fails without error #12

Closed
@tdicola

Description

@tdicola

Not a high priority but it looks like accidentally configuring a ADC using a pin string name will succeed:

adc = machine.ADC('A0')

However attempting to read values with read() will just return max value 4095.

>>> adc.read()
4095

The right way for this to work is to send a machine.Pin instance like:

adc = machine.ADC(machine.Pin('A0'))

Then the values are read as expected. However it's odd that passing a string vs. machine.Pin succeeds and doesn't fail with an error. Ideally we should catch this and throw an error that tells the user they need to specify a pin instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions