Arduino Forum

Using Arduino => Audio => Topic started by: ELHeath on Sep 06, 2011, 01:40 pm

Title: MIDI Note On foot pedal
Post by: ELHeath on Sep 06, 2011, 01:40 pm
Hi! I'm trying to build a foot pedal that will allow me to send MIDI "note on" information to a sampler at the maximum velocity (as the sampler takes velocity information as control volume, so it needs to be set at the highest value). The information would be sent when a momentary switch is pressed and will stop sending when it is released. I also want this pedal to be able to send the same information but change the MIDI note (using another switch and a way of knowing which note the pedal is set to), so I would be able to move up, say from note 1, to note 20, without changing the velocity. This would enable me to trigger different loops with my sampler with my foot throughout my set.

Since the Arduino board runs C, I need to find out what each note appears as in code. I know that F#0 (lowest octave) appears as 0x1E in this example: but would I have to tell the board what each note appears as or can it move sequentially up and down? (I.E. is G0 (G on the lowest octave) 0x1F?). Is there any way of telling the board how to count up in this way so when it reaches the next octave it goes up? Would that make F# on the next octave up "1x1E" or "0x2E"?

Whenever I look, throughout the open source projects that people are making which use Arduino boards, no one ever mentions the board model they have used and there are quite a few! It would be good to keep it battery powered (9v battery?)

Basically I am trying to build a similar design to the Midi Mouse, of a similar size, but allows me to send MIDI note information, as the Midi Mouse doesn't seem to (and anyway, is rather over-priced).

If anyone could help it would be brilliant! This looks a good design but I'm trying to make mine smaller and it would be nice not to have to just trigger a MIDI event by using different switches as I only need to run one event per song, but several events in the set and it would save me having to re-program the pedal before every set if I can just move from note to note.

Many thanks,

Eric Heath
Title: Re: MIDI Note On foot pedal
Post by: D4p0up on Sep 06, 2011, 05:23 pm

Don't worry about Midi note it's simple, start from C-1 = 0, then it increments note per note...

What I'd do in this case is having a 3 switch pedal, with the center one sending the Midi Note On/Off at a Note, that you can increment / decrement by pressig on the other buttons.

Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 06, 2011, 08:18 pm
Hi, thanks for that link.

Just had a chat to my dad about Hex. F#0 appears as "0X1E" ("0X" stating that the command is in Hex and "1E" being the number). 1E is the Hex for "30". F#5 appears as "0X5A" which is the Hex for "90".

If MIDI works from Octave -1 then 0 then 1, then F#0 would be 18 and F#5 would be 78. But thanks to your chart, Midi note 30 is "F#1" and 90 is "F#6". So that has got the first bug out of the way (the wrong octaves given to the notes!).

Thanks to both the chart and a book I've found I now know which note is which Hex value, which really simplifies things. I've also found the Midi implementation chart for the SP-404 sampler I'm using, which gives the Hex value for each function or Pad as well as the Midi note number. Only problem is that it seems to stop after bank G, something about "Pad Base Channel +1". ( (Midi implementation chart).

The sampler functions start at note 46, so A#2 so a fair way up already, and ends on 118 (A#8). It would be silly to start the pedal on 0 and have to press up 46 times to get to the start so it seems sensible to write a program for each note I'll use then use the right switch to move up a program, left to go down a program and the center switch to transmit the program. So I would have to write a lot of programs!

In the tutorial on Midi here: ( the the octave of the notes seem wrong (F#-0 and not even F#0 would be "1E", F#1 is). But it also mentions that instead of writing "note off", people just tend to make velocity = 0. I was thinking, if I use a momentary switch, it would just stop transmitting anyway, but would it be worth telling the board that velocity = 0 when the switch is released? Also the tutorial is to make the board loop a chromatic scale of notes, when I would only want to play one note, not a sequence. How easy would the code be to modify to make each program play the next note up from the program before? And how easy is it to make the left and right switches tell the board to move up to the next program? Also does the Arduino have enough space for all these programs?

Would the "Pro" board be the one to get if trying to add a MIDI shield and send MIDI information?

Many thanks,

Eric Heath

Title: Re: MIDI Note On foot pedal
Post by: pellen on Sep 06, 2011, 10:24 pm
Don't worry about the octave numbers. The important thing is for keyboards the middle c is supposed to be pitch 60. I've seen synths use different numbers for that octave, probably depending on if they wanted numbering to start on -1, 0, or 1... But your device isn't even a keyboard, so the only thing that matters is making sure the pitch numbers match the numbers for each pad. No need to use hex or worry about what octaves they would represent. Seems like you already found the correct numbers from the manual, so just use those, start at the lowest one and have a switch to increase by one?

The Arduinos are all very similar. Any one of they would work for a simple project like this one.

You talk about keep sending note on while pedal is pressed. Do you mean that the sample will start playing when pressing the pedal, then stop when it is released? That is very simple. Just send note on when detecting the pedal is pressed, note off when it is released.

As for MIDI shield, I guess that would work on most normal-sized Arduinos, but for just sending MIDI the only thing you need is a MIDI port and a resistor (see the Arduino MIDI tutorial).
Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 06, 2011, 11:18 pm
Hey, thanks Pellen.

To fit a Midi port to a board, would the Uno board work? Or something a little larger? Is it easy to fit a battery compartment to these?

I'm glad it seems simple! The Sampler explains the midi notes both in numbers and in Hex. When writing the code for this, how simple is it to make the switch increase the note by one? Also you say I don't need to worry about Hex, can I program the board to just take, say 60 (middle C) and go to 61 (C#) when by pressing the right pedal and D# (59) when pressing the left one? Also how can I tell the pedal to start at 47?

The Sampler will play the sample as either a One Shot or a Loop, depending on what it is set to. I have a few One Shot samples which would be good to trigger with the pedal, they just fade out on their own (if triggered again they just start again). If set to loop, you trigger the sample and it keeps going until you play the same note again (or press the pad again) and it stops dead. This is useful too because I trigger a loop in a band I play in, and I'm playing bass when I need to cut it out again.

So this should be very simple and cheap? Brilliant! It would be good to get it working by November when I'm off on tour most of the month in China.

Thanks for all the help so far.

Eric Heath
Title: Re: MIDI Note On foot pedal
Post by: gutbag on Sep 07, 2011, 02:29 pm
I've built something similar to this. Some info here:

... although there's very little technical detail in the blog post. If you want to see some code, let me know. It's based on an Uno, BTW.
Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 07, 2011, 02:58 pm
Hi Gutbag, sure, code would be a help! I'm not a programmer but I've got an interest in it.

Indeed, seems you have a similar idea to myself. Your sampler works off Midi On as well?

The code just needs to tell the pedal to start at 46 and end at 118, a switch on the right needs to increase the note value by 1 and the switch on the left needs to reduce it by 1. The velocity needs to be 127 and it is probably best that when the momentary switch (I see you have a sustain pedal there) is released it tells the sampler that note is off, rather than velocity 0 as some people write, because my sampler takes velocity as control volume and would probably turn a looping sample's volume to 0! If you tell the sampler "note off" then it just carries on looping or just keeps playing a one shot sample. If you press the note again for a looping sample it turns it off.

So the Uno could fit 3 momentary switches and a Midi port on easily?

Thanks for all the help.
Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 08, 2011, 06:52 pm
I've just found some code and a project that again is similar without actually being close enough to what I need to understand. (

In this, it mentions note values being in numbers, not Hex, so middle C would be "0X60". It also shows how to start from a set lowest value: "const int middleC = 60;"

Middle C would be the lowest value. But the use of the term "middleC" confuses me even more.

My lowest value would not be middleC, it would be 46 or 47.

It doesn't mention how to set board to play a single note (say 46) at velocity 127, and then note off when released. It uses "velocity 0" which would not work with my sampler. Also, and most importantly, it does not explain how you could move the note value up or down sequentially using a switch.

Surely it can't be that hard to increase or decrease the pitch value (note number) by 1?

I have also found this. Any use? (

Title: Re: MIDI Note On foot pedal
Post by: mymaestro on Sep 09, 2011, 02:55 am
It's just my opinion, but I would start this project without the MIDI implementation.
Start with the basics.
First, I would start with the basic "blink" example, combined with the "DigitalReadSerial" example. Using three buttons and three LED's (and the necessary resistors), printing the values to the serial port, you can simulate almost totally what you want to do with pedals.
You will print the note number to the serial port for each button press, for example, without the complications involved in sending MIDI data. That way, you know the basic logic works, and you have very simple wiring, and can see what it does (easy to debug, get help, ask questions, etc.).
After you have the button presses lighting the correct LED's and incrementing/decrementing the values, and printing them to the serial port, it will be relatively easy to change the serial "prints" to MIDI "prints".
Title: Re: MIDI Note On foot pedal
Post by: Grumpy_Mike on Sep 09, 2011, 06:08 am
@ELHeath - further to last night's discussion get your electronics mate to build this:-
It is basically what you asked for plus a knob. When you press the select push button the select pot (knob) can be turned to rapidly change the number of the sample / note. It also serves as a preset, that is you are going up and down with the sample numbers using the up / down push buttons and then you push the select button and you instantly go back to the sample number you set last with the pot.

The three seven segment displays are on a port expander, note that the hundreds display will only show nothing or a one. This is known as half a digit so you have a two and a half digit display here.
When it is built give me a shout and we will discuss software for it.
Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 09, 2011, 04:47 pm
Hi Mike, thanks for your time explaining last night.

I'll get the board and have a play around, seeing if I can get lights to light and what not.

The girlfriend of a friend of mine studied AI at Manchester Uni, she understands the code so far, so we have tried to get it down in a basic form.

Main queries are:

With noteOff, the values are (channel, note, aftertouch)? A lot of other places mention that the third value is "velocity". I know that my sampler takes noteOn velocity information and uses that to control the volume the sample is played at. Velocity on noteOff would probably do nothing to the volume of the sample, but I can't help worrying that a velocity value of 0 would silence the sample. It is a very annoying feature and I can't find a way to turn it off on the sampler.

So, noteOff information is (0x80, 0x2E, 0x0)? (if you were trying to turn off note 46 on channel 0 (really channel 1 of course) with a velocity/aftertouch of 0). Since 0 in Hex is 0, and I've not found an example of noteOff data with a 0 velocity value, I'm guessing it would be "0" rather than "00"?

The select button and pot seem a really good idea for moving quickly between samples between songs. Much better than pressing 46 times to get up to note 92! It would make sense to use the up/down switches to enable a note/sample to be triggered (noteOn), then released (noteOff) then up to the next note/sample and the same done. Then if need be, the select switch pressed then goes back to the first note/sample value and enables that to be switched off, and the others sequentially. Brilliant.


Title: Re: MIDI Note On foot pedal
Post by: mymaestro on Sep 09, 2011, 06:04 pm
For some good explanation about hex vs decimal vs binary notations, you can read:
Title: Re: MIDI Note On foot pedal
Post by: Grumpy_Mike on Sep 09, 2011, 11:04 pm
With noteOff, the values are (channel, note, aftertouch)? A lot of other places mention that the third value is "velocity".

A lot of places are right. aftertouch is the third parameter of the note off command.
A note on with a velocity of zero should be treated the same as a note off message and all systems I have seen do.
A note off with a none zero aftertouch value will still turn the note off, most sound modules don't implement aftertouch so it is of little use. I am not too sure what it is anyway.
Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 10, 2011, 01:33 pm
Thanks Mike. The aftertouch value should read 0x0 then, for a value of 0?

I think I'll play it safe and be clear with the noteOn, noteOff commands.

Title: Re: MIDI Note On foot pedal
Post by: Grumpy_Mike on Sep 10, 2011, 06:00 pm
The aftertouch value should read 0x0 then, for a value of 0?

Yes 0x0 is the same as 0.
In any number base 0 is zero  :)

As a curiosity I had a computer system that would work in any number base you set it to. However, whenever you printed out what number base you were in it always printed 10.
This is correct, your task is to understand why.  ;)
Title: Re: MIDI Note On foot pedal
Post by: ELHeath on Sep 11, 2011, 03:42 pm
Hi Mike, was it the (0) value of 10 that made it base?

I know it seemed a silly question but the only other examples had both been 2 digit, so (10) or (2E), so rationally it might just possibly be 00 rather than just 0. Just making sure.

Board will arrive on Wednesday.
Title: Re: MIDI Note On foot pedal
Post by: Grumpy_Mike on Sep 11, 2011, 05:28 pm
well if you are in decimal the number base is 10.
If you are in hex then the number base is sixteen but when you write sixteen in hex it displays as 10.
If you are in octal then the number base is eight but but when you write eight in octal it displays as 10.

In general give any number base that number written in that number base is always 10.

In other words the second significant place is always the number base.