Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8037

MicroPython • Some kind of interrupt messing with code

$
0
0
Hello,

I have a Raspberry Pi Pico 2W running a multiplexed 6-digit display, and there's a problem: every 14 seconds, the display turns off for about 50 ms (I can measure this more precisely if needed). It looks bad because the display visibly flashes.

At first, I thought it might be related to communication with the Wi-Fi chip, but I tried the Pico 1 (without Wi-Fi) and got the same result.

Do you have any idea why this might be happening?

Code:

# from machine import, Pin, Timermachine.freq(250000000)number_to_display = 888888Define the 7-segment pins (GP0 to GP7)segments = [machine.Pin(i, machine.Pin.OUT) for i in range(8)]  # GP0-GP7 for segments A-G and DP# Define the digit control pins (GP8 to GP13)digits = [machine.Pin(i, machine.Pin.OUT) for i in range(8, 14)]  # GP8-GP13 for digits 1-6# Seven-segment display mapping for common cathode (0-9)segment_map = [    (1, 1, 1, 1, 1, 1, 0),  # 0    (0, 1, 1, 0, 0, 0, 0),  # 1    (1, 1, 0, 1, 1, 0, 1),  # 2    (1, 1, 1, 1, 0, 0, 1),  # 3    (0, 1, 1, 0, 0, 1, 1),  # 4    (1, 0, 1, 1, 0, 1, 1),  # 5    (1, 0, 1, 1, 1, 1, 1),  # 6    (1, 1, 1, 0, 0, 0, 0),  # 7    (1, 1, 1, 1, 1, 1, 1),  # 8    (1, 1, 1, 1, 0, 1, 1)   # 9]# Timer interrupt to control multiplexingcurrent_digit = 0# Function to display a number on a single 7-segment displaydef display_digit(digit, digit_number):    global number_to_display    # Turn off all digits    for i in range(6):        digits[i].value(0)  # 1 turns off the digit (common cathode)    # Decimal point    #segments[7].value(0) # Turn off decimals    if digit_number in [1, 3]:  # Light up DP on 2nd and 4th        segments[7].value(1)  # Turn on decimal point    else:        segments[7].value(0)  # Turn off decimal point        # Set the segments according to the digit    for i in range(7):        segments[i].value(segment_map[digit][i])  # Set the segment state    # Turn on the desired digit    digits[digit_number].value(1)  # 0 turns on the digit# Function to update the display every cycledef update_display(timer):    global current_digit    # Convert the number to a 6-digit string    str_number = f"{number_to_display:06d}"        # Display the current digit    display_digit(int(str_number[current_digit]), current_digit)        # Move to the next digit    current_digit = (current_digit + 1) % 6  # Cycles through digits 0 to 5# Set up a timer to update the display every 5 milliseconds (adjust for flicker control)timer = machine.Timer()timer.init(period=2, mode=machine.Timer.PERIODIC, callback=update_display)/code]

Statistics: Posted by Auxilius — Tue Jun 10, 2025 9:32 am



Viewing all articles
Browse latest Browse all 8037

Trending Articles