What do you get out of interfacing Arduino to a low cost keyboard -
UPDATE - New synthesis mode added - Auduino style grain synthesis
UPDATE - Listen to the five dollar synthesiser here -
Why hack a cheap childs keyboad -
1) Three octaves or more of ready made piano style keys
2) A large number of general purpose buttons for configuring you synth engine, adding effects or controlling a sequencer
This post concludes with a sketch which will provide your keyboard with some interesting capabilities to experiment with -
3) Four different waveforms - sine, square, ramp and dirty triangle
4) An adjustable speed arpeggio mode, low speed = arpeggios, high speed = chord like effects, very high speed = spacey distortion
5) Arpeggio record and play back
6) Transpose function, this shifts the three octave keyboard up and down by upto 7 octaves to give full access to the 128 midi note range - its also used in the video to creating the sweeping Arpeggios.
7) Delay ! - the code now features a delay function which you can here in action in the video.
Quick demonstration of using transpose with arpeggios -
Interfacing a low cost keyboard to Arduino -
The keyboard I am using is available for around 5 to 10 dollars, any similar keyboard in this price bracket is likely to work in the same way so pick one up and prepare to plug in.
So whats inside your typical five dollar keyboard ?
The main features are two PCBs which connect the many buttons and keys in a matrix.
The top PCB has been turned over to show the buttons and connections.
The entire matrix of buttons and keys is accessible from the17 solder pads visible in the center of the top PCB. Through these 17 pads we can read the state of any of the 36 keys and 33 buttons on our example keyboard.
Your keyboard may have a different number of keys and buttons, but the concept will be the same - all of the buttons are connected in a matrix pattern and this matrix is used to read the state of the individual buttons.
Zooming in for a closer look
While it might not be obvious from the picture the 17 solder connections represent 9 rows of 8 columns.
When a button is pressed it makes a unique connection between a row and a column.
By reading the state of these unique connections we know which keys are currently pressed.
The great thing about using a ready made keyboard is that someone has already built the matrix for us. This many buttons and keys to plug into our Arduino is an excellent deal - its even better when you consider that we can read these buttons using only 10 or less Arduino pins.
How can we read the buttons using only 10 pins ?
The solution is multiplexing. To do this we switch all of the rows off and then switch each one on in turn. We record which row is currently on and then read the column to see if any keys are pressed.
If we press the center key of the keyboard, our column pins will not read anything until row 3 is the active (on) row. Then we can then do some simple maths to get the key number -
key number = (row * number of pins in a column) + column;
20 = (2*8) + 4
How do we do this with Arduino ?
One approach to this would be to dedicate a digital output pin for each row and a digital input pin for each column. This can be done but its a huge waste of resources, we would also need to write code to manage the switching on and off (multiplexing) of all of these pins.
A 4017 Decade Counter is a low cost widely available chip that will do this work for us using only 2 pins from the Arduino.
The 4017 Decade counter does exactly what we want -
1) Has ten outputs
2) It only activates one output at a time
3) It automatically figures out which output to turn off and which one to turn on in a repeatable sequence
4) It does this switching across the 10 outputs and all we have to do is simply set an output HIGH then LOW to tell it when to switch to the next row.
Upgrading your keyboard
Your keyboard almost certainly has an existing micro controller inside it. In the example keyboard the micro controller is encased in a blob of white plastic so there is no chance to identify it or reprogram it.
To upgrade the keyboard we want to access the keyboard matrix using our Arduino, in the case of the example keyboard the microcontroller is on a separate board which can easily be removed by desoldering.
Before - The microcontroller PCB is fitted sideways into the main key matrix PCB.
After - The original micro controller replaced with a set of wires that we can use to access the key matrix from Arduino.
Once the original micro controller is disconnected from the key matrix we can solder in a set of wires in its place, these wires will be used to connect the Arduino and 4017.
The Schematic
Parts List -
8 * Current limiting resistors ( whatever you have between 500Ohms and 1K Ohms)
8 * 10K Pull down resistors
10 Diodes
1 * 4017 Decade Counter
Connecting wire
The arrangement of resistors shown for pin 4 should be duplicated for the 8 columns (pins 4 to 11). The 10K resistor pulls the input down to ground when the switch is open, without this, the switch would be floating leading to inconsistent readings. The 680 Resistors is in series with the pin and is there to limit the current entering the pin when a key is pressed.
In pictures
Columns
Starting at the bottom of the picture each column is connect to ground through a 10K pull down resistor.
The keyboard columns are connected through the thin white wires in the center of the picture.
These are then connected to the white jumper wires at the top of the screen through 680 Ohm current limiting resistors.
Thats it for the columns
Rows
Starting from the bottom we have the keyboard rows connected through the thin white wires.
Each of these is connected through a diode to an output of the 4017 Decade counter.
The full circuit - 72 Keys from 10 Arduino Pins using just one IC, 16 Resistors and 9 Diodes -
Later in the series we can introduce a shift register to bring the number of Arduino pins down to 5 from the current 10.
Key Scanning Code
In order to ensure the code is portable between the Arduino Mega, Uno, Leonardo, Teensy and Due, the code makes use of the DigitalIO Library. This is not as fast as using direct port manipulation or the DigitalPin library but it is around four times faster than standard Arduino digitalRead and digitalWrite functions - a useful saving.
The DigitalIO and DigitalPin libraries are the work of Arduino forum user FatLib16 whose name comes from fast SD Card libraries that FatLib16 has also created.
The DigitalIO and DigitalPin Libraries can be downloaded from the following link -
http://code.google.com/p/beta-lib/downloads/detail?name=DigitalPinBeta20120804.zip&can=2&q=
For a complete list of FatLib16's libraries see here -
http://code.google.com/p/beta-lib/downloads/list
Some of these will be interesting to explore in the future as a way to add a sample and playback capability to the 5 dollar keyboard.
Key Scan using DigitalIO Library
for(unsigned char sRow = 0;sRow <= (KEYS/COL_PINS);sRow++)
{
for(unsigned char sCol = 0;sCol < COL_PINS;sCol++)
{
// read each column pin using an array of DigitalIO objects, its faster than digital read
// and portable to UNO, Mega, Leonardo, Teensy, Teensy 3 and Due in the future
// Direct port manipulation is faster, but not portable.
if(columnPins[sCol].read())
{
unsigned char sKey = (sRow<<3) + sCol;
// Do something with this key
}
}
clockKeyScanCounter(); // clock the 4017 to scan the next keypad row
}
The Next Step
The synth engine is provided by a single oscillator, using the library referenced in this post -
http://rcarduino.blogspot.com/2012/10/arduino-modular-synthesizer-part-one.html
The next version will include a simulated patch panel to configure the oscillator paths for a wider range of sounds and effects.
For a zip file including the complete sketch and modular synth library, message me Duane B on the Arduino Forum.
Duane B
UPDATE - New synthesis mode added - Auduino style grain synthesis
UPDATE - Listen to the five dollar synthesiser here -
Why hack a cheap childs keyboad -
1) Three octaves or more of ready made piano style keys
2) A large number of general purpose buttons for configuring you synth engine, adding effects or controlling a sequencer
This post concludes with a sketch which will provide your keyboard with some interesting capabilities to experiment with -
3) Four different waveforms - sine, square, ramp and dirty triangle
4) An adjustable speed arpeggio mode, low speed = arpeggios, high speed = chord like effects, very high speed = spacey distortion
5) Arpeggio record and play back
6) Transpose function, this shifts the three octave keyboard up and down by upto 7 octaves to give full access to the 128 midi note range - its also used in the video to creating the sweeping Arpeggios.
7) Delay ! - the code now features a delay function which you can here in action in the video.
Quick demonstration of using transpose with arpeggios -
Interfacing a low cost keyboard to Arduino -
The keyboard I am using is available for around 5 to 10 dollars, any similar keyboard in this price bracket is likely to work in the same way so pick one up and prepare to plug in.
So whats inside your typical five dollar keyboard ?
The main features are two PCBs which connect the many buttons and keys in a matrix.
The top PCB has been turned over to show the buttons and connections.
The entire matrix of buttons and keys is accessible from the17 solder pads visible in the center of the top PCB. Through these 17 pads we can read the state of any of the 36 keys and 33 buttons on our example keyboard.
Your keyboard may have a different number of keys and buttons, but the concept will be the same - all of the buttons are connected in a matrix pattern and this matrix is used to read the state of the individual buttons.
In the top right of the picture you might be able to make out a small amplifier. This amplifier uses a LM386 Chip which has previously been featured on RC Arduino in the post 'Adding Audio To Arduino Projects', this drives a small speaker fitted in the keyboard.
http://rcarduino.blogspot.com/2012/08/adding-audio-to-arduino-projects.html
http://rcarduino.blogspot.com/2012/08/adding-audio-to-arduino-projects.html
Zooming in for a closer look
While it might not be obvious from the picture the 17 solder connections represent 9 rows of 8 columns.
When a button is pressed it makes a unique connection between a row and a column.
By reading the state of these unique connections we know which keys are currently pressed.
The great thing about using a ready made keyboard is that someone has already built the matrix for us. This many buttons and keys to plug into our Arduino is an excellent deal - its even better when you consider that we can read these buttons using only 10 or less Arduino pins.
How can we read the buttons using only 10 pins ?
The solution is multiplexing. To do this we switch all of the rows off and then switch each one on in turn. We record which row is currently on and then read the column to see if any keys are pressed.
If we press the center key of the keyboard, our column pins will not read anything until row 3 is the active (on) row. Then we can then do some simple maths to get the key number -
key number = (row * number of pins in a column) + column;
20 = (2*8) + 4
How do we do this with Arduino ?
One approach to this would be to dedicate a digital output pin for each row and a digital input pin for each column. This can be done but its a huge waste of resources, we would also need to write code to manage the switching on and off (multiplexing) of all of these pins.
A 4017 Decade Counter is a low cost widely available chip that will do this work for us using only 2 pins from the Arduino.
This chip has previously been featured on RC Arduino as a means to drive upto 10 Servos from just two digital output pins. It is a chip with all sorts of uses - LED Chasers, input and output multiplexing and more. If you don't have any, order a few, they are about 30 cents each and I can guarantee you will find a use for them.
http://rcarduino.blogspot.com/2012/08/arduino-serial-servos.html
http://rcarduino.blogspot.com/2012/08/arduino-serial-servos.html
The 4017 Decade counter does exactly what we want -
1) Has ten outputs
2) It only activates one output at a time
3) It automatically figures out which output to turn off and which one to turn on in a repeatable sequence
4) It does this switching across the 10 outputs and all we have to do is simply set an output HIGH then LOW to tell it when to switch to the next row.
Upgrading your keyboard
Your keyboard almost certainly has an existing micro controller inside it. In the example keyboard the micro controller is encased in a blob of white plastic so there is no chance to identify it or reprogram it.
To upgrade the keyboard we want to access the keyboard matrix using our Arduino, in the case of the example keyboard the microcontroller is on a separate board which can easily be removed by desoldering.
Before - The microcontroller PCB is fitted sideways into the main key matrix PCB.
After - The original micro controller replaced with a set of wires that we can use to access the key matrix from Arduino.
Once the original micro controller is disconnected from the key matrix we can solder in a set of wires in its place, these wires will be used to connect the Arduino and 4017.
The Schematic
Parts List -
8 * Current limiting resistors ( whatever you have between 500Ohms and 1K Ohms)
8 * 10K Pull down resistors
10 Diodes
1 * 4017 Decade Counter
Connecting wire
In pictures
Columns
Starting at the bottom of the picture each column is connect to ground through a 10K pull down resistor.
The keyboard columns are connected through the thin white wires in the center of the picture.
These are then connected to the white jumper wires at the top of the screen through 680 Ohm current limiting resistors.
Thats it for the columns
Rows
Starting from the bottom we have the keyboard rows connected through the thin white wires.
Each of these is connected through a diode to an output of the 4017 Decade counter.
Later in the series we can introduce a shift register to bring the number of Arduino pins down to 5 from the current 10.
Key Scanning Code
In order to ensure the code is portable between the Arduino Mega, Uno, Leonardo, Teensy and Due, the code makes use of the DigitalIO Library. This is not as fast as using direct port manipulation or the DigitalPin library but it is around four times faster than standard Arduino digitalRead and digitalWrite functions - a useful saving.
The DigitalIO and DigitalPin libraries are the work of Arduino forum user FatLib16 whose name comes from fast SD Card libraries that FatLib16 has also created.
The DigitalIO and DigitalPin Libraries can be downloaded from the following link -
http://code.google.com/p/beta-lib/downloads/detail?name=DigitalPinBeta20120804.zip&can=2&q=
For a complete list of FatLib16's libraries see here -
http://code.google.com/p/beta-lib/downloads/list
Some of these will be interesting to explore in the future as a way to add a sample and playback capability to the 5 dollar keyboard.
Key Scan using DigitalIO Library
for(unsigned char sRow = 0;sRow <= (KEYS/COL_PINS);sRow++)
{
for(unsigned char sCol = 0;sCol < COL_PINS;sCol++)
{
// read each column pin using an array of DigitalIO objects, its faster than digital read
// and portable to UNO, Mega, Leonardo, Teensy, Teensy 3 and Due in the future
// Direct port manipulation is faster, but not portable.
if(columnPins[sCol].read())
{
unsigned char sKey = (sRow<<3) + sCol;
// Do something with this key
}
}
clockKeyScanCounter(); // clock the 4017 to scan the next keypad row
}
The Next Step
The synth engine is provided by a single oscillator, using the library referenced in this post -
http://rcarduino.blogspot.com/2012/10/arduino-modular-synthesizer-part-one.html
The next version will include a simulated patch panel to configure the oscillator paths for a wider range of sounds and effects.
For a zip file including the complete sketch and modular synth library, message me Duane B on the Arduino Forum.
Duane B
Man I really love your project. You've done a great job of simplifying it and explaining it well. This is exactly what I've been searching the web for for a year now, something this easy to understand yet freakin awesome!!! I have 3 keyboards, a load of rock band controllers and a Mixman dm2 dj controller and an arduino UNO still wrapped up just waiting to be hacked for a bit the ol sonic madness. You are great, can't believe you don't have a million comments, this is brilliant.
ReplyDeleteThanks for the complements on the blog, you should check out the new video clip I added to the post today. I also have a few more I need to edit - one of them has me failing to play the 'fly like a G 5' hook, the synth sound is very close especially for a little 8-bit micro controller - its my attempt at playing it that is not so close.
ReplyDeleteGreat project. I like the "five dollar synth" concept.
ReplyDeleteI've made too Illutron and Auduino and some other arduino/audio/midi creations, and try to follow your tutorials. And I was wondering if it was possible (I'm sure you already thought about it) to add some LP, BP or HP filter effects. It seems impossible without FFT analysis, but maybe you have a cheap solution :)
With multiple waveforms, 2 oscillos (arduino not enough powerful ?), and filters, the five dollars synth would be better than most of 200 dollars synth...
Hi, I Have a few ideas for filters, but I also have a half formed philosophy that the five dollar synth should continue to develop as a low cost machine with a highly configurable sound of its own - rather than try and build in features that any serious musician will already have or that would drive up the cost for any less serious visitors that want to build a machine of their own. Having said that I am looking at using switched capacitor filters and also for software techniques which would provide interesting ways to morph the sound without requiring too much computation. Stay tuned. Duane B
ReplyDeleteYes, of course, the filter should have to work on the Arduino Uno. Or maybe some electronic (a few capacitors and resistors should be enough to make a basic LP filter). Maybe you already know, but I found this library which work on the Uno, and have a filter algorithm, but I don't understand at all how it works.
ReplyDeletehttps://github.com/sensorium/Mozzi/blob/master/LowPass1stOrder.h
Other idea for synth effects : There's a little effect processor called "biscuit" made by Oto :
ReplyDeletehttp://en.audiofanzine.com/multi-effects-processor/oto/biscuit/news/a.play,n.6103.html
The principle is to create drive or bitcrushing by inverting bits of the digitalized signal (when you push a button on the box, it's inverting a bit). The sound is very crazy and impredictible.
I think it shouldn't be too difficult to implement an algorithm which inverts bits in an arduino, and shouldn't take too much cpu. And the effect is very original.
Hi,
ReplyDeleteI have used bit crushing and another similar effect 'gain' in the five dollar synth. The type of bit crush I have implemented is effectivley down sampling. The other effect, 'gain' is simply digitally multiplying the signal, this causes the output to overflow and wrap around distoring the waveform. I will have a look at the links you have suggested over the holidays.
Thanks
Duane B
hi, can you show the entire sketch? thanks so much...
ReplyDeleteHi, If anyone wants the code, send me a message with your email address through the arduino forum - www.arduino.cc my username is DuaneB
ReplyDeleteDuane B
Hey, I co-run our high school engineering club, and we're starting Arduino stuff right now. What are your thoughts on this project as a beginner project? If not, then what are some good projects you did as a young neophyte?
ReplyDeleteHi, I would suggest the Illutron B or the Auduino as good projects to start with -
ReplyDeletehttp://rcarduino.blogspot.ae/2012/08/the-must-build-arduino-project-illutron.html
or
http://rcarduino.blogspot.ae/2012/08/adding-audio-to-arduino-projects.html
Would be interested to hear if your club builds them and happy to post any picture or videos particularly if you come up with some nice enclosures or use interesting sensors instead of the simple potentiometers.
Duane B
Dear Duane B,
ReplyDeletecan you please give some more help for the 4017 scan matrix code?
Thank you in advance
Stavros
What are you struggling with ?
DeleteDuane B
Dear Duane B,
ReplyDeleteI also try to the 5 dollar piano once seen in your blog.
I finally found a different aproach taken from https://arduinocode.codeplex.com/releases/view/121334
Thank you for reply and sorry if I annoyed you, but I have seen that I could ask for code if i sent message from arduino.cc
Thank you and sorry again.
Hello, The link is not working, can you send me the files? :) Thank you so much
DeleteGreat job. I have a yamaha psr 292 and I intend to do the same with it. But I think it might be trickier becaus its keyboard i s a little bit more complex. Any suggestions?
ReplyDeleteCan you send me the zip file please, this is great and I want to try it.
ReplyDeletec:
Hi Duane. I tried leaving a message at arduino.cc a few days ago (Slider2732), but maybe life moved away from checking there regularly. Got some coding done of the returning signals, plus some MIDI and...now am stuck lol. Would really appreciate the code that you wrote :)
ReplyDeleteGreetings.
ReplyDeleteI sent a message to you from arduino forum. I'm stuck in code :) Thank you so much. :)
Super project!!!
ReplyDeleteThanks for the child keyboard idea..
Hey DuaneB.. just revisited this page again to see how far you’ve gotten. You are doing a great job of exposing the value of so called cheap synth chips. A whole EMU chip to run a sound blaster card.... crazy! As an electrical scientist/hobbyist/Synth nut I love the ability to grab sound. I wish Bob Moog was still around, he’d have applauded your creativity. I’ve been working/designing, my SNÖ BEL synthesizer for my company SNÖ SOUND. Here’s something for you to explore. You have an Arduino, You have python libraries... without altering the original keyboard and utilizing all the switches,knobs, and doodads (yes I said that) you can add amazing functionality to your synth with just the cost of time that will be reusable to you in your future endeavors. Take a look at Sonic Pi. I am integrating it into my synth for a truely upgradable synth. I think you might find some answers there. Your comment on software solutions caught my eye. I like how you’re thinking 🤔 sir.
ReplyDeleteWhat sort of keyboard is that and where would you get one from?
ReplyDelete
ReplyDeleteVery nice blog, I found it very useful .Even I have this wonderful website norton.com/setup
www.norton.com/setup
ReplyDeleteThere are many blogs I have read But when I read Your Blogs I have found such useful information, fresh content with such amazing editing everything is superb in your blog, Thank you so much for sharing this useful and informative information with us. Wish you all the best for upcoming comments. And I have also few informative links which I am going share here. wwww.norton.com/setup enter product key
www.norton.com/setup, Norton product key, Norton com setup download, norton.com/setup
Hi Duane B,
ReplyDeleteeven if with a few years of delay, I read and appreciated your post "Five Dollar Synthesizer" .... is it possible to have some more information maybe with the zip file that you make available on request?
Thanks in advance
best regards
Pino Barberio (pino.barberio1@gmail.com)
On this day 10/04/2021, I testify truly about wizardcharles1@gmail.com that indeed they are honest and truly the best to be contracted for any cyber fraud solution mostly when it comes to funds recovering cause I made a huge mistake that almost ruined my life and that of my families whereby both my credit score and funds amounted to $346,000.00 US Dollars were gone simply because I wanted to invest with a broker who made me believe I can become a multimillionaire within 6 months not knowing it was just only a way out to fraud me but all thanks to wizardcharles1@gmail.com
ReplyDeletevisit their website to read more about them: https://wizardcharles1.wixsite.com/mysite/services
Great project !! But here's something that could be interesting : why not try to make some provision to upload a sound file consisting of the sound required to be played on the pressing of each key and play the sound using the keys ? That may sound a bit hard as you're using an Arduino, but still I guess it will be interesting.
ReplyDeleteContact Wizard Larry for problems such as hacking emails, Facebook, Twitter, Instagram, note changes, deleting criminal records, credit and debit refill, reloading insurance documents, lost funds or lost file recovery, background check of people and organizations Monitor your spouse's activities regarding the phone and social media and contact him at Larrywizardhacking57@gmail.com or text him on WhatsApp, telegram(+971551744806) He is trustworthy ��
ReplyDeleteWizard Brixton Group of Hacker save My Marriage I was a victim of Marriage cheats from my husband without knowing he has a family outside our Marriage and has been spending my money on them I never know he was capable of such but due thou the recently way he starts sneakily around I got suspicious of him and was in need of a Hacker to spy on him without no doubt my suspicious was true. Wizard Brixton Hacker got me proof of his message and calls and the address of other families where he goes frequently if you have such a cheating partner contact him via Wizardbrixton at Gmail dot com WhatsApp : (+1- /807-23 ) 4-0428 he is a Real Wizard
ReplyDeleteLEGIT FULLZ & TOOLS STORE
ReplyDeleteHello to All !
We are offering all types of tools & Fullz on discounted price.
If you are in search of anything regarding fullz, tools, tutorials, Hack Pack, etc
Feel Free to contact
***CONTACT 24/7***
**Telegram > @leadsupplier
**ICQ > 752822040
**Skype > Peeterhacks
**Wicker me > peeterhacks
"SSN LEADS/FULLZ AVAILABLE"
"TOOLS & TUTORIALS AVAILABLE FOR HACKING, SPAMMING,
CARDING, CASHOUT, CLONING, SCRIPTING ETC"
**************************************
"Fresh Spammed SSN Fullz info included"
>>SSN FULLZ with complete info
>>CC With CVV (vbv & non vbv) Fullz USA
>>FULLZ FOR SBA, PUA & TAX RETURN FILLING
>>USA I.D Photos Front & Back
>>High Credit Score fullz (700+ Scores)
>>DL number, Employee Details, Bank Details Included
>>Complete Premium Info with Relative Info
***************************************
COMPLETE GUIDE FOR TUTORIALS & TOOLS
"SPAMMING" "HACKING" "CARDING" "CASH OUT"
"KALI LINUX" "BLOCKCHAIN BLUE PRINTS" "SCRIPTING"
"FRAUD BIBLE"
"TOOLS & TUTORIALS LIST"
=>Ethical Hacking Ebooks, Tools & Tutorials
=>Bitcoin Hacking
=>Kali Linux
=>Fraud Bible
=>RAT
=>Keylogger & Keystroke Logger
=>Whatsapp Hacking & Hacked Version of Whatsapp
=>Facebook & Google Hacking
=>Bitcoin Flasher
=>SQL Injector
=>Premium Logs (PayPal/Amazon/Coinbase/Netflix/FedEx/Banks)
=>Bitcoin Cracker
=>SMTP Linux Root
=>Shell Scripting
=>DUMPS with pins track 1 and 2 with & without pin
=>SMTP's, Safe Socks, Rdp's brute
=>PHP mailer
=>SMS Sender & Email Blaster
=>Cpanel
=>Server I.P's & Proxies
=>Viruses & VPN's
=>HQ Email Combo (Gmail, Yahoo, Hotmail, MSN, AOL, etc.)
*Serious buyers will always welcome
*Price will be reduce in bulk order
*Discount offers will gives to serious buyers
*Hope we do a great business together
===>Contact 24/7<===
==>Telegram > @leadsupplier
==>ICQ > 752822040
==>Skype > Peeterhacks
==>Wicker me > peeterhacks