Pico Gpio 19 and 21 incorrect output - bug in Micropython port

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
jay99
Posts: 2
Joined: Sun Jan 31, 2021 9:33 pm

Pico Gpio 19 and 21 incorrect output - bug in Micropython port

Post by jay99 » Sun Jan 31, 2021 9:45 pm

There appears to be a bug in the Micropython port for the pico which needs to be tested/fixed by the team. When you access gpio 19 and 21 as output, sometimes they will randomly (nearly always) either 'stick' on high output (bit1) or low (bit0), or will fluctuate (especially gpio 19) and can visually see an led flicker when connected.
When you flash the Pico with CircuitPython, Gpio19 and 21 behave perfectly.
This has been reported by several users already on the Facebook group 'Raspberry Pi Pico' and from their posts you can see how the arrive at the conclusion with the Micropython firmware.

Group link https://www.facebook.com/groups/pipico

The circuit tested, red led from each gpio 18,19,20,21, through 330r to ground.

Micropython code:-

import machine
import utime

led1 = machine.Pin(18, machine.Pin.OUT)
led2 = machine.Pin(19, machine.Pin.OUT)
led3 = machine.Pin(20, machine.Pin.OUT)
led4 = machine.Pin(21, machine.Pin.OUT)

while True:
led1.value(0)
led2.value(0)
led3.value(0)
led4.value(0)
utime.sleep(1)
led1.value(1)
led2.value(1)
led3.value(1)
led4.value(1)
utime.sleep(1)


---------------------------------------------------------------------

CircuitPython code:-

import board
import digitalio
import time

led1 = digitalio.DigitalInOut(board.GP18)
led1.direction = digitalio.Direction.OUTPUT
led2 = digitalio.DigitalInOut(board.GP19)
led2.direction = digitalio.Direction.OUTPUT
led3 = digitalio.DigitalInOut(board.GP20)
led3.direction = digitalio.Direction.OUTPUT
led4 = digitalio.DigitalInOut(board.GP21)
led4.direction = digitalio.Direction.OUTPUT

while True:
led1.value = 0
led2.value = 0
led3.value = 0
led4.value = 0
time.sleep(1)
led1.value = 1
led2.value = 1
led3.value = 1
led4.value = 1
time.sleep(1)



This is a known current issue with utime and debug ports, but, this also happens when you do not use the utime module:-
Hardware setup, red led to gpio 18,19,20,21 through 4x330r to ground.
copy the 2 code listings and switch between them running each in turn.
My results, code 1: gpio 18=off, 19=on, 20=off, 21=off
code 2: gpio 18=on, 19=on, 20=on, 21=off (momentary flash on)


code 1:

led1 = machine.Pin(18, machine.Pin.OUT)
led2 = machine.Pin(19, machine.Pin.OUT)
led3 = machine.Pin(20, machine.Pin.OUT)
led4 = machine.Pin(21, machine.Pin.OUT)

led1.value(1)
led2.value(1)
led3.value(1)
led4.value(1)

led1.value(0)
led2.value(0)
led3.value(0)
led4.value(0)




code 2:

led1 = machine.Pin(18, machine.Pin.OUT)
led2 = machine.Pin(19, machine.Pin.OUT)
led3 = machine.Pin(20, machine.Pin.OUT)
led4 = machine.Pin(21, machine.Pin.OUT)

led1.value(0)
led2.value(0)
led3.value(0)
led4.value(0)

led1.value(1)
led2.value(1)
led3.value(1)
led4.value(1)

jay99
Posts: 2
Joined: Sun Jan 31, 2021 9:33 pm

Re: Pico Gpio 19 and 21 incorrect output - bug in Micropython port

Post by jay99 » Tue Feb 02, 2021 10:45 pm

Just fixed in latest 20210202.UF2 update - 2nd Feb 2021. So, if you have this problem update to this or newer UF2 file...

Post Reply