Author Topic: Arduino metronome with keypad input  (Read 7007 times)

0 Members and 1 Guest are viewing this topic.

Offline JuiceKingTopic starter

  • Regular Contributor
  • *
  • Posts: 233
  • Country: us
Arduino metronome with keypad input
« on: July 30, 2012, 03:50:56 am »
My wife is a musician, and this morning she complained that her metronome didn't have the precision she wanted.  She could set it to 72 or 76 beats/minute, but nothing in between.

Happily, she said that she didn't need a metronome to be battery-powered, which makes it easier. This looked like a nice opportunity to use a 12-button keypad I had in my parts box with an Arduino Uno. The Arduino would be simple to set up as a metronome with a flashing LED and clicking piezo, and the keypad would take an arbitrary input for tempo.

The result is below. One thing I discovered in working on this is that the Arduino has a very easy-to-use external interrupt scheme, tied to pins 2 and 3. I connected pin 2 to the '*' button on the keypad. So, to enter a tempo, my wife would press '*' to get the Arduino's attention, followed by the number. I used pin 3 to drive an LED, and pin 0 to drive a piezo buzzer.

One useful lesson learned: pins 0 and 1 have special serial duties associated with code loading as well as run-time serial communications for monitoring. That means that if you use serial communications for debugging messages, you must avoid using pins 0 and 1 for anything else or the utility communications will clobber your user data and vice-versa. This prototype continues to use pin 0 for the piezo buzzer, but you get a bit of spurious buzzing at boot-time and when code is loading. Unfortunately, the Arduino Uno has just enough digital input lines to handle the digits 0-9, plus the special character '*' and that leaves only 1 pin for the LED left-over, plus pins 0 and 1. That means there aren't enough pins for mapping to the '#' button, which might have served as a special termination character--an "Enter" key. I got around this by making all tempo inputs a 3-digit number. That means that 60 beats/minute is entered "*060".

Even if you don't need or want a metronome, it seems to me that this is a useful if you want to use a keypad with the Arduino for any kind of digital input. I see that there are matrix-driven keypads that use fewer pins in exchange for more complicated decoding. That's probably a better choice, and if I knew this much I wouldn't have bought this particular keypad. But since I had it on-hand, it's what I used.

Code is attached, and here's how it looks:



- Ken






« Last Edit: July 30, 2012, 07:42:10 pm by JuiceKing »
 

Offline FenderBender

  • Super Contributor
  • ***
  • Posts: 1115
  • Country: us
    • The Solid State Workshop
Re: Arduino metronome with keypad input
« Reply #1 on: July 30, 2012, 07:14:03 pm »
What a coincidence...I was laying in bed last night thinking of projects and I thought how simple and effective an metronome would be and you can deck it out with all sorts of nice features. It would be interesting if we could develop a tuner also...

I'm not sure exactly how one would do that because musical instruments have all sorts of harmonics and I'm not sure how you would analyze all of that..You'd have to extract the fundamental frequency somehow. Actually all sorts of stuff you'd need. Lot's of filters. Hmmm maybe some other time. Haha
« Last Edit: July 30, 2012, 07:19:17 pm by FenderBender »
 

Offline AlphZeta

  • Regular Contributor
  • *
  • Posts: 242
  • Country: us
    • Kerry D. Wong
Re: Arduino metronome with keypad input
« Reply #2 on: July 30, 2012, 08:16:08 pm »
Great job! The keypad input is a nice touch.

I have built two metronomes for my daughter over the years. Since a typical metronome only has around 30 discrete frequencies, I used LEDs to multiplex the display in my first built (http://www.kerrywong.com/2011/01/16/digital-metronome/).

A couple of months ago, I built another one (http://www.kerrywong.com/2012/06/21/digital-metronome-revisited/) with improved sound level and displays. It is certainly fun to build something that is also useful.
 

Offline IanJ

  • Supporter
  • ****
  • Posts: 1725
  • Country: scotland
  • Full time EE & Youtuber
    • IanJohnston.com
Re: Arduino metronome with keypad input
« Reply #3 on: July 30, 2012, 08:55:41 pm »
One useful lesson learned: pins 0 and 1 have special serial duties associated with code loading as well as run-time serial communications for monitoring. That means that if you use serial communications for debugging messages, you must avoid using pins 0 and 1 for anything else or the utility communications will clobber your user data and vice-versa.

Yes, I've bricked a serial LCD when uploading to an Arduino because the USB data is echo'd out on pin 1. Got away with it a few times until the USB data just happened to match some config codes for the LCD. No amount of soft/hard reset could fix it.

Ian.
Ian Johnston - Original designer of the PDVS2mini || Author of the free WinGPIB app.
Website - www.ianjohnston.com
YT Channel (electronics repairs & projects): www.youtube.com/user/IanScottJohnston, Twitter (X): https://twitter.com/IanSJohnston
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf