0

I'm currently doing a project using all of the GPIO pins on the raspberry pi pico. I want to configure pins 31, 32 and 34 (GP26, 27 and 28) as outputs but keep getting the 'invalid pin' error. No idea what I'm doing wrong as the other pins all seem to be happy as outputs. The only difference I can see is that these 3 pins can also be used for the ADC.

Here's what I've done:

from machine import pin

#control pins
W = Pin(31, Pin.OUT) #GPIO 26
PROG = Pin(32, Pin.OUT) #GPIO 27
HLT = Pin(34, Pin.OUT) #GPIO 28
#Data Pins
D0 = Pin(1, Pin.OUT) #GPIO 0

This is the error message:

Traceback (most recent call last):
File "<stdin>", line 42, in <module>
ValueError: invalid pin

The data pin D0 is quite happy being an input but the others not so much. Any ideas anyone?

4
  • Noticed syntax error sorry. Pin is capitalised in the first line. Still not working
    – lia12
    Aug 17, 2023 at 15:32
  • The Pin method takes the GPIO number not the physical number!
    – CoderMike
    Aug 17, 2023 at 15:47
  • Thank you @CoderMike
    – lia12
    Aug 17, 2023 at 15:52
  • Issue seems to be gone. Such a simple fix!
    – lia12
    Aug 17, 2023 at 15:52

1 Answer 1

1

As per my comment, the machine.Pin constructor uses the GPIO number rather than the physical pin number.

https://docs.micropython.org/en/latest/library/machine.Pin.html?highlight=pin#constructors

Pico pinout: https://pico.pinout.xyz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.