Close
0%
0%

RaspiDrums

Electronic drums using a Raspberry Pi and ±200g accelerometers.

Similar projects worth following
I'm not working on RaspiDrums anymore, please check out my new project eXaDrums, it's much better!

Electronic drums usually use piezoelectric sensors as triggers.
Although they are cheap, they require quite a bit of signal conditioning.
I decided to spend more money on sensors that don't require any additional components.
After spending some time looking for the right sensors, I found the perfect candidate: an accelerometer! I was quite surprised to see that the acceleration of a drum head can be greater than 200g! (according to Wikipedia that's more than a Sprint missile -- see "G-force" page).

I decided to use the ADXL377 3-axis accelerometer, because they have 1kHz low-pass filters at each output, the signal is thus very clean, and it always stays between 0 and 3.3V.

As I want the drum kit to be as close as possible to real electronic drums, I use a Raspberry Pi (originally B/B+, and now 2B).

***************************************************************************************************************************************

I'm not working on RaspiDrums anymore, please check out my new project eXaDrums, it's much better!

***************************************************************************************************************************************

Introduction

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

General overview

The following figure shows how the thing works.

diagram

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.

Hardware required

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.

Usb soundcard

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...

Read more »

  • 1 × Raspberry Pi Can be a B, B+ or 2B
  • 1 × MCP3204 or equivalent ADC Clips, Contacts, Terminals and Splices / Terminals
  • 1 × ADXL377 Semiconductors and Integrated Circuits / Misc. Semiconductors and Integrated Circuits
  • 1 × USB Soundcard Optional

  • New project: eXaDrums

    Jeremy01/28/2016 at 19:58 0 comments

    Hey guys,

    RaspiDrums is now a completed project, and I'm working on eXaDrums instead.

    eXaDrums comes as a shared library that is a fork of RaspiDrums. In addition to the shared library, an executable provides a nice GUI, which can be used with the Raspberry Pi 7" official touchscreen. Pretty exciting isn't it?

    In short, eXaDrums is an electronic drum kit, and its drum module has a touchscreen!

    Check out the new project: https://hackaday.io/project/9350-exadrums.

    Cheers.

  • Last project log next week

    Jeremy01/22/2016 at 23:00 0 comments

    Hi guys,

    I'm currently writing the other project I told you about in the previous log. The new software is a fork of RaspiDrums, and it will be published next week on Hackaday.io.

    As a result, I will change the status of the RaspiDrums project to "completed", and work exclusively on the new project. Of course, the source codes of both projects will be available on Github.

    Note that, for the new project, I intend to use tinyxml2 instead of libxml. I haven't started that yet, but that one of the many things I have to do.

    Cheers.

  • Slight change of plan

    Jeremy01/06/2016 at 22:55 0 comments

    It's now official, I'm going to New Zealand for work, so I'm going to be away for a couple of weeks. It's probably going to be very difficult to work on the software during those two weeks.

    However, I'd like to make some progress, so instead of improving the SoundProcessor, and publish a new video, I will start to write the new project. I intend to publish the project by the end of the month. The software is now stable enough, even if there's still the sound processor to improve.

    Apart from that, I ran the software on my Raspberry Pi 2 with Ubuntu MATE 15.10, it works pretty well. So far, it has been running on my laptop under Debian (Jessie, and Sid), Xubuntu (15.04, and 15.10), and on the Raspberry Pi 2 under Raspbian (Wheezy, and Jessie), and Ubuntu MATE (15.10). I think it's important to make sure that the software runs okay with different operating systems. So far, so good!

    Cheers,

    Jeremy.

  • New Year: updates

    Jeremy01/03/2016 at 12:28 0 comments

    Some interesting things happened between over the last month:

      • I updated my Raspberry Pi 2B to Raspbian Jessie. FYI, I used the method described here: https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=121880 and it worked straight away. Though, if you intend to do it that way, be aware that it took almost 3 hrs to update everything (I removed the wolfram engine prior to the update to speed things up). If you want to know more about Raspbian Jessie, you can read this: https://www.raspberrypi.org/blog/raspbian-jessie-is-here/.
        The desktop doesn't really change, but the benefit is that you get up to date software. It's really good to work with an (almost) up to date g++ compiler!
        However, when I tried RaspiDrums, I had no sound over the USB sound card...
        It wasn't too hard to fix though. I just followed the method described here: http://superuser.com/questions/989385/alsa-base-conf-missing-in-new-raspberry-pi-raspbian-jesse.
        So finally, it works very well, and I'm quite happy with the update.
      • I didn't spend so much time coding, but I though a lot about possible improvements.
        A good one is that I figured a way to avoid real-time sound processing. Instead, the sounds will be processed as the drum kit is being loaded. It will use more RAM, but less CPU, and it will probably be easier to implement.
      • Another good news is that I ordered all the components to build the final board. The design is pretty clear in my head, so I'm going to start asap.
        The board will feature a MCP3008, which means 8 analog inputs, instead of 4 right now (MCP3204). Since the hi-hat needs two sensors (pedal + cymbal), I intend to build the following drum set:
        • Snare drum
        • Bass drum
        • Hi-had (pedal + cymbal)
        • Tom-tom
        • Floor tom
        • Crash cymbal
        • Ride cymbal
        That's a minimalist drum kit, but I don't need more than that.
      • Unfortunately, I'm going to have to travel or work, probably for a couple of weeks. So that's going to help to get things done quickly...
        But when I come back, the plan will be the following:
        • Deal with the SoundProcessor.
        • Publish a new video to show you how it performs.
        • Publish the new project.
        • Build the board.
        • Improve the software.
        • Start to build the kit.

      Not sure how I'm going to build the kit yet, but I have some time to think about it before I start. Suggestions are more than welcome. The main goal is to make it cheap, easy to build, and stable. I will use muffle heads for the drums, as I already have them, but everything else is to be determined.

      That's it for now!

      Happy new year to all of you.

      Cheers.

    • Some progress

      Jeremy12/19/2015 at 21:35 0 comments

      As mentioned in the previous post, I've been working a lot on RaspiDrums. A lot of improvements have been made, and as I said, I'm still waiting for the software to be a bit more stable before I publish the changes.

      Basically, everything I mentioned in the previous post is almost finished. The biggest thing now is to work on the Sound Processor. When that part is done, I will be able to focus on the hi-hat, and that shouldn't take very long.

      Because it's the end of the year, and I have less and less time, I think I will need another month or two to finish that. So end of February, or possibly a bit before that, is the target for a working hi-hat system. As I said in the previous log, the work I'm doing now will be published in another project, because it's now very different, and a lot better.

      Cheers.

    • Lots of changes...

      Jeremy11/15/2015 at 16:08 0 comments

      Despite the absence of project logs, I've been working quite a lot on RaspiDrums. I haven't published anything yet because I'm waiting for the software to be more stable. All the modifications concern the software, and they make it a lot easier to use.

      Here's a list of the major changes:

      • The project is now a shared library, so it's a lot easier to reuse in other programs.
      • I Created a SoundBank that holds and handles all the sounds.
      • I Created a SoundProcessor for some real-time sound processing.
      • I Created a KitManager to manage the drum kits configuration.
      • Sensors' inputs are read in a separate thread.
      • Don't need to specify which sensor to use in the code.
      • And there's a lot more, and a lot more is coming...

      The projects is now a lot bigger than it used to be, and it will continue to grow. I want that software to become exactly like a real drum module, but I need more time to make it so. I think that it will take another couple of months before I can publish something. It's actually going to become a new project, and there's a reason for that, but that's a surprise! I'll let you guys know how things go, but I'm really optimistic, it's really going to become a very cool software.

      Cheers.

    • Time to think about the hi-hat

      Jeremy09/27/2015 at 20:40 0 comments

      I've been thinking quite a lot about the hi-hat lately.

      I don't know exactly how the software will handle it, as I'd like to get a continuous variation of the sound between the closed and open states.

      So far I'm investigating the hardware, and it looks like I'll go for an optical detection (phototransistor + led). So, I just bought and tested a KITRONIK 5105 Ambient Light Sensor Breakout Board. It uses a SFH 320-3/4-Z phototransistor, so we're talking about visible light.

      The measured response time is about 2 ms, which is probably good enough for a hi-hat pedal. We'll see if it's worth pursuing.

      Cheers.

    • Working with two sensors now.

      Jeremy09/20/2015 at 21:11 0 comments

      Hi guys,

      I tried to make RaspiDrums work with two sensors yesterday, and guess what, it worked (after a minor bug fix...). This a little step forward, but an important one that has now disappeared of my TODO list.

      The good news is that the latency doesn't change at all. So, whatever the number of sensors I use, it should remain below 10 ms (tested on Raspi 2B only).

      I guess the next step is to start thinking about a viable solution for the hi-hat. I already have an idea for the software, so I just need validate it, and to find the right sensor for the pedal.

      Cheers.

    • Latency goes below 10ms!

      Jeremy09/13/2015 at 13:55 0 comments

      Latency has always been an issue since I started this project. The main reason was that the sound card I use a minimum buffer size of 1024 samples, which corresponds to a latency of 21.3 ms at 48kHz sample rate.

      The obvious choice is to use another sound card. I now use a Startech ICUSBAUDIO2D, for which I can set a 44.1, 48, or even 96kHz sample rate. But that's not it, the minimum buffer size is 96 samples, which corresponds to 2 ms latency at 48kHz.

      Using this configuration, I was able to compare the delay between the piezo, that is already in one of my Roland's drum pads, and the output of the RaspiDrums.

      The following figure shows how this delay changes.

      The average delay is 12.8 ± 0.7 ms. But that's without setting a high priority to the process. So, using nice, and setting the highest priority, I was able to get 9.2 ± 0.8 ms. That's below 10 ms!

      Those tests were performed with a scan time of 4 ms, which means that RaspiDrums scans the signal for 4 ms, looking for the maximum value, before it sends the sound to the mixer. Lowering this value leads to a lower latency. So finally, using a 1 ms scan time instead of 4 should lead to 6.2 ± 0.8 ms (not tested, but I recommend you use a 4 ms scan time).

      In conclusion, that definitely proves that RaspiDrums latency is below 10 ms. Note that even without using nice (12.8 ms latency), I don't really notice any latency while playing.

      Cheers.

    • Thanks Hackaday!

      Jeremy09/12/2015 at 14:41 0 comments

      Last week RaspiDrums has been featured by the hackaday team:

      http://hackaday.com/2015/09/04/raspidrums-uses-expensive-sensors/

      I wanted to thank them, so thanks a lot guys! I hope this will give a lot of good ideas to the readers, and help them to find new applications for high g accelerometers.

      Some project updates are coming soon, don't miss them!

      Cheers.

    View all 12 project logs

    Enjoy this project?

    Share

    Discussions

    The Big One wrote 09/02/2015 at 22:08 point

    Ahh, so this is what you are doing.  Very interesting idea, I had not thought to use an accelerometer as a drum sensor.  That will definitely get rid of most of the hardware I have designed for piezo conditioning, and probably give a much larger dynamic range that I am getting with piezos.

    I wonder what the upper limit of the number of drums that you can support is?  I suppose that would depend on the accelerometer + interface... if you are using an external ADC like you show above, you could use multiple ADCs with 4 channels each for more drums (you just need to dedicate a pin for CS on each SPI interface).  I2C accelerometers would be easier for low numbers, but would probably be difficult on more than 8 drums (most devices that I see don't give you more than 3 address bits, if that).  Plus I2C is much slower than SPI.

    It's hard to tell from the video, but I do not see any noticeable latency.

    Anyway, very nice work, I will definitely be watching your progress.

      Are you sure? yes | no

    Jeremy wrote 09/04/2015 at 20:20 point

    Cheers mate! 
    Yes, accelerometers are expensive, but the output is quite clean.
    I know for sure that I can have at least 4 drums. That's because the ADC
    is a MCP3204, it has 4 outputs, and I can read them one after another.
    It might be possible to get 8 drums with the MCP3208. If you use the CS
    pin, you can have even more. 
    I haven't really tried I2C, but I think you're right, it's probably too slow...

    It's really to say if there's some latency by just looking at the video. I used a pad from my electronic drums, and recorded the output of both the piezo and the soundcard of the raspi. The latency varies between 20 and 25 ms, worst case is 30 ms... It seems to be because of alsa(?), as the raspi 2B isn't any faster than the B+... That's why I asked you the question about the latency of your drum kit with the raspi. But I believe that, if you use a codec, it's a lot faster. Again, maybe is misconfigured alsa...

    I'll be watching you progress too! I'm looking forward to seeing your results.

      Are you sure? yes | no

    The Big One wrote 09/04/2015 at 20:23 point

    I'm hoping that the PCBs arrive next week (I was hoping that they would arrive this week, but that has not happened).  Once I get it all together I will try a similar latency test to see what sort of latency I am getting.  I'll let you know.  :-)

    Cheers

      Are you sure? yes | no

    Jeremy wrote 09/04/2015 at 20:29 point

    Hope you get your PCBs next week.
    Hopefully the latency will be very low ;-)
    Cheers.

      Are you sure? yes | no

    Similar Projects

    Does this project spark your interest?

    Become a member to follow this project and never miss any updates