Skip to main content

OpenDrum - the Open-Source Drumless

OpenDrum is the open-source version of Drumless - an award-winning air-drumming system. It is built around an Arduino Nano 33 BLE (Sense).

Parts list

Qty Product Part number
1 Arduino, Nano 33 BLE Module 192-7587
1 Arduino, Nano 33 BLE Sense Module with headers 192-7592
1 Arduino, Nano 33 BLE Module with headers 192-7591
1 Arduino, Nano 33 BLE Sense Module 192-7588

Introduction

A few months ago, I posted a Student Innovation article about my air-drumming project - Drumless. The article became relatively popular, and a few of you mentioned that you would like to get your hands on a pair of the Drumless sticks. I have always considered making the project open-source, but the custom-built PCB with tiny components, the expensive SEGGER J-Link debugger and Tag-Connect programming cable, and the hassle of setting up the nRF5 SDK, SEGGER’s Embedded Studio and some proprietary sensor-fusion libraries by InvenSense all result into a pretty high barrier to entry for anyone interested. That is why I decided to break down the project into independent, fully open-source components, that can be easily reproduced, starting with my Single Button User Interface article. In this follow-up article, I am releasing the source code for OpenDrum - the open-source Drumless - which can run on an off-the-shelf Arduino Nano 33 BLE Sense (192-7588) or Arduino Nano 33 BLE (192-7587) .

Technical Implementation

The goal of OpenDrum is to reduce the number of dependencies and setup steps required to get started with using the product. As a result, the sensor fusion algorithm, the real-time operating system (RTOS), and Bluetooth Low Energy (BLE) code had to all be rewritten.

Sensor Fusion

As described in the initial article, sensor fusion is the process in which the drumstick orientation is obtained from the raw accelerometer, gyroscope and magnetometer data. Drumless uses a proprietary library by InvenSense. By comparison, OpenDrum uses an open-source sensor fusion algorithm, developed by Sebastian Madgwick.

The new open-source library is much lighter and faster than the original and performs just as well in this particular application. However, it is missing some non-essential, but nice-to-have features. For example, the InvenSense library would calibrate the magnetometer and the gyroscope behind the scenes, without any user input. Furthermore, it would reject the magnetometer readings if they are considered "unreliable".

With regards to gyroscope calibration, the OpenDrum project currently has a separate piece of firmware, which needs to be executed during the setup of a new Arduino. The firmware outputs a vector of calibration values, which are then overwritten in the OpenDrum source code. The magnetometer readings, however, are currently not used at all, since they can degrade the quality of the sensor fusion if not calibrated well. Since OpenDrum is now open-source, anyone interested is welcome to contribute and fill these gaps! Let me know in the comments if you need guidance with that!

RTOS

Drumless uses FreeRTOS, an open-source real-time operating system for microcontrollers. Although this matches the criteria of being open-source, easy to use, and powerful, it requires extra work to set up. The MBED RTOS, however, comes with Arduino. As a result, it was used in OpenDrum.

But why exactly is an RTOS needed? Let's imagine that we wanted to do two things in our code - read sensor data and fuse this data to obtain orientation. Let's say that the sensor data had to be read every 2 ms and that the data had to be fused every 5 ms, but reading the data took 1 ms and fusing the data took 3 ms. If we took the naive approach shown below and did everything sequentially in a loop, the highest rate at which the sensor data would be read is every 4 ms (1 ms to read the data plus 3 ms to fuse it), which doesn't meet the specification.

An RTOS allows you to run multiple tasks (such as reading data, and sensor fusion) in parallel, without creating such bottlenecks. In fact, OpenDrum runs four main tasks in parallel to provide air-drumming functionality (see figure 1). In essence, the Sensor Task reads data from the sensors. The Fusion Task takes these sensor readings and fuses them into Euler angles, which represent the orientation of the drumstick. The Detection Task uses the raw sensor data and the Euler angles to detect a drum strike. Lastly, the BLE Task takes the detected strikes, represented as a note and velocity (see MIDI), and sends a signal to a connected device, such as a mobile phone, to play the sound.

block diagram of the RTOS tasks

Figure 1. A block diagram of the RTOS tasks, their frequencies and communication details.

BLE

Drumless used the nRF5 SDK to establish a BLE connection with a mobile device. The code for that spans across several files and hundreds of lines of code. Arduino has a BLE MIDI library, written by GitHub user lathoub, which allows us to create the same functionality in just a couple of lines of code.

Getting Started with OpenDrum

Enough talking, how do I get OpenDrum? I'm glad you asked. OpenDrum was written using PlatformIO. PlatformIO was preferred to Arduino since it offers much better organisation of the code base, and a much better IDE (such as VS Code) can be used, which allows for nice features such as code completion, Git integration, formatting and more! So, to get OpenDrum simply install PlatformIO from here, clone OpenDrum from here and flash to your Arduino.

Conclusion

This article attempts to make Drumless easily accessible to everyone. While making the original Drumless requires custom PCB making, expensive hardware and complex software setup, OpenDrum can be flashed onto an off-the-shelf Arduino with the click of a button.

This is my third Drumless-related article. Stay tuned in the coming months, since I have planned a follow-up article on OpenDrum, which will include a 3D-printable drumstick and an optional PCB for some extra functionality.

Downloads

I have a BEng in Electrical & Electronic Engineering and an MSc in Artificial Intelligence. I like to combine knowledge from both fields in my work. In short, I make computers walk, talk, hear, see and understand.
DesignSpark Electrical Logolinkedin