Adding Midi to a 32 note Pedalboard via Teensy?

Status
Not open for further replies.

TJBentley

Member
Hellow all - I sent the following to Paul via email and he asked that I post here so all might see his advice and perhaps garner advice/support of others interested in this same type of project.

I am about to start a project to convert an Allen Princess organ pedalboard to midi signal and have heard about your products through the virtual organ forum. I am totally electronics illiterate and wondered if there was some instruction available to how I might accomplish this as a DIY project using your products. Hope I you don't mind my contacting you but I'm trying to explore every available and especially cost effective solution to my project.

As regards additional info I unfortunately do not have pictures at this time (no digital camera avail) but can give details of wiring and what I have.

1. There are 32 individual thin greyish wires (one for each pedal note) in the wiring harness. I have identified via multi-meter which wire goes to which pedal.

2. There is also a red and a blue wire which were apparently used originally for power/ground (common). When buzzing out the grey wires (pedal contact wires) I get continuity between each grey thin wire and the red/blue wire (they seem redundant and one could either be stripped out or just ganged to the other).

3. Signal is activated when pedal is pressed down and ends upon release of the pedal.

Questions --

1. I need therefore to connect each grey wire to an individual input on the Teensy board (32 grey wires) and then somehow connect the common (red/blue) to effect all individual grey wire connections.

2. The end result is to get a "note on - when pedal depressed/note off when pedal released" signal from the pedal to a midi output from Teensy and then to a computer via midi usb cable.

3. Obviously also have to power the board s it sends current to establish the connection to the wires.

4. At some point down the line (soonish) there will also be expression pedal(s) involved (max 3/min 1) but I don't know if this should be a separate project or if it would be included on the same Teensy with contacts.

Sorry this is so lengthy but there's a lot to explain.

My fears/hopes are -- how do I connect the grey wires to the board (ribbon cable and connectors?) and do i simply strip the non-connector end of the ribbon cable and hand wire it to each grey wire, add a little solder, and wrap each connection in electrical tape?

My shortfalls in skills are definitely electronics understanding and soldering - I have zero knowledge of either skill.

Can anyone advise me of the product list I would need from PJRC and where I might find enough instruction to wire this thing up? Also, I am clueless about writing "code" etc. to tell the board what to do.

..... If I am asking too much I would understand being told to go away (haha) I wouldn't blame ya'll.

Thanks in advance for your thoughts.

Tom
 
First, download Arduino and install Teensyduino. No purchase is necessary to get the software.

http://www.pjrc.com/teensy/td_download.html

Run Arduino and select Teensy++ 2.0 from the Tools > Boards menu. Also set Tools > USB Type to MIDI.

Then open this example using the menu: File > Examples > Teensy > USB_MIDI > Buttons

Teensy is about DIY electronics, so this is the type of code you'll be working with. Read through the code. It has a lot of comments. If you feel you can work with this, then buy a Teensy++ 2.0. This example is probably very close to what you need.

To use it, just connect the red/blue wire to GND, and the gray wires to the digital pins numbered 0 to 11. For more than 12, you'll need to copy and paste the sections in the code. Hopefully it should be pretty obvious.

But first, just get it running as-is with 12, or even just 1 peddle connected. That's the trick to doing these sorts of projects... make progress in small incremental steps to build upon each success.
 
2. There is also a red and a blue wire which were apparently used originally for power/ground (common). When buzzing out the grey wires (pedal contact wires) I get continuity between each grey thin wire and the red/blue wire (they seem redundant and one could either be stripped out or just ganged to the other).

4. At some point down the line (soonish) there will also be expression pedal(s) involved (max 3/min 1) but I don't know if this should be a separate project or if it would be included on the same Teensy with contacts.
Hi Tom,

Regarding 2. Can you check that you don't have the grey wires connect to the red (or blue) wire when depressed and the blue (or red) when idle ? that's the common way to have velocity : you can count the time between the loss of contact with one and the contact with theh other ;-)

Regarding 4. You can connect your expression pedal on the same Teensy, and make it impact the working of the sketch. You need a resistor and use an analog input. That's of course already more complex, because you need to calibrate it. The temperature tutorial of Paul should give you an idea of teh kind of complexity. Using 2 teensys would make it even much more complex, because then you need to define and debug a protocol between both (could be some MIDI, or something else).

Good luck.
 
Last edited:
Regarding 2. Can you check that you don't have the grey wires connect to the red (or blue) wire when depressed and the blue (or red) when idle ? that's the common way to have velocity : you can count the time between the loss of contact with one and the contact with theh other ;-)
Pedal boards (and organs in general) typically don't have velocity. But if it was wired like that yes, you could.

Edited to add: I checked and indeed there is no velocity (as expected). See
Allen 'Princess' Pedalboard MIDI Conversion
 
Last edited:
If you were going to detect velocity, you'd probably avoid using the Bounce library. One strategy for doing it across many keys might be storing the micros() count into an array (one per key) when the first edge is detected, then get the micros() count at the second edge is detected and subtract the first micros count for the elapsed microseconds of the key press.

But for a beginner project, I'd highly recommend keeping it simple, hopefully starting with File > Examples > Teensy > USB_MIDI > Buttons and then expanding the code as needed.
 
Hi Tom,

Pedal boards (and organs in general) typically don't have velocity. But if it was wired like that yes, you could.

And, in my opinion, it should! You are, after all, retrofitting this thing pretty much from the ground up, and there's no reason not to go above and beyond plain-ol' organ pedalboard functionality. For an example of what's possible, I'll refer you to the course webpage for UCSB's Media Arts and Technology 594O.

Sensors and Interfaces for Media Art

One student's project was a Hammond pedalboard with an Arduino-based sensor array. Here's the kicker; rather than simply providing note-on/note-off functionality, each pedal is a continuous controller (i.e. an expression pedal in its own right!). In hindsight, he cautioned that however cool a design may be, build issues like soldering complexity must be taken into account; it took him 40 hours to connect all of the sensors alone.

As far as I know, the Arduino sent the raw sensor feeds (USB serial, not MIDI) to a PC running a MaxMSP patch, which processed the sensor values to generate velocity and note-on/off messages. If you don't own MaxMSP, don't fret; its free, open-source sister Puredata is up to the task as well. However, mainstream music applications (i.e. Ableton Live, Pro Tools, Reason, FLStudio) and hardware synthesizers (i.e. Yamaha Motif, Korg Triton, Roland Fantom) don't generally have the ability to do such note-generation from continuous controllers; they will be expecting fully-formed MIDI note messages. As Adrian Freed has mentioned elsewhere on these forums, with the significantly higher computational power of the Teensy 3.0, some of these gestural pre-processing tasks may be done on the microcontroller itself; a Teensy3-based pedalboard may send both the continuous signals and cleanly-debounced note messages in the same MIDI stream.

Keep in mind that all such expanded capabilities don't mean much if they're not mapped to any parameters in your synth. A Yamaha WX-5 wind controller, for instance, benefits tremendously from being paired with its matching VL70 tone module; the VL70's presets already have the lip-pressure and breath-speed controllers mapped to appropriate sonic parameters. Although a general-purpose synth like Yamaha's flagship Motif may be far more powerful than the VL70, you'd have to edit the Motif's controller mappings by hand, which can sometimes be a frustratingly-arbitrary set of decisions to make. That being said, most synthesizers have no shortage of cool parameters waiting to be mapped; have fun!

I can't imagine a better long-term project to acquaint oneself with the basics of electronics, programming, and musical interaction design, because the scale of such a project (i.e., sky's the limit) lends itself to being broken up into a collection of related, evolving prototypes. Not only, as Paul says, is it wise to proceed in small incremental steps, but this project is amenable to being split into smaller modules (sub-designs?), each of which may yield important understanding about one or more of the issues surrounding musical systems design.
 
As Adrian Freed has mentioned elsewhere on these forums, with the significantly higher computational power of the Teensy 3.0, some of these gestural pre-processing tasks may be done on the microcontroller itself; a Teensy3-based pedalboard may send both the continuous signals and cleanly-debounced note messages in the same MIDI stream.

Even Teensy 2.0 can probably do those sorts of computations.

In fact, it's probably faster to do them on Teensy 2.0 and transmit native USB MIDI than to send as serial (even virtual serial that never gets sent as slow serial like Arduino Uno). If you run the data into something like MaxMSP, there are operating system scheduling latencies on the scale of 2 to 15 ms, to receive the data, do computations and retransmit to another application. If you use integer math, even Teensy 2.0 can do a pretty substantial amount of work to analyze and transform the raw data into useful stuff. With native USB MIDI, you're mainly dealing with the 1ms USB frame latency to get to the MIDI driver on the computer.

But of course, the first step is to just get the simplest note-on & note-off working. Tom, any word on how it's going?
 
Hi everyone,

I've been doing a lot of Internet research in the past months, in orther to finish a BDO Organ Pedalboard I built myself a few years ago (Photo 1).
Now I'm trying to midify it with an arduino nano (I friend told me to use this one), but simply had no success.

I found an wiring schematic (Photo 5) that I adapted to 30 notes in my pedalboard (5 x 6 matrix), and finished with the reed switches, diodes and magnets (Photo 2 and 4).
You can see the first 6 notes wires (Photo 3). There are 4 more groups like these.

The problems come when I connect everything to the arduino.
I simply can’t get a valid and realistic NOTE ON/NOTE OFF with the code I have.

First of all, this friend I’ve spoken gave me this arduino code and gave me some “lights” about how to try it. I have no knowledge in electronics or programming, so this increases my problems.
But the problem is that I’m not shure that it really works and, even more, I’m not shure that the suggested pins in the wiring schematic (Photo 5) are the one I really must connect the wires.

I f you want, I can send you the arduino code I have.

So, this post is just to ask you if you think that this kind of wiring schematic will really work on this, and if you think that an Arduino Nano is ok for this project.
And, of course, if you have some code already made for this kind of project, can you share it?

Hope you understand what I said and that you can help me.

Kind regards,

Jorge Martins (Portugal).

1.jpg

2.jpg

3.JPG

4.JPG

5.GIF
 
It's too bad your friend didn't suggest using a Teensy.

One really nice feature you get with Teensy, which Arduino Nano can't do, is USB MIDI. And while USB MIDI is active, you also can use Serial.print() to send info to the Arduino Serial Monitor to help figure out what your program is doing. That's a LOT easier than having to use a physical switch to change between MIDI output and the ability to see stuff in the serial monitor window.

Teensy can also do USB MIDI, real serial MIDI (with the resistor and PC900 if you need input too), and also print to the Arduino Serial Monitor: all 3 simultaneously!
 
Last edited:
Also, this project would be much simpler using a Teensy++ 2.0, because it has enough pins to simply connect each peddle to its own pin. Then you can use the Bounce library to read each one.

In fact, if you install Teensyduino (no physical board needed to install the software), you can open the example code from File > Examples > Teensy > USB_MIDI > Buttons. That example works with 12 inputs. You could just copy and paste the code and change the pin numbers and note numbers to easily extend it to 32 inputs.
 
Dear Paul,

Is it really that simple?
I didn't knew this boards.

You said that the software itself does have an example code and the board has enough pins to connect each peddle/note to its own pin. But, with this system I developed, for each reed switch/diode, I need to wires.
Are there enough pins to connect, in this case, 60 wires?

Thanks for your time.



Also, this project would be much simpler using a Teensy++ 2.0, because it has enough pins to simply connect each peddle to its own pin. Then you can use the Bounce library to read each one.

In fact, if you install Teensyduino (no physical board needed to install the software), you can open the example code from File > Examples > Teensy > USB_MIDI > Buttons. That example works with 12 inputs. You could just copy and paste the code and change the pin numbers and note numbers to easily extend it to 32 inputs.
 
It really is that simple, at least if you use one input per pin.

If you have the board, you can run the example and use a wire or paperclip to touch between GND and the pins for quick testing. You computer will receive a MIDI note on message each time the wire touches, and a note off each time it disconnects.

Teensy++ 2.0 has 46 I/O pins. 36 are on the outside edges for each connection, and 10 are located in the interior of the PCB, so you can connect up to 46 inputs this way. If you also want to connect serial MIDI (the large 5 pin DIN connectors), 2 of the pins are needed for a hardware serial port, so you could connect up to 44 inputs.

For 60 inputs, you would need to use a more complex approach.
 
Thanks.

When I said I needed 60 pins, I (think) wanted to say that I have 30 Inputs and 30 Outputs. 1 I/O for each note.
So, according to your answer, I think that will work and solve my problem.

Let me get a board and give it a try.

Thanks once more.
 
Jorge,

I f you want, I can send you the arduino code I have.

I would like to see the Arduino source code, but based on the schematic you provided I would speculate that the design is using multiple I/O to scan the pedalboard without using external multiplexer chips. See these articles for good examples of this approach.

<http://www.dan-nixon.com/2012/04/multiplexing-switches-on-arduino.html>
<http://www.dribin.org/dave/keyboard/one_html/>

Initially (i.e. in void setup(){}), all columns and rows are set HIGH. When the main program loop (void loop(){}) begins executing, it runs through a nested for-loop to read the entire button matrix. The outer loop iterates through all the column pins, each time driving one column pin LOW. The inner loop then reads all of the row pins to check if any of them are LOW; if the switch between a given row pin and the currently LOW column pin is being pressed, that row pin will read LOW. The "colPrev[cPin][rPin]" code is used to keep track of each button's prior state.

In pseudocode, here's roughly what's happening:

For each column pin

Set this column pin LOW

For each row pin​

Check this row pin

If this row pin is reading LOW​

If its previous state was not already LOW​

We have a new press. Update this button's state.​

Otherwise it was already pressed, and is still pressed. Do nothing.​

Else if this row pin is reading HIGH​

If its previous state was not already HIGH​

This button has just been released. Update this button's state.​

Otherwise it was not pressed, and is still not pressed. Do nothing.​

Reset this column pin HIGH​

Note that, using this multiple-I/O approach with 44 pins on the Teensy++ 2.0, you could theoretically scan up to 484 buttons. All those switches and diodes will likely cost much more than a Teensy! However, if you only need 30 buttons and your microcontroller has 30 or more pins, there is no need to use a multiplexing scheme. You can either:

1) Connect one contact of all buttons to +5V, and the other contact of each button to a separate pin for input. Use a loop to read all of the input pins; if an input pin reads HIGH, that means its button has been pressed. This is a scaled-up version of the technique described in <http://arduino.cc/en/Tutorial/Button>

2) A variation on the first option; set all input pins to INPUT_PULLUP. Connect one contact of all buttons to GND, the other contact of each button to a separate input pin. In this configuration, an input pin will read LOW if its button has been pressed. This is based on the technique described in <http://arduino.cc/en/Tutorial/InputPullupSerial>

When I said I needed 60 pins, I (think) wanted to say that I have 30 Inputs and 30 Outputs. 1 I/O for each note.

The Teensy++ 2.0 has 46 I/O pins, but a given pin cannot be used as an input and an output simultaneously. The microcontroller can, however, change the mode of its pins very quickly, quickly enough to achieve the impression of simultaneity in some applications, such as Charlieplexed LED matrices <http://www.instructables.com/id/Controlling-20-Leds-from-5-Arduino-pins-using-Cha/>.

For musical applications, however, this may introduce unacceptable latency, and will probably add considerable complexity to your code and circuitry.

One really nice feature you get with Teensy, which Arduino Nano can't do, is USB MIDI.

The USB-MIDI capability of the Teensy is wonderful; it's class-compliant HID, so there are no drivers to install, it just works! The convenience of this plug-and-play behavior is just one of several reasons I don't forsee purchasing many more official Arduinos anytime soon. Keep up the good work, Paul, and thank you!
 
Last edited:
Hi Andrew,

Thanks for your answer.

The first link you sent is really helpfull. I'm going to try it.

This is the code I'm using, so you can give it a look.

int baseNote = 52;
int channel = 1;

//CONSTANTS
byte noteOffByte = 0x80;
byte noteOnByte = 0x90;


byte channelCode;
byte noteOnCode;
byte noteOffCode;

int outputs[] = {8};//{A1, A2};//{8, 9, 10, 11, 12};
int inputs[] = {A1};//{8, 9};//{A0, A1, A2, A3, A4, A5};
//int actions[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int lastValue[] = {LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW};
boolean hasAction = false;

void setup() {

channelCode = byte(channel-1);
noteOnCode = noteOnByte + channelCode;
noteOffCode = noteOffByte + channelCode;

int i;
for(i = 0; i<1; i++){
pinMode(inputs, INPUT);
//digitalWrite(inputs, HIGH);
}

int o;
for(o = 0; o<1; o++){
pinMode(outputs[o], OUTPUT);
//digitalWrite(outputs[o], LOW);
}

//noInterrupts();
//digitalWrite(outputs[0], HIGH);
// Set MIDI baud rate to 31250 or 38400 :
Serial.begin(38400);
}



void loop() {

int noteGap = 0;
//para cada output
int out;
for(out = 0; out < 1; out++){
digitalWrite(outputs[out], HIGH);
//delay(10);
//vai correr os inputs
int in;
for(in = 0; in < 1; in++){
int a = digitalRead(inputs[in]);
int note = baseNote + noteGap;

if(a != lastValue[noteGap]){
if(a == HIGH){
delay(5);
a = digitalRead(inputs[in]);

if(a == HIGH){
//actions[noteGap] = 1;
noteOn(note, 0x70);
lastValue[noteGap] = HIGH;
//hasAction = true;
}
} else if(a == LOW){
delay(5);
a = digitalRead(inputs[in]);

if(a == LOW){
//actions[noteGap] = 2;
noteOff(note, 0x7F);
lastValue[noteGap] = LOW;
//hasAction = true;
}
}
}
noteGap++;
}
digitalWrite(outputs[out], LOW);
}
//if(hasAction){
//hasAction = play();
//}
}


/* boolean play(){
int n;
for(n = 0; n<30; n++){
int note = baseNote + n;
if(actions[n] == 1){
noteOn(note, 0x70);
actions[n] = 0;
}else if (actions[n] == 2){
noteOff(note, 0x7F);
actions[n] = 0;
}

}
return false;
}
*/

/* void noteOn(int pitch, int velocity) {
Serial.write(noteOnCode);
Serial.write(pitch);
Serial.write(velocity);
}

void noteOff(int pitch, int velocity) {
Serial.write(noteOffCode);
Serial.write(pitch);
Serial.write(velocity);
}
*/
void noteOn(int pitch, int velocity) {
Serial.print("noteOn ");
Serial.println(pitch);

}

void noteOff(int pitch, int velocity) {
Serial.print("noteOff ");
Serial.println(pitch);
}


Thanks for your time.

Jorge.
 
This code appears to send serial MIDI messages. On Teensy, "Serial" is the USB virtual serial. At the very least, you'll need to change every "Serial" to "Serial1", so it will transmit the messages on the TX1 pin instead of the USB.

If you want to send USB MIDI, you'll need to set Tools > USB Type to MIDI. Then you'll need to edit the functions that transmit messages. Here's the page about USB MIDI:

http://www.pjrc.com/teensy/td_midi.html

For example, you'll need to change this:

Code:
void noteOn(int pitch, int velocity) {
  Serial.write(noteOnCode);
  Serial.write(pitch);
  Serial.write(velocity);
}

to this:

Code:
void noteOn(int pitch, int velocity) {
  usbMIDI.sendNoteOn(pitch, velocity, 0);
}
 
Status
Not open for further replies.
Back
Top