chipKIT: TouchClamp click drum machine

Teodor Costachioiu
Jul 27, 2016 · 4 min read

In this project, I will use the VS1053-based MP3 Click as a drum machine, with the TouchClamp Click as an input device, and some jars acting as drum pads. One chipKIT UNO32 is used to control the whole musical instrument, the software being written in Arduino IDE. The required chipKIT core was installed via the boards manager.

This article is more than two years old and might contain obsolete information; it is still kept here for informational purposes.

Initially, I wanted to use the Flip & Click board, but I had to change my mind: even in version 1.6.9 of Arduino IDE the I2C library for SAM processors is flawed, and there’s no way to issue a repeated start command. As the Flip & Click is inspired by the Arduino Due, it looks there’s little chance to see a fixed I2C library soon. I think the only way is to take some time and fix it myself…

Anyway, this leaves me with little options. I need an Arduino or Arduino compatible board that works with 3.3V as both the TouchClamp and the MP3 click boards are 3.3V devices. That board should also be compatible with the Arduino Uno Click shield that I plan to use. The final choice went to the chipKIT UNO32, which was already in my inventory. I know that this little board was replaced by the chipKIT uC32 — no big deal, just use whichever board you have.

If you don’t like the chipKIT range, another good candidate for this project is the 3.3V version of the Arduino Pro 328. All you have to do is to adjust the SPI clock divider accordingly. For your information, the Sparkfun part no. is DEV-10914.

So, here’s what I used: chipKIT UNO32, Arduino Uno click shield, MP3 click and TouchClamp click:

The pin definition used in the software below requires the TouchClamp to be placed in the first socket, with the MP3 click the second socket.

Connections to the jars or “drum pads” are made using some wires with crocodile clips on both ends. No soldering necessary. The TouchClamp click offers seven plated holes for clamps, with an eighth button right on the click board. As such it allows for a small drum arrangement. I went for a typical rock setup, with a bass drum, a snare drum, low-, mid- and high-tom and two cymbals.

In the picture above the glass bottles act as cymbals and the compressed air can in the front is the bass drum. The black can is the snare drum, the yellow one is the floor tom. The two blue cans on the last row are the mid- and high tom drums.

Normally the bass drum and the hi-hat cymbal are played using footswitches. Unfortunately, I had none of those, so everything here is played by hand only. But I leave this option open, it’s extremely easy to change the code if you add the missing footswitches.

That’s all for the hardware side…

Touch clamp drum machine: the software

And now we come to the fun part: the software.

For the TouchClamp click I used the MPR121 library from Adafruit, with a small change: the Adafruit_MPR121.cpp file.

/***************************************************************/ /*! @brief Writes 8-bits to the specified destination register */ /***************************************************************/
void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
Wire.beginTransmission(_i2caddr);
Wire.write((uint8_t)reg);
Wire.write((uint8_t)(value));
Wire.endTransmission();
}

has to be changed to:

/***************************************************************/ /*! @brief Writes 8-bits to the specified destination register */ /***************************************************************/
void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
Wire.beginTransmission(_i2caddr);
Wire.write((uint8_t)reg);
Wire.write((uint8_t)(value));
Wire.endTransmission(true);
}

Without this little change, there’s no stop condition sent after writing data to the MPR121.

The MP3 code for real-time MIDI is based on the MP3_Shield_RealtimeMIDI.ino. It’s the same code I used as a source of inspiration when I created the Flip & Click Theremin, and I know it works fine.

There are several particularities in the way percussion instruments work in VS1053. First, the instrument bank is 0x78. One must select an instrument, no matter which one. There are no notes, each note code corresponds to a percussion instrument — a list of percussion MIDI codes can be found on http://soundprogramming.net/file-formats/general-midi-drum-note-numbers/. So, to hit the bass drum one must play note code 36. The snare drum is 38. Low tom is 43, mid tom is 47 and high tom is 50. The ride cymbal is 51, and the pedal hi-hat is 44. The open Hi-hat is not implemented. I have mapped it to the H button on the TouchClamp click but is very hard to play it this way.

With the above considerations, the code is:

Originally published at https://electronza.com on July 27, 2016.

Electronza

DIY electronics projects and more

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store