A “Chiptune” jukebox you ask, what’s that? Well…
This is a Yamaha YM2149 IC chip, it’s a replacement chip to the AY-3-8910. It was used in the late 70’s through to the 90’s to make games consoles and computers make noise, namely the Atari ST.
I’ve always been a fan of the old school bleep blop bloopy noises of old game consoles and computers (and *ahem* early 2000’s keygens *ahem*) so when I had the chance to pick up a chip I couldn’t resist!
In this project I am going to be using the chip to build a retro sounding jukebox along with an Arduino, Orange Pi Zero and some other random electronic bits (you’ll just have to read and find out)
For those who might be interested in doing this project for yourself I will also be showing you how I eventually managed to install SC68, a piece of software that plays the SNDH format sound files. You can view that guide in my other post.
Florent Flament’s tech blog post has been a MASSIVE help in getting this going and I recommend that you go and check out his site if you’re thinking of giving this a go yourself.
This post will follow along with the project progress and I will update it when new things happen, there will also most likely be a video at some point too!
I will begin by explaining what I hope to achieve from this project. If that’s not already obvious by the title, I want a jukebox that uses the YM2149 chip to play retro tunes when a button is pressed.
- Yamaha YM2149F
- Orange Pi Zero
- Arduino Nano
- Class D Audio Amplifier
Apart from the above I will also be needing a speaker and an enclosure or some sort of box to put it all in and some buttons but we’ll get to that later on.
To begin, I shall install Armbian onto the Orange Pi Zero, this isn’t really a tutorial so I won’t go into how to do that but I’ll just say that’s done and I’ve also installed Python and some libraries as well as compiled SC68. If you are doing this and would like some more specifics feel free to message me or leave a comment.
With the Pi ready for action, I soldered the YM2149 onto some protoboard according to the schematic from Florent’s site. I did however leave out the LEDs in the top right and the crystal oscillator and instead provided the clock signal from an ATMega 328 chip as I have an idea to use the chip to provide text and playing data to a screen also in the future, hopefully, maybe. I routed all cables to headers so I could easily plug them all in.
After all the soldering was done, I flashed the Arduino Nano with the main.c file from the GitHub repo using the Orange Pi Zero and used the Arduino IDE to program the ATMega chip (My self built Arduino Uno named “Pandachip 328”) to output a clock signal to feed the YM2149 IC.
Here is the code I used in the Arduino IDE to generate the clock signal, I can’t remember where I got it from initially.
const int freqOutputPin = 11; // OC2A output pin for ATmega328 boards (Physical pin 17)
const int prescale = 1;
const int ocr2aval = 3;
// Period in microseconds
const float period = 5.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6);
// Frequency in Hz
const float freq = 1.0e6 / period;
// Setup the frequency clock maker
// Set Timer 2 CTC mode with no prescaling. OC2A toggles on compare match
// WGM22:0 = 010: CTC Mode, toggle OC
// WGM2 bits 1 and 0 are in TCCR2A,
// WGM2 bit 2 is in TCCR2B
// COM2A0 sets OC2A (arduino pin 11 on Uno or Duemilanove) to toggle on compare match
TCCR2A = ((1 << WGM21) | (1 << COM2A0));
// Set Timer 2 No prescaling (i.e. prescale division = 1)
TCCR2B = (1 << CS20);
// Make sure Compare-match register A interrupt for timer2 is disabled
TIMSK2 = 0;
// This value determines the output frequency
OCR2A = ocr2aval;
Arduino’s all hooked up and programmed, Orange Pi all setup so next I did some Python script editing on the files from the GitHub repo to start and stop the audio playback and to choose a random SNDH file from a folder and it was all working just lovely. The Arduino Nano plugs into the Orange Pi via USB and controls the YM2149.
So, what’s next? Well I need to do a lot more work on the Python script as currently it starts OK and stops OK but then continues to play another track again and again instead of stopping fully. It’s all down to the Orange Pi Zero GPIO library and my lack of pull-up resistors but anyway, that’s next update hopefully. When the code is all done I’ll chuck it on GitHub too.