Friday, August 29, 2014

Organ pedal for practicing at home - for a few bucks

If someone would like to play the organ, soon will be hit by the problem that he or she can only practice playing the pedal parts in a church, needs approval, needs money, needs traveling - wouldn't it be much simpler if one could practice at home. For that the easiest is probably to buy an organ or build one. But even in the latter case, just the pedal will cost thousands of dollars.

In 2013 I got an idea to make a USB MIDI pedalboard at home, just with simple electronic and household parts, costing around $40, including all electronic and mechanical parts. You might guess that there is some trade-off here, as just the wooden material should cost around $500 for a real pedalboard. Well, take a look at my first prototype:


The trick is capacitive sensing, driving the pedals just by touching. So you need to be in socks or bare feet, and clearly some stuff would be harder or different than on a normal pedalboard, but still is a great aid in learning hand-foot independence, sharing our attention, practice harder parts, the footing, or just to play the organ at home for fun. (Most of my interest goes anyway to casual music players, not for professionals.)

My (beginner) experience is that before performing in the church, one should practice 1-2 hours on site, to get accomodated to the differences. Though this is nothing special, there are virtually no two organs with the same sizes and controls, so unless you are quite experienced, you need that extra practice time anyway.

On the video above you can see, that the "mechanical" part consits of plain household aluminum foil.
So for the full project you'll need the following parts (some of these are best to order from some Chinese gadget shop, so you'll probably need 3-6 weeks to get everything).

From a household/diy shop:
aluminum foil
- paper glue
duct tape
- 20 A4/letter paper
- 150cm polyfoam or similar insulator

From an electronics shop:
60m cheap insulated wire
- 32 pieces of alligator clips
- 4 pieces of CD4021 IC 
- 32 pieces of 680kOhm resistor
- Terminal block for 32 points (spring or screw based, doesn't matter)
- 10kOhm linear potentiometer

Electroincs shop or China (e.g. dx.com):
breadboard (either 1260 point solderless or a cca. 10x20 cm solderable)
- jumper cables for the breadboard

Tools:
- scissors
- soldering station (with a solderless breadboard you don't necessarily need it)
- multimeter (not a big deal, if you don't have one, just without it harder to find possible errors in building.)

You will need a computer, which can run http://www.hauptwerk.com/ organ sampler (but I guess you have one anyway, as this is only the pedal, and you'll probably need 2 more MIDI keyboards as manuals). Also the computer is needed for programming the Arduino.

Let's see what to do.

Electronics

Arduino is the most popular "brain" in DIY hobby electronics - it is a microcontroller, ie. something like a very small computer, which is cheap, small and directly can handle electronics components. There is an official store for officially produced Arduinos, but you can find some cheaper clones as well - mostly they do as well (though I have one clone failed from the 3. The original official one still works perfectly.)

Arduino UNO R3 version is usable for our goals, with some extra electronics we can connect 32 capacitive touch sensors and then upload a program which will turn the Arduino UNO R3 into a MIDI pedalboard with USB output.

When you're building the electronics, it's quite important to do it step by step and always check your work, check the solderings, whether every connection is looking good, there are no shortcuts etc.

When you buy an Arduion the software inside it blinks the small LED. As a first step I recommend uploading our pedalboard software to let us check its working during build.

Programming

Programming our microcontroller take two parts. First, you need to upload a program to the central unit (the atmega328 microntroller), then upload the USB-controller program (changing the firmware in the atmega16u2 chip on the Arduino board) - this will transform the Arduino from a programmable device into a USB musical instrument.

Programming the central unit

Download the microcontroller software from here: organ_pedal.cpp.hex
Using http://www.hobbytronics.co.uk/arduino-xloader you can upload it onto the Arduino (assuming you've already got the drivers, for Windows you can download it from  http://arduino.cc/en/guide/windows#toc4).

Programming the USB controller

Somewhat complicated, and I recommend doing this when building the electronics is mostly done, to let us check that the central unit's programming is already done correctly. We'll use HIDUINIO: https://github.com/ddiakopoulos/hiduino/blob/master/Compiled%20Firmwares/HIDUINO_MIDI.hex
For details see: http://bartruffle.blogspot.hu/2013/09/dfu-programming-atmega16u2-on-arduino.html

Circuit

I'm not going to show you a big schematic here, but instead a breadboard view for 8 keys. For 32 keys it is straightforward to expand.
Not the most beautiful drawing, the point is to show every connection points. Indeed, this is a very simple circuit, just having quite a lot of wires. In real life you don't need so much place (as you can get the resistors standing e.g.), you should not need more than 2 big or 4 small breadboards.

You can see the following in the picture:
- CD4021 IC, having 16 pins. 8 pins are connected to the pedal notes themselves, the purple wires show that going to the terminal then to the notes (the foils) themselves.
- Upper left pin (no. 16) goes to 5V input (+), a lower right (8) goes to the ground (-)
- The IC pins assigned as the following:
  1. Highest note (G, on 2nd IC D#, on 3rd B, on the 4th G again)
  2. not connected
  3. Goes back to the Arduino - lowest notes to pin 7, then 6, 5 and 4 respectively.
  4. Lowest note (C)
  5. C#
  6. D
  7. D#
  8. Ground
  9. Control signal from Arduino pin 8
  10. Clock signal from Arduino pin 9
  11. Ground
  12. not connected
  13. E
  14. F
  15. F# 
- Resistors: every IC pin connected to a note must also be connected to its own 680kOhm resistor and then through the resistor to Arduino pin 10.
- Variable resistor (aka potentiometer): 3 pins, side pins go to 5V and ground, middle pin goes to A0 of Arduino. This resistor will set the sensitivity of the capacitive sensors.
- Arduino 5V, GND etc. is connected according to the picture
- While you have only one CD4021, testing the first 8 notes, the inactive inputs, pins 6,5 and 4 on Arduino should be connected to the high signal level, ie. 5V

When everything is connected we can power up the Arduino using the USB cable from the computer. The computer should be connected to the wall socket (to provide some consistent grounding, otherwise there could be problems with sensitivity).

After some blinking the "ON" LED should light up on Arduino, but the L LED should not.
If everything is correct by this time, we can try the electronics with some metal (a piece of wire, a knife etc.) - touch the terminals and the L LED should light up while touching. (Make sure your body, your skin is connected to the terminal via the wire, as you body will act as the capacitor.)


Soldered on a breadboard.


Testing MIDI output


When also the USB programming is done, our computer should recognize the electronics as "HIDUINO". Starting Hauptwerk you should be able to make real sound using by touching the terminals.
The hard part is done, now let's do the "paperwork". 

The physical pedalboard

Pedalboard template

I've created a template that you can print on simple A4/letter papers. Then you just print it glue it with duct tape and can just glue the aluminium foil strips.  HERE you can download it. Two white pedals should be 63.5 mm (2.5 inches) from each other (measure at the bottom of the black keys).



My original pedalboard was linear, not curved, but you can do whatever you like. I think because of playing without shoes and just touching, not pressing, the radial pedalboard template is more practical.
You don't have to be very very very precise, your feet will be quite big relative to the pedal size, and also every pedalboards differ a bit in size anyway.

Keys (pedals)

Unfortunately aluminium foil tears easily, but hard to cut with scissors, my recommendation is to cut a sized paper template, draw the border line on the aluminium foil, and then you can easily fold and cut it. You'll need 19 pieces of long and 13 pieces of short keys.

During preparation. In the middle of the picture the key template and the cutting appliance.

Pedalboard base

2 more layers needed, the first is a polyfoam layer which will make the paper more stable and give some sense of pressure.

Wiring the keys 

Take appropriate length of wires, solder onto the alligator clips, and connect them to the respective notes - white notes will have the clip at the bottom, black notes at the top. Lead the wires under the polyfoam. (Don't lead neighboring wires very close to each other, otherwise they will sound together in some cases).

Grounding

To make the electronics work really stable, under the polyfoam or under yourself (that is you should sit on it) take a big aluminium foil plane and connect it to the GND of the Arduino.



After this you can start playing, given you can sit comfortably. A little help for this: 

Extra: organ bench 

Just for some inspiration:


The respective Sketchup model can be downloaded here, you can see the measurements there. This bench is special, because you can change the bench height. 

When you're ready, you can have something like this (or something much more beautiful):

The 1st keyboard is a 25 years old Yamaha, that's why it's yellowish.

If you create this, and want to discuss, just comment!

Extra 2: MIDI electronics for a normal pedalboard

The same electronics and microcontroller software can be used for normal MIDI pedalboard electronics as well. Just use switches that connect CD4021 to the ground at the note pins. Parallel to the switch you need a 10kOhm pullup resistor (connecting to 5V). Pushing the switch will push the note's voltage to 0 (ground) and that will mean the pushed state.

(c) Bertalan Fodor, 2014, All rights reserved

Friday, September 20, 2013

Donate for sheet music

If you would like to donate some money to support my efforts in creating free sheet music, please use the button below:


Saturday, September 14, 2013

LilyPond vs. MuseScore in polyphony

I had a hard time when wanted to typeset the polyphonic parts of BWV 572 with MuseScore 1.2.



So I gave LilyPond (version 2.16.2) a try:

\score {
 <<
 \new Staff <<
 \new Voice = "one" \relative c' {  
 \clef treble
 \key g \major
 \time 2/2 
 \voiceOne
 r2 g'' ~ g4 g fis e d1
 }
 \new Voice = "two" \relative c' {  \voiceTwo  r2 b'2 ~ b4 b a2 ~ a4 a g fis}
 \new Voice = "three" \relative c' {  \voiceThree r2 d'2 c1 ~ c4 c b2 }
 >>
>>
} 



Much better default output, mainly due to the default offset of the middle voice (which is a disadvantage in the 8th bar), but still needs tweaks from the first measure - which is much easier in MuseScore. So this use case again proves my experience: automated engraving is unfortunately more of a myth. It is better to tweak every measure visually than to tweak every second measure via a text interface. With MuseScore in 2 minutes I could arrive at the tweaked version:

Wednesday, September 11, 2013

DFU programming the atmega16u2 on the Arduino UNO R3

If you don't know what the title means, then probably you don't need this information :)

I wanted to have my own MIDI instrument, so I had to reprogram the atmega16u2 chip on my Arduino UNO R3 board. There is a somewhat outdated tutorial for that, but to completely do that, and easily I had to gather information from various blogs, forums, projects.
Though actually the process is very easy and fast, you can write a .bat file or shell script to change the firmware in seconds.

Programming with the dfu-programmer tool is very easy, for me seems easier than any other options. So these are the steps - written for Linux, but with some straightforward adjustments should apply to Windows as well - mainly the difference is that on Windows you need only the dfu-programmer package, no other installation/compiling needed - and to run dfu-programmer you don't need sudo.


Install necessary software
Download latest dfu-programmer (which knows about the atmega16u2 on the R3 Uno) from http://sourceforge.net/projects/dfu-programmer

On Linux you need to install some extra:
- sudo apt-get install libusb-1.0

On Windows you might get a 'libusb0.dll missing' error - in that case you need to install http://sourceforge.net/projects/libusb-win32/ - from the zip file you can download, unzip bin/x86/libusb_x86.dll to the same folder as dfu-programmer.exe and rename the dll to libusb0.dll
Also, on Windows - after you put the Arduino into DFU mode - you need the USB drivers for the atmega16u2 - the best is to get it from atmel's Flip programmer, there you find an Atmel\Flip 3.4.7\usb folder - so go to Device Manager (in Windows Control Panel), select Install Software for your "Unknown Device" - then set this folder as driver source - it will be installed correctly.

Unzip the downloaded file. On Windows you can use it straight away. On Linux you need some extra steps (and might need to install gcc and others tools, see compiler messages.)

To unzip and install on Linux: 
- tar xzvf ~/Downloads/dfu-programmer….tar.gz
- cd into the unzipped directory
- run ./configure
- run make
- run sudo make install

Programming a new firmware consists of the following steps:
  1. Put the atmega16u2 chip into DFU mode
  2. Erase the atmega16u2 flash memory
  3. Upload the new content for the atmega16u2 flash memory
  4. Reset the atmega16u2
  5. Plug off and in the Arduino



Put Arduino into DFU mode
First connect the Arduino to the computer using the USB port.
To reprogram the atmega16u2, you must put the chip into DFU (Device Firmware Update) mode. 
On the Arduino R3 that's very easy: shortcut briefly the 2 leftmost ICSP headers next to the USB port. 


Led on pin 13 will flash. (Might not flash if the firmware installed doesn’t do that.)
running lsusb should now show 03eb:2fef Atmel Corp., that is the Arduino is no longer visible as Arduino.
At this point you have not changed anything on the board, if you want to abort the process, just plug off and in the board.


Put new firware
First erase: sudo dfu-programmer atmega16u2 erase
Then flash the new one: sudo dfu-programmer atmega16u2 flash MYFIRMWARE.hex
Reset the chip: sudo dfu-programmer atmega16u2 reset
pull out the usb cable then put it back


Put back old firmware
To put back the original firmware, you must locate it first in your arduino installation, it is Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex
You must first erase the flash (see previous section), then flash the new one with one more special parameter:

sudo dfu-programmer atmega16u2 flash ~/prog/arduino-1.0.4/hardware/arduino/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex --suppress-bootloader-mem

Then reset the chip (see previous section) and replug the Arduino.

Running lsusb should now show Arduino SA Uno R3 (CDC ACM)


Friday, March 1, 2013

Simple mod_ruid installation

Instead of suPhp I'm now using mod_ruid on my PHP websites on Ubuntu 12.
To install, I ran the following commands:
apt-get install libcap-dev

apt-get install gcc
apt-get install apache2-prefork-dev
wget http://sourceforge.net/projects/mod-ruid/files/mod_ruid2/mod_ruid2-0.9.7.tar.bz2
tar xjf mod_ruid2-0.9.7.tar.bz2
cd mod_ruid2-0.9.7/
apxs2 -a -i -l cap -c mod_ruid2.c
service apache2 restart

Then set the following directive in the sites-available configuration file:
RUidGid myuser mygroup


Thursday, November 29, 2012

Review of Roland Mobile Cube



I've acquired a Roland Mobile Cube. I tried it before buying and was convinced. The reviews I found on the internet praised the stuff a lot, so I could hardly wait to actually try it.

Thursday, October 11, 2012

Pergolesi: Stabat Mater

Giovanni Battista Pergolesi: Stabat mater

(This post is a part of my series introducing to the enjoyment of classical music.)

Stabat Mater is a poem from the 13th century, commonly attributed to Jacopone da Todi, a Franciscan monk. It's one of the few sequences (a song specific to the given feast, which is sung before the gospel) still in use in the Roman Catholic liturgy - currently it is on the feast of "Mater Dolorosa", 15 Sept.

Stabat Mater is a meditation at Christ's cross. The richness in thoughts and pictures, its disciplined structure and colorful language usage are all exceptional, a good expression of the 13th century's exstatic view of the world. A poem basically - similarly to the Dies irae sequentia of the requiem, which is also from this century - draws a picture of a fundamental scene of Christian faith and comes to the personal participation - taking misery voluntarily gives the certainty in salvation. This route can be summarized by quoting 3 verses (in the translation of Edward Caswall):