Midi Record/Play/Overdub With 5-Pin Connections

* Uses an ATMega-1284 chip running at 8 MHz, with 4 k Bytes of RAM and 4 kBytes of eeprom

* Uses the old DIN 5-pin connectors

* Allows recording and playback, as well as overdub: recording along with something you recorded before.

* Full menu

* Capability of naming and storing a file in eeprom

* Editable tempos and time signatures

* Rudimentary quantization

* Proof of concept: you may find this project challenging.

What this tutorial includes:

* Parts list

* Project Report (Attached to this panel)

Contains a lot of info you need to know about the project

* Link to the C code on GitHub


* Step-by-step instructions for building the project and adapting the code

Step 1: Parts List

Some parts I got at school at a discount. Some I got at a store and paid too much. If you have time, get all this online.

1 Breadboard, any model, about the same size as the one in the introduction photo, $20

1 Microprocessor, model ATMega1284, $5

This is a versatile chip with great features. Find the data sheet here:


1 5-Volt Power Supply


This is the interface between your computer and the microprocessor. You also need some code editing software (an IDE) and a compiler that can cross-compile C to the architecture of the ATMega chip. Atmel provides an environment, Atmel Studio that meets these requirements. Download it here: https://www.microchip.com/

1 Opto-coupler, model 6N138 or equivalent, $5

This is for the input; the midi standard requires that devices be isolated from each other to prevent ground loops. I used the NEC equivalent chip with identical pin-out arrangement. See the photo above for info or just google '6n138 pinout'. If you use a model with different pin assignments, find the corresponding pins (carefully).

2 LCD Screens, Model 1602A1, $3 each

I used 2*16 displays, meaning they have 2 rows, each 16 characters wide. The code is written specifically for these, so try to use the same ones. Connections are: 8 data lines and 2 control lines. You can share the data lines between the two screens, but you need 2 control lines for each one, for a total of 4 control lines. My project uses bus C for LCD data lines and the upper nibble of bus D for control lines. If you wire yours differently, change the output buses in your code.

1 Speaker

For metronome output; any speaker will do. You'll be feeding it 3-5 volt square waves, so it doesn't need to sound pretty. You can also connect to an external amplifier.

1 Capacitor, to soften the square wave output to the speaker

2 5-Pin DIN Connectors, male or female

I used male cables and hardwired them to the board. For a more elegant solution, use female connectors and connect male cables to other devices. (Remember the pin numbers are backward depending on which way you look at the connector!)

Resistors, 180-330 Ohm, 1k-10kOhm

You may need to experiment with resistor values to get the opto-coupler to track the input quickly enough


The design calls for a diode across the opto-isolator input, but an LED will do. Use an LED for the metronome, to blink in time with the beeping speaker. Have more LED's on hand for debugging output if you need them.

Wires, lots of wires

20-22 gauge, solid wires, long, short and tiny.

Step 2: C Code

Go to github to get the code: https://github.com/sugarvillela/ATMega1284

* Make sure you read and understand the code because you may have to alter it to fit different hardware.

* The project report on the intro panel contains detailed descriptions of the software modules and how they interact.

* No copy-paste. Interact with the code; experiment; rewrite. You can probably improve it.

Step 3: Initial Wiring (Refer to the Project Photo for Guidance)

Notes about the project photo before we start

In the photo the opto-coupler is the last chip on the right, and the processor is the big chip on the left.

You'll notice two other chips in between with a bunch of resistors connected. Ignore them please. Those are shift registers, which are not being used in this project. If you ever feel like adding an LED array, you will find out what they are for.

The round black thing is the speaker (a piezo buzzer).

The buttons are top-left. That's pretty far from bus A on the lower-right of the chip.

The LCD screen on the left is LCD 0. The one on the right is LCD 1.

In these instructions, I will assume you are using the exact part specified (wherever a model number is given in the parts list).

Wire the power supply

The breadboard has power rails around the edges and between sections. Use short wires to link all of them together, and to connect them to the power supply. Now you can access positive and ground from anywhere on the board.


Install the ATMega Chip, being careful not to bend the pins (a good caution for any chip) and making sure it is seated all the way in.

Install the opto-coupler adjacent to the processor.

Wire the power supply rails to the appropriate pins on the processor and the opto-coupler.


Read the included file LCDhookup.pdf (below) for help connecting an LCD.

Each screen has two power connections and three ground connections.

Pin 3 is a brightness control that, if set wrong, will make the screen contents invisible. If you have a potentiometer handy, use this to adjust the control voltage. You can also try fixed resistors, to get the voltage about 1/2 of VCC.

Pins 4 and 6 on LCD 0 connect to D4 and D5 on the processor. These are used to enable and reset the screen.

Pins 4 and 6 on LCD 1 connect to D6 and D7 on the processor.

Pins 7-17 on both LCDs connect to C0-C7 on the processor. This is a shared data bus. Each screen will ignore the data until a control signal comes in on pin 4 and 6.

Read: LCD Info and more info to help understand how the LCD screens work.


Connect the four buttons to A2-A4 on the processor. (I left A1 open for A/D converter input, but did not use it.)

On any type of logic chip, an unconnected input floats high, meaning the processor will see a 1 on that input. To control this, you need to connect pins to ground via a resistor. I wired the buttons to be at ground (through the resistor) when not pressed, and high when pressed. Use any resistor 330 to 1k for this purpose.

Alternately, and maybe more power-efficiently, you could wire the buttons to be high when not pressed and low when pressed. You would need to change the code (buttonBus.c) to look for ~PINA instead of PINA.



    • Backyard Contest

      Backyard Contest
    • 1 Hour Challenge

      1 Hour Challenge
    • Frozen Treats Challenge

      Frozen Treats Challenge