Raspberry Pi Air Drum Kit

While perusing a local car boot sale, David Pride came across a Silverlit Air Drum Kit for the grand total of one whole shiny pound. And just like any digital maker, he bought it, realising the potential of this wondrous discovery.

David Pride Air Drum Kit

The original Silverlit Air Drum Kit

David had been recently fiddling with the Python CWiid library, a resource that allows you to use Wii controllers (Wiimotes) with a Raspberry Pi via Bluetooth. However, it was the setup of two controllers to a single Pi that was causing issues:

I’d only ever managed to get one controller working with a single Pi before, so the first challenge was to get a pair of controllers working as the ‘sticks’. That took a lot of mucking about, until I found the excellent post by WiiGate that detailed how to set up two controllers properly, using the MAC addresses. You can find it here.

Once this hurdle had been overcome, David collected a variety of open-source drum sample .wav files from the abundance of sound clips available on the web.

Did you honestly believe we’d get through this entire blog without a single cowbell reference?

David used Tkinter, writing a small app that would allow him to understand the positioning of the controllers, and as a result the data produced. Due to the nature of the controllers, movement wasn’t the only factor to consider. Speed and the way in which the controller was moved were also important. Move the controller quickly, and a different set of data is produced from that generated by a slower motion.

However, David isn’t one to give up and after a (relatively long) while, he had managed to plot positions for four distinct drum sounds:

I initially wanted to get three sounds on each controller, but the movement scale was a bit too tight to do it successfully every time, and two sounds often overlapped. So, I’m using the trigger button on each controller, combined with the movement for one of the sounds. This gives six different drum sounds, three per controller, that can be played without the sounds overlapping.

The final result of David’s tinkering is this wonderful air drum kit that provides a clean, impressive response with every movement. And because he’s such a lovely chap, all the code you need can be found at his GitHub page.

So David, all we need now is the air guitar, air bass and air keyboard, and we’ve got the start of this year’s Christmas Number One.

Band name suggestions welcome…


Andy avatar

Come and meet Dave and maybe his drum kit at this Saturday’s Cotswold Raspberry Jam, University of Gloucestershire, Park Campus, Cheltenham – cotswoldjam.org

Andrew Oakley avatar

See it in action, and if you ask nicely maybe have a go, at Cotswold Jam in Cheltenham on Saturday. A teeny number of free tickets still available (>100 already allocated!): http://www.cotswoldjam.org

Andrew Oakley avatar

Oh, and here’s your Raspberry Pi powered air guitar, or rather guitar bag: https://blog.adafruit.com/2016/09/16/zippy-is-a-guitar-bag-guitar-piday-raspberrypi-raspberry_pi/

Kevin Hainsworth avatar

Will this work with even more controllers ? I’m thinking of a Wii orchestra and even perhaps a bit of Command Line interfacing with Sonic-Pi. Is it likely that there would be timing issues on the Pi and if so might they be mitigated by using multi-threading ?

David Pride avatar

Bluetooth can natively support up to eight devices (I believe) Although I haven’t tested how many the cwiid library can support – that’s definitely something worth trying! Not sure re multi-threading, again something worth investigating.

I’ll try with 4 controllers and let you know how it goes :)



Kevin Hainsworth avatar

By my reckoning each Wiimote has 11 inputs plus the accelerometer. Here is a link to a Sonic-pi CLI https://github.com/Widdershin/sonic-pi-cli
Too much to look into before Saturday ?

David Pride avatar

Oh now that looks like a whole lot of fun. :)

Not going to have time to do anything before Saturday – but no reason why we can’t have a play on the day!

Fester Bestertester avatar

Not a programmer, but a musician: how ’bout Uillean Pipes? Oughta be possible :)

HAN avatar

so cool! up!

Aaron avatar

I’ve done something wrong. :(

Any thoughts on where?

Bluetooth pairing attempt 1
Socket connect error (control channel)
Error opening wiimote connection
Bluetooth pairing attempt 2
Socket connect error (control channel)
Error opening wiimote connection
Bluetooth pairing attempt 3
Socket connect error (control channel)
Error opening wiimote connection
Bluetooth pairing attempt 4
Socket connect error (control channel)
Error opening wiimote connection
Bluetooth pairing attempt 5
Socket connect error (control channel)
cannot create connection

ben avatar

You can pick up the balance boards in recycle centres for not a lot. (at least the local one to me up in yorkshire seems to).

So there’s the floor drums… or …

Ferdie avatar

Love it … made me go find my Wii remotes to give it a spin.

Lag was bad with aplay and the os call. I’m not a developer but a quick Google and pygame seems to be the way to go for better response.

import pygame
pygame.mixer.pre_init(44100, 16, 2, 4096)
Tom01 = pygame.mixer.Sound(‘Tom01.wav’)
kit1103 = pygame.mixer.Sound(‘kit1103.wav’)
CYMBL1 = pygame.mixer.Sound(‘CYMBL1.wav’)
kit252 = pygame.mixer.Sound(‘kit252.wav’)
Snare09 = pygame.mixer.Sound(‘Snare09.wav’)
Ride2 = pygame.mixer.Sound(‘Ride2.wav’)

then just where relevant a

Ride2.play() instead of the os.system line.

Now I can really smash it.

Later Ferdie

David Pride avatar

Aaron – it’s not detecting the wiimotes. What result do you get if you run the hcitool scan? This should give you the MAC addresses of both remotes, then enter these into the code where noted.

If they are not detected then probably either BT not installed correctly.

One other thing to watch – the cwiid library only works with original WiiMotes, not those with motion plus. Some clones work but this is a bit hit and miss (no pun intended!)

David Pride avatar

Ferdie – that’s a nice touch using PyGame :) Going to have to try that one!

Were you using Pi 2 or 3? – I used 3 and didn’t have any problems with lag.



AndrewS avatar

PyGame is also the approach used by DrumHAT

Ferdie avatar

David, it was on the Pi 3 .. the lag was not in the Wii remotes talking to the Pi, but rather getting audio device busy on some combinations strikes. I think what pygame allows is to play multiple sounds at the same time on the same channel.

So now with pygame one can play

Tom1 1.47480373052e+12
(130, 118, 103)
Snare1 1.47480373053e+12
(133, 112, 101)

at the “same” time.

Timestamp print via
import time
print “Tom1 ” + str(time.time()*1000.0)

As for the balance board – man had to go dig around to find one, have probably not seen it in 3-4 years. Once I got it out I looked at some cool Pi Wii projects

https://github.com/aelveborn/Wii-Scale and

A modify of Stavros Korokithakis’ Gr8W8Upd8M8.py script allowed me to confirm that one can listen for changes on the four corners of the balance board, and still be going at it with air drum – so 3 wii devices is not a problem.

rawTR = (int(bytes[0].encode(“hex”), 16) << 8) + int(bytes[1].encode("h$
rawBR = (int(bytes[2].encode("hex"), 16) << 8) + int(bytes[3].encode("h$
rawTL = (int(bytes[4].encode("hex"), 16) << 8) + int(bytes[5].encode("h$
rawBL = (int(bytes[6].encode("hex"), 16) << 8) + int(bytes[7].encode("h$

topLeft = self.calcMass(rawTL, TOP_LEFT)
print "Top Left" + str(topLeft)
topRight = self.calcMass(rawTR, TOP_RIGHT)
print "Top Rigth" + str(topRight)
bottomLeft = self.calcMass(rawBL, BOTTOM_LEFT)
print "Bottom Left" + str(bottomLeft)
bottomRight = self.calcMass(rawBR, BOTTOM_RIGHT)
print "Bottom Right" + str(bottomRight)

I suspect air drum has been some of the missing thinking in getting a WiiPi drum project going.

Later Ferdie

Phil Atkin avatar

Good grief you lot – just code it natively in C++ using ALSA. You’ll get 10x the throughput and 1/10 the latency.

CoderJoe avatar

Neat project. Two years ago when I got my Pi I attempted something like this as well. However I just used the nunchuck as the second “drum stick”. Much easier. I used the drum sounds from Sonic Pi. An interesting idea would be to use the ir camera in the wiimotes to detect position.

BTW if anyone figures out how to run Sonic Pi with python let me know! I would like to do something like this project to dynamically control Sonic Pi. Or, you know, make a midi controller like device.

RoundDuckMan avatar

Wow, a hack I can easily do, gotta find some Wii remotes…

Comments are closed