Multitasking@Raspi? Running a python script while streaming audio

114 views Asked by At

I am trying to implement a digital clock in my Raspberry Pi Zero with a Audio Hat with a 7-segment display with the following code:

import tm1637
import time, threading
import datetime
tm = tm1637.TM1637(clk=5, dio=4)

def curTime():
    # display current time
    now = datetime.datetime.now()
    tm.number(int(f'{now.hour:02d}' + f'{now.minute:02d}'))
    threading.Timer(1, curTime).start()
    tm.numbers(now.hour, now.minute)

curTime()

The script works just fine, however it messes up a little bit my Mopidy audio streaming... it tere a better way to execute these 2 processes without one conflicting to the other?

Thanks for any help you guys could provide :)

1

There are 1 answers

0
Eduardo On

Shame on me: I was blaming the poor Pi while I was actually doing a silly mistake: the GPIO5 was used by mistake by the Mopidy-Raspberry-GPIO extension as a play/pause button - hence the script was pausing the audio stream while an updated time information was sent to the 7-segment display. So now audio streaming and real-time clock are working together like a charm :)