As it was mentioned on my website in my previous article, using accelerometers as drum triggers is deadly easy. So why not pushing it further, and try to develop a full drum kit? A few months have passed since I first had the idea of turning my Raspberry Pi into a drum kit, and because I wanted to do something great, I had to learn how to use C++11. That was really helpful, and I think that the project wouldn’t be that good if I had used C. In that project, the software part is clearly the heart of the drum module. It’s ensuring the communication between an ADC, connected to an accelerometer, and the Raspberry Pi. Then, the data is processed and sent to the soundcard. It sounds simple, and that’s the whole point! It is simple. And it’s also entirely reconfigurable, which means that you can change the drums sounds, and all sort of parameters to personalise your drum kit. But before I go into more details, I will describe you the hardware, and show you what you need to make your own RaspiDrums.
Presentation of the hardware
The following figure shows how the thing works.
As you hit the drums, an analogue accelerometer transforms the vibrations of the drum head into an electric signal. This signal is then converted by the ADC in a sequence of bits that depends of the acceleration measured by the accelerometer. The Raspberry Pi reads those bits, and converts them into a value that is proportional to the drum head’s acceleration. Thus, the stronger you hit the drum, the higher this number is. This value is used to set the volume of the drum sound, which is sent to the soundcard, and ultimately to your headphones.
So, according to what we just said, here is what you need:
- A Raspberry Pi (tested on B, B+, and 2B)
- An ADC — I use an ADC click
- An accelerometer — I use an ADXL377
- An external soundcard (if you want to have a good sound quality)
Attention: the choice of the accelerometer is important, please read next section to understand why! The external soundcard isn’t really necessary, but the audio output of the raspi is really bad, so that’s up to you. Anyway, if you choose an external soundcard, don’t forget to make sure that it is compatible with your Raspberry Pi.
Accelerometer + ADC
As you should know if you read my previous project, the Rhythm coach, accelerometers have a lot of advantages to be used as drum triggers. The most important one is that they don’t need any signal conditioning, the output is always very well controlled. Another advantage is that they often come soldered to a breakout board, which makes things a lot easier. Since the Raspberry Pi has only one Spi bus, I decided to use ananalogue accelerometer connected to an analogue to digital converter(ADC). The MCP3204 that I used has 4 inputs, so we can connect up to four drums to the Pi. It is very important to make sure that the accelerometer can take a really high acceleration, as the drummer can reach ±200g very easily.
Whether you want to use an external soundcard or not is up to you. It will definitely add some latency, but the integrated soundcard of the raspberry pi is really, really bad… That’s unfortunate, but at least, it has a soundcard. I use an Aureon Dual Usb from Terratec, which is compatible with the Pi and has a good audio quality. Further information will be given later, especially about the alsa configuration.
Wiring the whole thing
Here we are, if you’ve got all the components, you can now start to wire your RaspiDrums. The only tricky part is to wire the ADC to the Pi, so if you need some help, feel free to use the following schematic:
This figure shows how to connect the Raspberry Pi to the ADC.
Description of the software
As you might guess, once all the components are correctly wired together, the most important thing is to get a good software. I spent some time to make the software flexible, which is why it had to be C++11. You can download the full Eclipse project here: RaspiDrums [Github].
Please read the following sections to understand how to use the software properly.
How it works
The RaspiDrums software uses the Alsa native driver to play the drums’ sounds. All the configuration files are located in the Data folder. You can configure how the software behaves with regards to Alsa by changing the contents of the alsaConfig.xml file. Be careful though, wrong parameters can cause an unexpected behaviour of the software, i.e. no sound, crash…
Here is a example of what that file may contain:
- The device is used by Alsa to determine which soundcard to use. I recommend you keep default, but you can also try plughw:0,0, or hw:0,0.
- When capture is 0, Alsa is in playback mode. When it’s set to 1, Alsa uses your microphone to record sounds.
- The sound format should be SND_PCM_FORMAT_S16_LE. If you change that, you have to change the format of all your sound samples.
- You can choose any sample rate, as long as it is supported by you soundcard. The default is 48kHz, but you can choose 44.1kHz if you want. Note that you have to record your sample sounds at the same rate, as there will be a pitch change if you don’t.
For more detail: Electronic drums using a Raspberry Pi and ±200g accelerometers.
Current Project / Post can also be found using:
- diy module drums electric