Python on IoT Redboard error

Hello. I’m running through the Jupyter Notebook Example 1B - Potentiometer. Example 1A went fine. I get an error running the following code:

potentiometer = ADC(Pin.board.A0)

Error:

Traceback (most recent call last):
e "<stdin>", line 3, in <module>
AttributeError: type object 'board' has no attribute 'A0'

Any ideas?

Did you happen to skip one of the cells? I’d guess the ‘import Pin’ was missed. You can reset and then click the button to run all of the code cells in order

Thanks for the response. No cells were skipped. RP2350 was reset. Webpage was refreshed and reconnected to the RP2350. I’ve created a new notebook with just the following lines. Same error as above.

from machine import Pin
from machine import ADC 

led_pin = Pin(34, Pin.OUT)
potentiometer = ADC(Pin.board.A0)

Additionally, does Sparkfun have documentation for Micropython?

I’ve figured out, but I’m wondering if the examples are wrong or I need newer FW or something else is happening.

I found Sparkfun’s Micropython help.c for RP2 documentation which led me to modify the code below. Seems like there is no need to provide Pin.boad.A0 like the example shows. Per the documentation, you can simply define the ADC Pin using a numeric value. See updated example below.

from machine import Pin 
from machine import ADC 

led_pin = Pin(34, Pin.OUT) 
potentiometer = ADC(0) 

Reading the potentiometer, I get a value from about 0 to 65535 with values changing as I change the pot. Again, still confused if the documentation needs to be updated or there’s something else on my end (FW update?) that needs to occur.

Are you using an older IoT RedBoard RP2350 that did not come with the MicroPython SIK kit? The firmware that ships on the boards we are including in the MicroPython SIK should contain the proper definition for Pin.board.A0. If you are using a board that you already had and are repurposing it for use with the SIK, try flashing it with the linked firmware and it should hopefully clear up your errors: https://github.com/sparkfun/micropython/releases/download/v1.26.0-preview-beta02/SIK_MICROPYTHON_IOTREDBOARD_RP2350.uf2

1 Like