Arduino MIDI Chiptune Synthesizer

by TheSpodShed in Circuits > Arduino

22944 Views, 63 Favorites, 0 Comments

Arduino MIDI Chiptune Synthesizer

Queen of the Night, chiptunes style
IMG_3358 chiptunes.JPG

Relive the fun of early computer game music with an authentic 8-bit chiptune synthesizer, which you can control over MIDI from the comfort of any modern DAW software.

This simple circuit uses an Arduino to drive an AY-3-8910 programmable sound generator chip (or one of its many clones) to recreate that 1980's sound. Unlike the many designs that need specialised software to edit music, this looks like a standard USB MIDI device. The synthesizer has a clever algorithm which tries to keep the most musically-relevant notes playing; in many cases you can throw un-edited MIDI files straight at it and the tune comes right out. Total cost should be about £20.

Things You'll Need

IMG_3367.jpg
IMG_3369.jpg
IMG_3372.jpg

The full parts list for this, as you see in the pictures, is as follows:

  • Sparkfun Pro Micro clone (5V, 16MHz option). I used this one on Amazon.
  • Yamaha YM2149F PSG chip. I got mine from eBay.
  • 2 x 100nF ceramic capacitors
  • 1 each of 75R, 1K and 100K resistors (1/4 watt rating is fine).
  • 4.7nF ceramic disc capacitor
  • 1uF electrolytic capacitor (voltage rating > 5V).
  • 40 pin 0.6" DIP IC socket
  • 2 x 12 way 0.1" headers (this one from CPC)
  • Prototyping board, 3" by 2" approx. I bought a bulk pack of these, again on Amazon.

  • PCB mount phono socket
  • Miniature solid-core wire (like this).

You will also need a soldering iron, solder, wire cutters, pliers, and a wire stripper.

Alternative Parts

AY-3-8910.png
AY-3-8912.png
AY-3-8913.png

Alternative programmable sound generator chips

The YM2149 I used is a clone of the original General Instruments AY-3-8910 IC. (The first prototype used an AY-3-8910 I bought from eBay, but it turned out the white noise generator wasn't working. Sad face). You can use either for this project without any changes.

General Instruments also made AY-3-8912 and AY-3-8913 variants, which was the same silicon inside smaller packages, without some extra I/O pins. These pins aren't needed for any audio purposes, and this project doesn't use them. You can use an AY-3-8912 or -8913, just follow the pinouts shown above.

Alternative Arduinos

The "Pro Micro" I used is a copy of Sparkfun's Pro Micro board. If you're not confident with Arduino code it's best to stick with this; if you're happy to adapt the design, you'll need the following specifications

  • ATmega 16u4 or 32u4 device (needed to act as a USB MIDI device; the ATmega 168 or 328 can't do this).
  • 5V operation (the AY-3-8910 runs at 5V), and 16MHz clock speed.
  • At least 13 digital I/O lines.
    • Port pin PB5 must be connected (it's used to generate a 1MHz clock signal). On the Pro Micro this is used as the D9 I/O pin.

The Arduino Leonardo and Micro boards both fit the bill, although I haven't tried them.

Other components

The resistors and capacitors used here aren't particularly special. Any parts of (approximately) the right value should work.

Laying Out the Circuit Board

IMG_3454.JPG

To build the circuit, it's best to start by positioning the sockets, then add the resistors and capacitors. We'll cover wiring these together in the next step.

Using the picture above as a guide, position the 40-pin IC socket, turn the board over and just solder in two opposite corner pins first. If the socket isn't then lying flat against the board, it's easy to fix by resoldering one or other pin. When it's OK, solder the rest.

Position the two 12-pin sockets, then insert the Arduino into them to hold them vertical and steady during soldering. Again, soldering two pins at each end first will allow a check before final soldering.

For the audio output socket, I used a small drill to enlarge the PCB holes, as the mounting tags are rather large.

Wiring Up

Chiptunes schematic.png
IMG_3322.JPG

Once the major components are positioned, they can be wired up on the back of the board, following the circuit above.

The audio output components (R2, R3, C2, C3) and decoupling capacitors (C1, C4) can be connected up with solid-core wire (or off-cuts of component leads). The ground and power connections from the Arduino to the PSG chip (red and black wires, in the picture) can now be made.

The Pro Micro's various outputs are wired up to the AY-3-8910 as follows (see the hookup guide for pin assignments):

Signal   Arduino  AY-3-8910 pin

  DA0      D2        37
  DA1      D3        36
  DA2      D4        35
  DA3      D5        34
  DA4      D6        33
  DA5      D7        32
  DA6      D8        31
  DA7      A0/D18    30
  BC1      D10       29
  BC2      MOSI/D16  28
  BDIR     MISO/D14  27
  RESET#   SCLK/D15  23
  CLOCK    D9        22 (via R1, 75 ohm)

Programming Using the Arduino IDE

Select device.png

If you're new to Arduino, I'd strongly recommend trying one of the many tutorials on the basics. Sparkfun's hookup guide gives full details. You can check that the basic programming is working by following the "Blinkies" tutorial. Arduinos can be a little tricky to persuade into 'bootloader' mode (where you can load new sketches), so a bit of practice with a simple example is useful.

Once you're happy, download the chiptunes.ino file attached to this page, and build and upload it. (I've found that using the "Arduino/Genuino Micro" board type is OK for this sketch, if you want to skip installing the Sparkfun board support).

Also, note that if you're on a Mac, the "Port" setting will need to be changed once you've loaded the sketch for the first time. With a 'blank' Arduino (or using the Blinky sketch) it will appear as something like /dev/cu.usbmodemXXXX, as shown in the picture above. When the USB MIDI device is active (as used by the chiptunes.ino sketch) it will be /dev/cu.usbmodemMID1.

Downloads

Testing and Using the Synth

Show MIDI studio.png
MIDI studio test.png
MIDI Channels.png

Once the Arduino is programmed, your workstation should automatically recognise it as a USB MIDI device. It will appear with the name 'Arduino Micro' - you should be able to see this on Device Manager in Windows, or the "System Information" app in Mac OS.

On a Mac, you can use the Audio MIDI Setup app to run a basic test. Start the app, then choose Window -> Show MIDI Studio. This will bring up the MIDI Studio window - all your MIDI interfaces will appear in a slightly random arrangement - which hopefully will include the 'Arduino Micro' device. If you click the 'Test Setup' icon in the toolbar, and then click the down arrow (see picture) on the Arduino Micro device, the app will send MIDI notes to the synth. (These aren't particularly tuneful!) The synth should make some random sounds at this point.

You can then add 'Arduino Micro' as an output device to your Digital Audio Workstation's MIDI setup, and start to play!

  • The synth responds on MIDI channels 1 to 4. Each channel has a different sound (well, a different volume envelope).
  • MIDI notes between 24 and 96 (C1-C7) are accepted; notes outside this range are ignored.
  • MIDI channel 10 plays drum sounds. Note numbers between 35 and 50 (see

    https://www.midi.org/specifications-old/item/gm-level-1-sound-set) are accepted.

  • There are three voice channels on the AY-3-8910. The synth firmware tries to play the most recently sent note, while keeping the highest and lowest currently-requested notes still playing. Other notes (usually the middle notes in a chord) are cut off if necessary.


And that's about it. Have fun!

Footnotes

About the demo tune

The demo tune - Mozart's famous Queen Of The Night aria - was created reasonably quickly from a MIDI file I found on the Internet (https://www.midiworld.com/mozart.htm). Someone else did all the hard work!

I'm using Presonus Studio One on a Mac, and the MIDI file was imported to four separate tracks. A small amount of editing was needed where the accompaniment notes are higher than the main tune, and to remove some of the more objectionable glitching between notes.

The audio you hear on the clip is straight from the synth, with just a touch of EQ and saturation to give it a bit of an 'arcade machine' low-fi feel.