XLoDrum - Turn your Raspberry Pi into a drum kit
Want to do something fun with your Raspberry Pi?
Why not use an XLoBorg to turn it into a drum kit!

XLoDrum takes the data from an XLoBorg and uses X, Y, and Z movements to represent different drum noises
There are some options you can configure from lines 9 to 18:
Here's the code, you can download the XLoDrum script file as text here
Since we also have sound files the full package is here
The samples were downloaded from Music Radar
To download it directly to the Raspberry Pi use
and run using
Why not use an XLoBorg to turn it into a drum kit!

XLoDrum takes the data from an XLoBorg and uses X, Y, and Z movements to represent different drum noises
There are some options you can configure from lines 9 to 18:
...Sampleare the files that will be played for each movementIntervalis the time between updatesthreshold...Highis the G reading at which to fire the soundthreshold...Lowis the G reading at which to reset ready for another movement
Here's the code, you can download the XLoDrum script file as text here
Since we also have sound files the full package is here
The samples were downloaded from Music Radar
To download it directly to the Raspberry Pi use
cd ~/xloborgwget http://piborg.org/downloads/XLoDrum.zipunzip XLoDrum.zipchmod +x XLoDrum.pyand run using
cd ~/xloborg./XLoDrum.py
#!/usr/bin/env python
# coding: Latin-1
# Load library functions we want
import XLoBorg
import time
import os
# Settings for the drum playing
xSample = 'drum-x.wav' # File to play for X movements
ySample = 'drum-y.wav' # File to play for Y movements
zSample = 'drum-z.wav' # File to play for Z movements
interval = 0.1 # Interval to check for movements
thresholdXHigh = 0.6 # G required to set a movement X
thresholdXLow = 0.1 # G maximum to clear a movement X
thresholdYHigh = 0.5 # G required to set a movement Y
thresholdYLow = 0.1 # G maximum to clear a movement Y
thresholdZHigh = 1.7 # G required to set a movement Z
thresholdZLow = 1.1 # G maximum to clear a movement Z
# Setup XLoBorg, states
XLoBorg.Init()
highX = False
highY = False
highZ = False
# Function used to play a sound file
def PlaySound(filename):
# Build a command and run it
command = 'bash -c "aplay %s &> /dev/null &"' % (filename)
os.system(command)
try:
# Loop indefinitely
while True:
# Read the accelerometer
x, y, z = XLoBorg.ReadAccelerometer()
# Has X been moved
if x < thresholdXLow:
highX = False
elif x > thresholdXHigh:
if not highX:
highX = True
print 'X'
PlaySound(xSample)
# Has Y been moved
if y < thresholdYLow:
highY = False
elif y > thresholdYHigh:
if not highY:
highY = True
print 'Y'
PlaySound(ySample)
# has Z been moved
if z < thresholdZLow:
highZ = False
elif z > thresholdZHigh:
if not highZ:
highZ = True
print 'Z'
PlaySound(zSample)
# Wait for the interval period
time.sleep(interval)
except KeyboardInterrupt:
# CTRL+C exit, do nothing
pass

