As an application of our previous post, here is a project where we used our PicPgm to program a PIC18F4550 micro-controller.

This little project is an example of a simple audio application using a PIC micro-controller. Using only digital inputs and outputs, we developed this simple piano/synthesizer with an 8 bit kind of style:

We decided to use the PIC18F4550 micro-controller for memory purposes.

First, the following functions were assigned to each port:

pins-i-o-cc3b3pia.png

The green terminals are assigned as inputs while the red terminals are assigned as outputs.

Then the pins were associated:

entradas-saidas.png

Inputs from b1 to b11 are the push buttons in the circuit while the mode input is the switch responsible for selecting the working mode. Outputs from l1 to l11 correspond to the LED indicators. Each LED is located right above its corresponding push button and it will light up when the respective musical note is played. The audio output is the pin that will connect to the speaker.

The circuit schematic was designed using the KiCad open-source software:

esquema.png

Then the PCB layout:

pcb.png

And here’s how it looks in 3D:

dsc02104.png pcb.png

To make the circuit we used a double sided PCB. The circuit was printed in magazine paper using a laser printer, then it was transfered to the PCB using the toner transfer method. First on one side, then a few drills were made to align the designs on the other side:

dsc02086.jpg

dsc02085.jpg

Then the PCB was put on an iron perchlorate solution to remove the copper from unprotected areas:

dsc02091.jpg

dsc02092.jpg

To remove the toner we used a sponge under warm water:

dsc02096.jpg

dsc02095.jpg

Then we made all the drills and placed all the components. The used components are mostly from old electronic devices, the push buttons are from an old VCR, the LED’s are from a modem and the speaker from an old clock alarm.

We have now our finished PCB:

dsc02157.jpg

dsc02158.jpg

How it works:

dsc02102-cc3b3pia.jpg

In the Playing mode, when mode=0, the push buttons b1 to b11 correspond to “piano” keys:

b1 – A (440 Hz)

b2 – B (494 Hz)

b3 – C2 (261×2 Hz)

b4 – D2 (293×2 Hz)

b5 – E2 (329×2 Hz)

b6 – F2 (349×2 Hz

b7 – G2 (392×2 Hz)

b8 – A2 (440×2 Hz)

b9 – B2 (494×2 Hz)

b10 – C4 (261×4 Hz)

b11 – D4 (293×4 Hz)

We chose to use the second octave as main scale and then added two more musical notes up and down. It is also possible to reproduce sharps and flats by pressing two adjacent buttons.

When each button is pressed, a square wave is sent to the speaker with the respective frequency.

For instance, when b1 is pressed the note A must be played. So to create this sound, a square wave with 440Hz is sent to the audio output. To do that we know that the wave period is 1/440 = 2272 µs approximately, so the audio output is placed at high level during half this time (1136 µs) and then at low level during the other half.

if (b1)

{

audio=1;

delay_us(1136);

audio=0;

delay_us(1136);

}

Also, besides the sound, when the note A is reproduced, the l1 LED lights up.

In Memory mode each button is associated with a particular music that is played when the button is pressed.

Each music in memory is made with two vectors, one for frequencies or musical notes, and other for timings. These vectors are later read through the function Sound_Play(x,y) from the used compiler (mikroC).

At last, b0 is the reset button in our circuit.

And that’s how to make another simple and fun application with a micro-controller.

Here’s the .hex file and the PCB layout: pianopic hex+pcb.zip


João Duarte

One of the founders of eLab Hackerspace! Post-Graduate with a Specialization in Electrical and Electronics Engineering. Some of his interests include digital fabrication, home automation, robotics, high voltage and chemistry.

15 Comments

George · 28/05/2013 at 09:44

Hi! Nice project, but I don’t see HEX-file and KiCAD source’s… Can you attach this?

georgн · 26/06/2013 at 17:37

what voltage?

    João Duarte · 26/06/2013 at 23:42

    It uses 5V. It’s actually powered by an old nokia cellphone charger.

Chaparro · 06/09/2013 at 15:39

Any chance we might see the source :)?

sffbh · 17/11/2013 at 12:34

Can i ask about the Components of that project ?

    João Duarte · 18/11/2013 at 00:21

    We didn’t make a list but you can see all parts and values on the schematic. Let us know if you need any information in particular😉

mike · 25/04/2015 at 12:05

you have a dsn file for whatch how run it

henzo · 12/05/2015 at 19:56

you can post assemly code pls

Konichiwa · 07/10/2016 at 19:36

Sir do you have a piano using pic16f84a with a assembly code .asm file? Thanks

    João Duarte · 07/10/2016 at 23:57

    Hey there! Unfortunately no. I actually started this project with a PIC16F88 though, however it didn’t have enough memory for storing all the musics and not enough I/O pins for my needs.

Lisbon Mini Maker Faire – part I | The BiT Bang Theory · 07/04/2015 at 01:06

[…] Piano PIC – João Duarte; […]

Lisbon Mini Maker Faire 2014 | eLab hackerspace · 01/08/2015 at 16:45

[…] I took the PianoPIC: […]

Leave a Reply