My Account

Wish List (0)

PiBorg is still open and we are still shipping orders.
We expect orders may be delayed by a day or two due to COVID-19.


Written by in Build, XLoBorg - Build on .

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:

  • ...Sample are the files that will be played for each movement
  • Interval is the time between updates
  • threshold...High is the G reading at which to fire the sound
  • threshold...Low is 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 ~/xloborg
chmod +x
and run using
cd ~/xloborg

#!/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
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)

    # 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'
        # Has Y been moved
        if y < thresholdYLow:
            highY = False
        elif y > thresholdYHigh:
            if not highY:
                highY = True
                print 'Y'
        # has Z been moved
        if z < thresholdZLow:
            highZ = False
        elif z > thresholdZHigh:
            if not highZ:
                highZ = True
                print 'Z'
        # Wait for the interval period
except KeyboardInterrupt:
    # CTRL+C exit, do nothing
Last update: Nov 05, 2017

Related Article


Leave a Comment

Leave a Reply

The product is currently Out-of-Stock. Enter your email address below and we will notify you as soon as the product is available.