MPLAB Xpress: MP3 click piano

0

Turning your PC into a piano? All you need is one MPLAB Xpress Evaluation board, one MP3 click board, a pair of PC speakers (headphones work too) and some programming skills. The idea behind this blog post is to configure the VS1053 IC onboard the MP3 click board into real-time MIDI mode by uploading a small patch code, then sending MIDI codes according to key presses on the PC.

So, one has to solve two issues: to establish communication with the VS1053 and to convert key presses to MIDI codes. I will start with the latter, as that is the boring and complicated part of this project.

We start with a standard US PC keyboard. The keys that will be used as piano keyboard are as follows:

PC Keyboard layout

PC Keyboard layout

When a key is pressed the PC receives the ASCII code corresponding to that key press. Different key combinations, such as pressing combinations of Shift, Alt, Ctrl or by having Caps Lock on will transmit different ASCII codes. As such, a key can have multiple ASCII code mappings. When using a PC terminal program to send data to the MPLAB Xpress evaluation board, what is sent is the ASCII code for each key press. Depending on the PC terminal program used, one might not be able to send complex key combinations but only lowercase and uppercase letters, and the special characters above the numbers.

In this code example I will take into account only the Caps Lock being on. So, the ASCII codes (in hexadecimal) for my keyboard are:

PC keyboard ASCII codes mapping

PC keyboard ASCII codes mapping

In this project all I want to do is to use this keyboard as a piano keyboard, something that looks like this in C major scale letter notation:

PC keyboard piano layout

PC keyboard: piano layout

When playing MIDI music, each note has its own MIDI code. Here is how the above keyboard looks in as MIDI codes, also in hexadecimal format:

MIDI codes for the piano keyboard

MIDI codes for the piano keyboard

1 2 3 4 5
Share.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.