Capacitive Touch Piano Project v1

 

Capacitive Touch Piano PCB PNG

 

In this project article, I’ll be showing you an interesting project of mine that I wanted to share for quite a long time. It’s a capacitive touch piano project, specifically version 1 of it. It’s designed to be a practical example that shows you how to design an embedded system that incorporates capacitive touch sensors and DDS sound synthesis.

It’s not meant to be “the best piano” in the world. However, it should sound cool and ultimately help you learn some new concepts and techniques. Without further ado, let’s get started!

This project is sponsored by JLCPCB. One of the market-leading PCB manufacturing services in the entire world with extremely competitive prices starting from 2$/5boards. And a very high-quality PCB fabrication as we’ll see at the end of this project while testing our board. 

[toc]


Project Overview

This project is designed to be 2 versions project. In the first version (v1) of the project, which is this one, we’ll be focusing on the design of the front-end for the CapTouch Piano. Doing the capacitive touch sensors design, scanning, filtering, and all that stuff. And the sound synthesis part will be off-loaded to a PC software with a serial port communication channel in between.

After testing the front-end behavior of the (v1) board, we can confidently incorporate that part into the (v2) board which will have everything on the same board. The piano will have the CapTouch sensing for all buttons, digitally-filtered, then it’ll do the DDS sound synthesis, and finally the audio power amplifier circuitry to output audible sound to speakers port. So you can plug power “or battery” and play!

Scope of CapTouch Piano v1 Project

Capacitive Touch Piano v1 Overview

As you can see in the diagram above, the first version (v1) of this project is going to have only the front-end on the PCB board. Which is the capacitive touch piano buttons as well as the microcontroller part that will be scanning through those buttons and filtering-out any noise.

And it should finally send the key states’ data to a PC software that will be handling all other stages. The PC software in (v1) project is going to do the DDS, waveform shaping, and driving the output speaker from your PC soundcard and play the actual music.

Short Demo Test Video

 

Features Summary For This Bord

Here is a list of the most important features of this project board and also the accompanying firmware code.

  • Capacitive Touch Piano PCB PNG 17 CapTouch Piano Keys
  • Customizable/Programmable Notes For Each Key
  • Reliable Digitally-Filtered Key Scanning Routine
  • Relatively Small Size Board With Low Count BOM
  • +5v DC input For Normal Operation
  • UART Port For PC Communication
  • ICSP Port For Flashing Firmware
  • Power Indicator LED
  • Aux LED For Debugging
  • 4 Mounting Holes For External Housing (non-metallic)




System Requirements & Design Specs.

In this section, we’ll wrap up everything that needs to be designed in order to achieve this project’s goals. Starting with the hardware (PCB), then the microcontroller’s firmware, and finally the PC software that plays the sound.

Hardware Requirements

  • The Board Shall Be Powered From +5v Adapter
  • The Board Shall Have 17 CapTouch Keys Piano-Shaped
  • The PCB Shall Have a Power Indicator LED
  • The PCB Shall Have a Programming pin-header port
  • The PCB Shall Have a UART serial pin-header port
  • The PCB Shall Have an AUX LED For Debugging

Firmware Requirements

  • The Main uC Shall Scan All 17 CapTouch Keys (at least @ 50Hz)
  • The Main uC Shall Digitally-Filter All Readings
  • The Main uC Must detect key hold/release states
  • The Main uC Shall Send Key States Via UART (@ 115200bps)

Software Requirements

  • The PC Software Shall Open Serial Port (USB-TTL)
  • The PC Software Shall Always Scan For New Character Received
  • If new char is received, the software shall trigger (Pluck) the DDS with the appropriate frequency that corresponds to the piano note being played
  • Visualize the sound waves being played on the screen window

 




Hardware Design

Detailed step-by-step design for this project will be done in a pretty long video that I’m going to published very soon on my English youtube channel. Make sure to subscribe there so you don’t miss that out when it’s published, And I’m also going to published a handful of tutorials as requested by many readers and it’s time to go on YouTube as well. Stay tuned for this!

Schematic Design & Capture

The first step in the PCB design is to finalize the schematic design of the board and then do the schematic capture to the CAD software tool. The PCB design tool that I’ve used for this project was KiCAD.

PCB Layout Editing & Routing

Capacitive Touch Piano PCB Routing

Generating Fab.-Ready Output Files (Gerber)

The final step is to generate the fabrication-ready output files (Gerber) to be sent later for manufacturing.

If you’re interested in PCB design with KiCAD, you can check my course on Udemy! it’s on SALE and you can get it for maybe 10$ or something. And in case you can’t enroll for whatever reason, just join my email list to get a 100% FREE coupon whenever I’ve free coupons, I’ll send them to all my list subscribers. So it can be something to consider.




PCB / SMT Order @ JLCPCB

I’ve chosen to go with JLCPCB when I first designed this board and still highly recommend this service to anyone. It’s by far the best I’ve ever used in terms of quality, speed, and low cost. Its competitive price point makes it a market-leading company in this area.

You can use this promo code “JLC-REBE” which is permanent (never expires) to get a 2$ offer fabrication for your 5 boards.

Step1: Go to JLCPCB.com & Click on “Quote Now”

Ordering From JLCPCB Step1

Step2: Upload the Gerber (zipped) file to JLCPCB

Ordering From JLCPCB Step2

Step3: Choose the board color, fabrication options, and quantity

Step4: Scroll Down & Enable SMT Assembly For This Order

Step5: Choose The Following SMT Options: 2 Boards / Top Side SMT

Step6: Now, You’ll Be Prompted To Upload The SMT Files “BOM & POS”. Which I’ve Provided To You in The SMT Assembly Folder. Click The Buttons & Upload Them!

Step7: Uploading Done .. Click Next

Step8: Parts Automatically Detected By JLCPCB System .. Click Next

Step9: Parts Placement Preview. Now We’re Done! Place Your Order!

That was the last step for placing the SMT order at JLCPCB.com, just give them a couple of days and your boards will be delivered to you. And here is how it looked like when it arrived to me.

Now, we’re almost done with the hardware part of this project. So let’s move to the next part which is developing the firmware for the main microcontroller (PIC18F46K22).




Firmware Layered Architecture

After being done with the top-level design and hardware, we can now proceed to the firmware design step. Starting with the software layered architecture overview “Static Design”. In which, we decide on the required software components and the layers in the whole project.

As you can see in the figure below, there are only two layers in this simple architecture. The top “Application Layer” in which we’ll develop the target application. And the MCAL layer (Microcontroller Abstraction Layer) which includes all the hardware peripherals drivers (libraries) which directly interacts with the low-level hardware registers of the machine.

CapTouch Piano Firmware Layers

The MCAL layer includes the following drivers for the respective purposes:

  • Timers: can be used to periodically scan the piano keys
  • ADC: used in conjunction with the CTMU to do the Capacitive Touch Sensing
  • CTMU: Used with ADC to do the Capacitive Touch Sensing
  • UART: used to send out the piano key states to PC




The Complete Hardware Functional Diagram

To conclude everything, here is a full functional diagram for this project. So you can better imagine how each part interacts with other system components. Because now we’re going to shift the focus to the last part of this system which is the PC software (audio synthesis).

CapTouch Piano Project Diagram




Software Part (PC Sound Synthesis)

As we’ve stated earlier that the audio synthesis will be done on the PC side. Therefore, we need to also develop a software program that reads in the incoming serial data from the uC on the PCB and generates the corresponding tone sound that matches the note to be played.

For this task, I’ve chosen to go for a processing library that will help us handle the ADSR sound synthesis as well as serial data reading. So, you need to first get processing downloaded on your machine.

visit processing.org

download and install the software package. And open it, you’ll notice that it looks very similar to Arduino IDE.

Now, you’ll need to install the audio library that I’m using in my code which is “Minim”. Just like you install Arduino library as usual. Go to the library manager tab and search for the “Minim” audio library and click install, then you’re good to go!

Processing Minim Audio Library

Now, create a new sketch and use the code listing down below.

Just make sure that you change the “COM” port number to match the one for your USB-TTL chip. And you can play with the ADSR “Attack-Decay-Sustain-Release” values in order to change how the piano will sound.

You can add more notes if you wish or change the octave. I’m using octave 4 and switched to octave 5 which sounds better to me. And here is the frequency table that you should be using for finding out the fundamental frequency for each note.

Piano_Notes_Frequencies

PC Audio Synth Software For Piano (java)

You can export the application after getting to a point where everything is working fine for you. The COM port is fixed, and the ADSR values are better optimized for your personal preference. Then it can be turned into a permanent application that runs on any machine by a click of a button to export the app.

Processing ADSR Application




Final Hardware Testing

Here is a demo video for this project. Disclaimer: I’m not a good piano player by any means XD! I did learn a bit when I was young and haven’t played for years.




Concluding Remarks

Get All Source Files For This Project!

  This project will be explained in a more detailed tutorial video that I’m going to publish on my new YouTube channel. So make sure you subscribe there so that you don’t miss any new tutorial videos. Any suggestions will be welcomed!

  If you’ve got any further questions or need help in a project you can drop me a comment down below or contact me via emails. I’ll do my best to help as much as I can.

  If you feel like really into PCB design and making your own boards. Please, check out my course on PCB Design For Embedded Systems. It’s growing in popularity and has been on the “Highest Rated” on Udemy since published. So, check it out!

  In case you find this website helpful, please consider supporting my work on patreon. I’d really like to grow that campaign in order to be able to take down a lot of the random google ads scattered all over my website. I don’t really like it as much as most of the readers. But with +50k readers/month there are only 3 partons, it’s quite difficult maybe.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

1 thought on “Capacitive Touch Piano Project v1”

Leave a Comment