Posts | Comments

Planet Arduino

Archive for the ‘musical hacks’ Category

If you have an iota of musicality, you’ve no doubt noticed that you can play music using glass bottles, especially if you have several of different sizes and fill them with varying levels of water. But what if you wanted to accompany yourself on the bottles? Well, then you’d need to build a bottle-playing robot.

First, [Jens Maker Adventures] wrote a song and condensed it down to eight notes. With a whole lot of tinkling with a butter knife against their collection of wine and other bottles, [Jens] was able to figure out the lowest note for a given bottle by filing it with water, and the highest note by emptying it out.

With the bottle notes selected, the original plan was to strike the bottles with sticks. As it turned out, 9g servos weren’t up to the task, so he went with solenoids instead. Using Boxes.py, he was able to parameterize a just-right bottle holder to allow for arranging the bottles in a circle and striking them from the inside, all while hiding the Arduino and the solenoid driver board. Be sure to check it out after the break.

Don’t have a bunch of bottles lying around? You can use an Arduino to play the glasses.

Want to play the xylophone but don’t want to learn how? [Rachad]’s automatic xylophone might be just the ticket. It uses homemade solenoids to play tunes under computer control. Think of it as a player piano but with electromagnetic strikers instead of piano keys. You can hear the instrument in action in the video below.

Since the project required 24 solenoids, [Rachad] decided to build custom ones using coils of wire and nails. We were amused to see a common curling iron used as an alternate way to apply hot glue when building the coils. The other interesting part of the project was the software. He now uses a toolchain to convert MIDI files into a serial output read by the Arduino. Eventually, he wants to train an AI to read sheet music, but that’s down the road, apparently.

Honestly, we were a bit surprised that it sounded pretty good because we understand that the material used to strike the xylophone and the exact position of the strike makes a difference. We doubt any orchestra will be building one of these, but it doesn’t sound bad to us.

The last one of these we saw did have more conventional strikers if you want to compare. Honestly, we might have just bought the solenoids off the shelf but, then again, we don’t make our own relays either.

Jenny did an Ask Hackaday article earlier this month, all about the quest for a cheap computer-based audio mixer. The first attempt didn’t go so well, with a problem that many of us are familiar with: Linux applications really doesn’t like using multiple audio devices at the same time. Jenny ran into this issue, and didn’t come across a way to merge the soundcards in a single application.

I’ve fought this problem for a while, probably 10 years now. My first collision with this was an attempt to record a piano with three mics, using a couple different USB pre-amps. And of course, just like Jenny, I was quickly frustrated by the problem that my recording software would only see one interface at a time. The easy solution is to buy an interface with more channels. The Tascam US-4x4HR is a great four channel input/output audio interface, and the Behringer U-PHORIA line goes all the way up to eight mic pre-amps, expandable to 16 with a second DAC that can send audio over ADAT. But those are semi-pro interfaces, with price tags to match.

But what about Jenny’s idea, of cobbling multiple super cheap interfaces together? Well yes, that’s possible too. I’ll show you how, but first, let’s talk about how we’re going to control this software mixer monster. Yes, you can just use a mouse or keyboard, but the challenge was to build a mixing desk, and to me, that means physical faders and mute buttons. Now, there are pre-built solutions, with the Behringer X-touch being a popular solution. But again, we’re way above the price-point Jenny set for this problem. So, let’s do what we do best here at Hackaday, and build our own.

The Physical Goods

What we need is a microcontroller that has native USB client support, multiple digital I/O pins, and some analog inputs. I went with the Arduino MKRZero for the small size, decent price, and the fact that it’s actually in stock at Mouser. The other items we’ll need are some faders and buttons. I went for the full-sized 100 mm faders, and some LED toggle buttons made by Adafruit. The incidentals, like wire and resistors, was sourced from the local parts bin in the corner.

My first thought was to design and 3D print the panel, but after doing the layout on a scrap piece of plywood, the resulting size proved a bit too large for my printer. So we’re going retro, and making a “wood-grain” mixing desk. This would be a great project for a CNC router, but as I’m not part of that particular cool club yet, it was a drill press, table saw, and oscillating tool to the rescue. The results aren’t quite as pretty as I wanted, but maybe we’ll get a Mark II of this project one day.

The wiring is relatively straightforward, with a current limiting resistor to protect the LEDs inside the buttons, and a pullup resistor to prevent the digital pin from floating when the button isn’t pushed. Now, that pullup might not be necessary, as I later learned that the Arduino has built-in pullup on its digital pins. And also of note, a 10 Ω resistor is *not* a good choice for a pullup. As Al eloquently put it, that’s a “pull way up resistor”. 10 kΩ is the better choice.

And to finish the build, we’ll need a sketch to run on the Arduino. Thankfully, there’s already a great library for exactly what we want to do: Control Surface. There’s a bunch of ways to set this up, but my sketch is pretty trivial:

#include <Control_Surface.h>
USBMIDI_Interface midi;

CCButtonLatching button1 {11, {MIDI_CC::General_Purpose_Controller_1, CHANNEL_1}, };
CCButtonLatching button2 {10, {MIDI_CC::General_Purpose_Controller_2, CHANNEL_1}, };
CCButtonLatching button3 {9, {MIDI_CC::General_Purpose_Controller_3, CHANNEL_1}, };
CCButtonLatching button4 {8, {MIDI_CC::General_Purpose_Controller_4, CHANNEL_1}, };
CCButtonLatching button5 {7, {MIDI_CC::General_Purpose_Controller_5, CHANNEL_1}, };
CCButtonLatching button6 {6, {MIDI_CC::General_Purpose_Controller_6, CHANNEL_1}, };
  
CCPotentiometer volumePotentiometers[] {
  {A0, {MIDI_CC::Sound_Controller_1, CHANNEL_1} },
  {A1, {MIDI_CC::Sound_Controller_2, CHANNEL_1} },
  {A2, {MIDI_CC::Sound_Controller_3, CHANNEL_1} },
  {A3, {MIDI_CC::Sound_Controller_4, CHANNEL_1} },
  {A4, {MIDI_CC::Sound_Controller_5, CHANNEL_1} },
  {A5, {MIDI_CC::Sound_Controller_6, CHANNEL_1} },
};
void setup() {
    Control_Surface.begin();
}
void loop() {
    Control_Surface.loop();
}

Pipewire to the Rescue

And now on to the meat and potatoes of this project. How do we convince an application to see inputs from multiple devices, and actually do some mixing? The problem here is de-sync. Each device runs on a different clock source, and so the bitstream from each may wander and go out of sync. That’s a serious enough problem that older sound solutions didn’t implement much in the way of card combining. Not long ago, the process of resampling those audio streams to get them to properly sync would have been a very CPU intensive procedure. But these days we all have multi-core behemoths, practical super-computers compared to 20 years ago.

So when Wim Taymans wrote Pipewire, he took a different approach. We have enough cycles to resample, so Pipewire will transparently do so when needed. Pipewire sees all your audio interfaces at once, and implements both the Jack and Pulseaudio APIs. Different distros handle this a bit differently, but generally you need the Pipewire packages, as well as the pipewire-jack and pipewire-pulseaudio packages to get that working.

And here’s the secret: The Jack routing tools work with Pipewire. The big three options are qjackctl, carla, and qpwgraph, though note that qpwgraph is actually Pipewire native. So even if an application can only select a single device at a time, if that app uses the Jack, Pulseaudio, or Pipewire API, you can use one of those routing control programs to arbitrary connect inputs and outputs.

So let’s start with the simplest solution: jack_mixer. Launch the application, and then using your preferred routing controllers, take the MIDI output from our Arduino control surface, and connect it into jack_mixer‘s MIDI input. In jack_mixer, add a new input channel, and give it an appropriate name. Let’s call it “tape deck”, since I have a USB tape deck I’m testing this with. Now the controller magic kicks in: hit the “learn” button for the volume control, and wiggle the first fader on that controller. Then follow with the mute button, and save the new channel. We’ll want to add an output channel, too. Feel free to assign one of your faders to this one, too.

And finally, back to the routing program, and connect your tape deck’s output to jack_mixer input, and route jack_mixer‘s output to your speakers. Play a tape, and enjoy the full control you have over volume and muting! Want to add a Youtube video to the mix? Start the video playing, and just use the routing controller to disconnect it from your speakers, and feed it into a second channel on jack_mixer. Repeat with each of those five cheap and nasty sound cards. Profit!

You Want More?

There’s one more application to mention here. Instead of using jack_mixer, we can use Ardour to do the heavy lifting. To set it up this way, there are two primary Ardour settings, found under preferences: Under the monitoring tab make sure “Record monitoring handled by” is set to Ardour, and the “auto Input does talkback” option is checked. Then add your tracks, set the track input to the appropriate input hardware, and the track output to the master bus. Make sure the master bus is routed to where you want it, and you should be able to live mix with Ardour, too.

This gives you all sorts of goodies to play with, in the form of plugins. Want a compressor or EQ on a sound source? No problem. Want to autotune a source? X42 has a plugin that does that. And of course, Ardour brings recording, looping, and all sorts of other options to the party.

Ardour supports our custom mixing interface, too. Also under preferences, look for the Control Surfaces tab, and make sure General MIDI is checked. Then highlight that and click the “Show Protocol Settings” button. Incoming MIDI should be set to our Arduino device. You can then use the Ctrl + Middle Click shortcut on the channel faders and mute buttons, to put them in learn mode. Wiggle a control to assign it to that task. Or alternatively you can add a .map file to Ardour’s midi_maps directory. Mine looks like this:

 
  <?xml version="1.0" encoding="UTF-8"?>
<ArdourMIDIBindings version="1.1.0" name="Arduino Mapping">
  <Binding channel="1" ctl="16" uri="/route/mute B1"/>
  <Binding channel="1" ctl="70" uri="/route/gain B1"/>
  <Binding channel="1" ctl="17" uri="/route/mute B2"/>
  <Binding channel="1" ctl="71" uri="/route/gain B2"/>
  <Binding channel="1" ctl="18" uri="/route/mute B3"/>
  <Binding channel="1" ctl="72" uri="/route/gain B3"/>
  <Binding channel="1" ctl="19" uri="/route/mute B4"/>
  <Binding channel="1" ctl="73" uri="/route/gain B4"/>
  <Binding channel="1" ctl="80" uri="/route/mute B5"/>
  <Binding channel="1" ctl="74" uri="/route/gain B5"/>
  <Binding channel="1" ctl="81" uri="/route/mute B6"/>
  <Binding channel="1" ctl="75" uri="/route/gain B6"/>
</ArdourMIDIBindings>

The Caveats

Now before you get too excited, and go sink a bunch of money and/or time into a Linux audio setup, there are some things you should know. First is latency. It’s really challenging to get a Pipewire system set up to achieve really low latency, particularly when you’re using USB-based hardware. It’s possible, and work is ongoing on the topic. But so far the best I’ve managed to run stable is a 22 millisecond round-trip measurement — and that took a lot of fiddling with the Pipewire config files to avoid garbled audio. That’s just about usable for self monitoring and live music, and for playing anything pre-recorded, that’s perfectly fine.

The second thing to know is that this was awesome. It’s a bit concerning how much fun it is to combine some decent audio hardware with the amazing free tools that are available. Want to auto-tune your voice for your next Zoom meeting? Easy. Build a tiny MIDI keyboard into your desk? Just a microcontroller and some soldering away. The sky’s the limit. And the future is bright, too. Tools like Pipewire and Ardour are under very active development, and the realtime kernel patches are just about to make it over the finish line. Go nuts, create cool stuff, and then be sure to tell us about it!

There comes a point in every Arduino’s life where, if it’s lucky, it becomes a permanent fixture in a project. We can’t think of too many better forever homes for an Arduino than inside of a 3D-printed synthesizer such as this 17-key number by [ignargomez] et al.

While there are myriad ways to synthesizer, this one uses the tried-and-true method of FM synthesis courtesy of an Arduino Nano R3. In addition to the 17 keys, there are eight potentiometers here — four are used for FM synthesis control, and the other four are dedicated to attack/delay/sustain/release (ADSR) control of the sound envelope.

One of the interesting things here is that [ignargomez] and their team were short a few regular pots and modified a couple of slide pots for circular use — we wish there was more information on that. As a result, the 3D printed enclosure underwent several iterations. Be sure to check out the brief demo after the break.

Don’t have any spare Arduinos? The BBC Micro:bit likes to make noise, too.

Arduino Lo-Fi Orchestra closeup thumbnail

Hardware projects often fall into three categories: Those that flash lights, those that make sounds and those that move. This virtuoso performance by [Kevin]’s “Lo-Fi Orchestra” manages all three, whilst doing an excellent job of reproducing the 1973 musical classic Tubular Bells by Mike Oldfield.

Producing decent polyphonic sounds of different timbres simultaneously is a challenge for simple microcontroller boards like Arduinos, so [Kevin] has embraced the “More is more” philosophy and split up the job of sound generation in much the same way as a traditional orchestra might. Altogether, 11 Arduino Nanos, 6 Arduino Unos, an Arduino Pro Mini, an Adafruit Feather 32u4, and a Raspberry Pi running MT32-Pi make up this electronic ensemble.

Arduino servo drumkit
Arduino Servo & Relay Drumkit

The servo & relay drumkit is a particular highlight, providing some physical sounds to go along with the otherwise solid-state generation.

The whole project is “conducted” over MIDI and the flashing sequencer in the middle gives a visual indication of the music that is almost hypnotic. The performance is split into two videos (after the break), and will be familiar to fans of 70’s music and classic horror movies alike. We’re astonished how accurately [Kevin] has captured the mood of the original recording.

If this all looks slightly familiar, it may be because we have covered the Lo-Fi Orchestra before, when it entertained us with a rousing rendition of Gustav Holst’s Planets Suite. If you’re more interested in real Tubular Bells than synthesized ones, then check out this MIDI-controlled set from 2013.

[poprhythm]’s Touch Tone MIDI Phone is a fantastic conversion of an old touch tone phone into a MIDI instrument complete with intact microphone, but this project isn’t just about showing off the result. [poprhythm] details everything about how he interfaced to the keypad, how he used that with an Arduino to create a working MIDI interface, and exactly how he decided — musically speaking — what each button should do. The LEDs on the phone are even repurposed to blink happily depending on what is going on, which is a nice touch.

Of course, it doesn’t end there. [poprhythm] also makes use of the microphone in the phone’s handset. Since the phone is now a MIDI instrument with both a microphone and note inputs, it’s possible to use them together as the inputs to vocoder software, which he demonstrates by covering Around the World by Daft Punk (video).

We love how [poprhythm] explains how he interfaced to everything because hardware work is all about such details, and finding the right resources. Here’s the GitHub repository for the Arduino code and a few links to other resources.

We have seen MIDI phone projects before, and each one is always unique in its own way: here’s a different approach to converting a keypad phone to MIDI, and this rotary pulse-dial phone went in a completely different direction with the phone itself completely unmodified, using only external interfacing.

You can admire [poprhythm]’s Touch Tone MIDI Phone in action in the short videos embedded below, with each one showing off a different aspect of the build. It’s great work!

Drums are an exciting instrument to learn to play, but often prohibitive if there are housemates or close neighbors involved. For that problem there are still electronic drums which can be played much more quietly, but then the problem becomes one of price. To solve at least part of that one, [Jeremy] turned to using an Arduino to build a drum module on his own, but he still had to solve yet a third problem: how to make the Arduino fast enough for the drums to sound natural.

Playing music in real life requires precise timing, so the choice of C++ as a language poses some problems as it’s not typically as fast as lower-level languages. It is much easier to work with though, and [Jeremy] explains this in great detail over a series of blog posts detailing his drum kit’s design. Some of the solutions to the software timing are made up for with the hardware on the specific Arduino he chose to use, including an even system, a speedy EEPROM, hardware timers, and an ADC that can sample at 150k samples per second.

With that being said, the hardware isn’t the only thing standing out on this build. [Jeremy] has released the source code on his GitHub page for those curious about the build, and is planning on releasing several more blog posts about the drum kit build in the near future as well. This isn’t the only path to electronic drums, though, as we’ve seen with this build which converts an analog drumset into a digital one.

[Kevin] has long wanted to do something musical with a vintage rotary phone and an Arduino, and has finally done so and committed the first of several experiments to HTML in a five-part series. He found a nice old British Telecom number, but it had been converted to plug and socket wiring to work on the modern system. Because of this, [Kevin] wanted to keep it completely functional as a phone. After all, it ought to work fine until 2025, when pulse dialing will no longer be supported in [Kevin]’s locality.

As you can likely understand, [Kevin] was keen to interface with the phone from the outside and leave the inside untouched. He used a sacrificial ADSL filter’s PCB to break out the socket, and added a pull-up resistor between the pin and 5 V.

Pretty quickly, [Kevin] figured out that when the phone is on the hook, it gives a constant high signal, where as the picking up the phone presents as a high signal going low, and dialing each number results in pulses of that quantity that alternate between high and low.

In part two of the series, [Kevin] really gets into decoding the pulse dialing, which is necessary for the third installment when things get musical. Here, [Kevin] adds in a MIDI module and a Roland MT-32 synth to use the dial as a MIDI note generator — each note dialed will sustain until the receiver is replaced on the hook.

Part four focuses on a MIDI patch changer. [Kevin] picks up the phone, dials a code up to three digits long, and hangs up, which this triggers the synth to change to the assigned voice. In part five, the phone becomes a random note sequencer, and each successive spin of the same digit will produce a different, randomly-chosen note. This is really just the beginning, however, so we’ll be checking back for updates. In the meantime, you can listen to the note generator and the random note sequencer demos after the break.

Wouldn’t you like to use a rotary dial all the time? Well, as long as it wasn’t an emergency?

A portable Bluetooth turntable.

You know, we were just discussing weird and/or obsolete audio formats in the writers’ dungeon the other day. (By the way, have you ever bought anything on DAT or MiniDisc?) While vinyl is hardly weird or (nowadays) obsolete, the fact that this Bluetooth record player by [JGJMatt] is so modern makes it all the more fantastic.

Not since the Audio-Technica Sound Burger, or Crosley’s semi-recent imitation, have we seen such a portable unit. But that’s not even the most notable part — this thing runs inversely to normal record players. Translation: the record stands still while the the player spins, and it sends the audio over Bluetooth to headphones or a speaker.

Inside this portable player is an Arduino Nano driving a 5 VDC motor with a worm gear box. There really isn’t too much more to this build — mostly power, a needle cartridge, and a Bluetooth audio transmitter. There’s a TTP223 touch module on the lid that allows [JGJMatt] to turn it off with the wave of a hand.

[JGJMatt] says this is a prototype/work-in-progress, and welcomes input from the community. Right now the drive system is good and the Bluetooth is stable and able, but the tone arm has some room for improvement — in tests, it only played a small section of the record and skidded and skittered across the innermost and outermost parts. Now, [JGJMatt] is trying two-part arm approach where the first bit extends and locks into position, and then a second arm extending from there and moves around freely.

Commercial record players can do more than just play records. If you’ve got an old one that isn’t even good enough for a thrift store copy of a Starship record, you could turn it into a pottery wheel or a guitar tremolo.

Have you ever been on a city street and seen a busker playing music on glasses? Each glass has a different amount of water and produces a different note when tapped. [Cyberlab] must have seen them and created an Arduino robot to play tunes on glasses. You can see the result in the video below.

If we had done this, we might have had a solenoid per glass or used some linear component like a 3D printer axis to pick different glasses. [Cyberlab] did something smarter. The glasses go in a circle and a stepper motor points at the correct glass and activates a solenoid. The result is pretty good and it is a lot simpler than any of our ideas.

If you aren’t musically inclined, you might wonder how you’d program the songs. There’s an example of taking a music box score from a website — apparently, there are lots of these — and removing any polyphony from it. The site mentioned even has an editor where you can import MIDI files and work with them to produce a music box strip that you could then convert. Then you encode each note as a number from 0 to 6.

Of course, you also have to fill your glasses with the right amount of water. A piano tuning phone app should be useful. We’ve seen this done in a linear fashion before. You can even use a single glass for many notes with a little ingenuity.



  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook