MicroPython library for SN76489AN + SN74HC595N hardware music playback.
https://www.youtube.com/watch?v=EC8a8s6aKmg
Supports Sega Master System .VGM (v1.50) files from DefleMask Legacy. To import the .VGM files please use Thonny IDE.
You can use a PWM signal (3579545 Hz, 50% Duty cycle) as a clock signal without any problem.
import time
import music76489
clock = True
if clock:
from machine import Pin, PWM
clock = PWM(Pin(id))
clock.freq(3579545)
clock.duty_u16(32768) # duty 50% (65535/2)
music = music76489.Music76489()
music.load_vgm("boss_battle.vgm")
try:
while True:
delta = time.ticks_us()
music.tick()
time.sleep_us(16666-time.ticks_diff(time.ticks_us(), delta))
except KeyboardInterrupt:
music.reset()
If your music contains periodic noise, the pitch will sound one note up. This problem is perhaps due to the fact that the SN76489AN chip uses a 15-bit shift register for periodic noise / arbitrary duty cycle instead of 16-bit as in the Sega Master System.
CircuitPython to MicroPython conversion by Kyuchumimo
CircuitPython script by Ricardo Quesada from quico GitLab Repository
https://gitlab.com/ricardoquesada/quico/-/blob/master/src/music76489.py
SN74HC595N MicroPython Library by mcauser
https://github.com/mcauser/micropython-74hc595