I was able to successfully set up the overlay but I'm still not able to use both devices together.
This is a simple python code that I wrote that handles the initialization of both the display and the amp. The mixer is using the pygame library rather the device uses the st7735 library.
When I turn the raspberry pi and try to test the amp, it works correctly. However, when the python program is launched and the devices are initialized, the amp doesn't work anymore.
I think that this a software problem, maybe caused by the libraries I'm using. Do you have any hint for further anaysis?
Code:
from rotary import RotaryEncoderfrom animation import Displayfrom mixer import Mixerfrom PIL import Image, ImageDraw, ImageFontimport argparseimport pathlibimport timeimport sysimport osimport st7735WIDTH = 160HEIGHT = 128def draw_image() -> Image: img = Image.new("RGB", (WIDTH, HEIGHT), color=(255, 0, 0)) draw = ImageDraw.Draw(img) # Draw a purple rectangle with yellow outline. draw.rectangle((10, 10, WIDTH - 10, HEIGHT - 10), outline=(255, 255, 0), fill=(255, 0, 255)) # Draw some shapes. # Draw a blue ellipse with a green outline. draw.ellipse((10, 10, WIDTH - 10, HEIGHT - 10), outline=(0, 255, 0), fill=(0, 0, 255)) # Draw a white X. draw.line((10, 10, WIDTH - 10, HEIGHT - 10), fill=(255, 255, 255)) draw.line((10, HEIGHT - 10, WIDTH - 10, 10), fill=(255, 255, 255)) # Draw a cyan triangle with a black outline. draw.polygon([(WIDTH / 2, 10), (WIDTH - 10, HEIGHT - 10), (10, HEIGHT - 10)], outline=(0, 0, 0), fill=(0, 255, 255)) # Load default font. font = ImageFont.load_default() # Alternatively load a TTF font. # Some other nice fonts to try: http://www.dafont.com/bitmap.php # font = ImageFont.truetype("Minecraftia.ttf", 16) return imgif __name__ == "__main__": parser = argparse.ArgumentParser(description="Music-box CLI") parser.add_argument( "file", type=pathlib.Path, help=("Path of the song to play") ) if len(sys.argv) == 1: parser.print_help() sys.exit() args = parser.parse_args() song_file = args.file process_id = os.fork() if process_id > 0: mixer = Mixer() rotary_encoder = RotaryEncoder(mixer=mixer) mixer.music_load(song_file) mixer.music_play() try: while mixer.music_get_busy(): pass except KeyboardInterrupt: pass finally: rotary_encoder.clean_channels() else: disp = Display() img = draw_image() disp.display(img)
This is a simple python code that I wrote that handles the initialization of both the display and the amp. The mixer is using the pygame library rather the device uses the st7735 library.
When I turn the raspberry pi and try to test the amp, it works correctly. However, when the python program is launched and the devices are initialized, the amp doesn't work anymore.
I think that this a software problem, maybe caused by the libraries I'm using. Do you have any hint for further anaysis?
Statistics: Posted by cale92 — Tue Nov 26, 2024 2:37 pm