Saxophone Light

by k31tht in Circuits > Raspberry Pi

1266 Views, 15 Favorites, 0 Comments

Saxophone Light

Sax_Light.jpg
Sax_light 2 - May 22.jpg
Sax_light 4 - May 22.jpg

A friend who pays saxophone in a band had someone design a light for his saxophone to illuminate it based on the note he was playing. It’s a great piece of electronics, but crucially was expensive, chewed through batteries (he has to replace them in the interval), was bulky, meaning that he has to physically wear the electronics, and was expensive to modify as it is based on complex circuitry with quite a few PCBs. I thought I could come up with a new software-based design that overcame all the problems that were bugging him. I also wanted it to be low-cost. The Raspberry Pi Zero is a great low cost board that had the ability to process sound to derive the notes being played and could also drive LEDs. I chose neopixels as they are easy to control from the Pi Zero and are plenty bright enough.

Downloads

Supplies

Supplies:

  • Raspberry Pi Zero (I used a Pi Zero 2W) - https://www.raspberrypi.com/products/raspberry-pi-zero/
  • USB microphone - USB Mini Recording Microphone, 360° Omnidirectional Portable Studio Speech Audio MIC Adapter Suitable for Web Chat, Network Video Conferencing, Network Recording(BLACK) from Amazon
  • Neopixel ring (WS2812) (16 LEDs) - Cool Components 16 LED 72mm Ring - WS2812B 5050 RGB LED with Integrated Drivers from Amazon
  • Gutter guard (plastic) - Merriway BH03114 (2 Pcs) Gutter Balloon Outlet Guard, Black To Fit 68mm Pipe from Amazon
  • Cables:
  • microsusb cable from Pi Zero to battery pack
  • microusb cable from Pi Zero to USB microphone
  • Press button switch (to shut down Pi Zero safely)
  • Rechargeable power bank (e.g. Trust 22821 4000mAh)
  • Bracket to mount Pi Zero - modified blanking plate from old PC
  • Screws to attach bracket to gutter guard and Pi Zero to bracket
  • Wire
  • Solder
  • Foam for the outside of the gutter guard to protect the saxophone bell

Hardware Design

Prototype_sax_light.png
Sax_light 3 - May 22.jpg

The saxophone bell has plenty of space to house the Pi Zero, the microphone and the LEDs. It can also accommodate the power bank though I decided to mount it on the side of the saxophone just in case it distorted the sound.

The first step is to design the mounting. I chose the gutter guard as I had one lying around and it was the right size. It could be 3D printed of course which would enable the mounting for the Pi Zero to be built in (as well as a power bank mounting); that will be a future development.

The mounting has to be removable and must not damage the saxophone so I chose some foam and used double sided tape to attach it.

I chose a Raspberry Pi Zero 2W as it is low cost, easy to program, is powerful enough to measure the saxophone notes in real time and works well with neopixels. At the time it was difficult to source Raspberry Pi boards and I had one to spare. I also experimented with a Pi 3B as well as a Pi Pico but settled on the Pi Zero.

The microphone choice resulted in a lot of experimentation using different microphones. In the end the cheap USB microphone proved more than adequate. As well as being cheap compared with other options it was small, sufficiently accurate, provided signals that could be used to deduce tone and volume and had a usb connection which was ideal for the Pi Zero.

The Pi Zero needs to securely attached inside the mounting and I used an old PCB blanking plate from a PC which I cut to size. This is attached by screws to the mounting.

Finally, the neopixel ring needs to be attached. The 16 LED ring is a perfect size though it would be easy to use a different number of LEDs. I chose 16 because they produced enough light, were the right size to fit in the saxophone bell and had a power consumption that could easily be met by a small power bank for a whole gig (up to 3 hours). The neopixel ring is attached by wire to the mounting.

The powerbank that is used is a flat one that is attached with Velcro to the outside of the saxophone. An alternative solution would be a cylindrical powerbank that could fit inside the bell of the saxophone. This would be a neater solution. A 4000mAh was tested and was capable of powering the saxophone light for non-stop for 3 hours.

Software Design

Sound measurement. The first step is to measure the sound from the saxophone. I decided to use MIDI tones as these discrete notes could be used to produce specific, individual colours for each tone. Using a recording from the saxophone the range of MIDI tones was established (47 to 74 inclusive).

After a lot of experimentation I settled on PyAudio (https://pypi.org/project/PyAudio/) to interface with the microphone and capture the audio stream and aubio (https://aubio.org/) to derive the tones (and volume). I sued NumPy to convert the output from PyAudio into aubio. The measurements were restricted to the tones produced by the saxophone (to prevent tones from other instruments in the band triggering the sax light) and a suitable threshold so that other external noises did not trigger the LEDs.

Sound processing. The sound is converted into midi tones and volume.

The maximum volume is constantly measured to allow the brightness of the LEDs to be controlled. The volume signal is reduced over time to progressively dim the LEDs as can be seen in the video. The output is also stopped after a pre-set number of (10) cycles. This makes the output a lot more attractive and less flashy/jumpy.

The LED colour needed to be discrete for each tone with a suitable progression from note to note. I used a RGB colour wheel with the introduction of white for the highest tone. I originally defined the colours directly as RGB but this was messy so I used HSL (hue, saturation and lightness) where hue is set by midi then converted to RGB (using colorsys).

LED control. I used neopixel to control the LEDs. This allowed colour and brightness to be changed based on the sound from the saxophone. The brightness fades after each cycle until a new note is detected. If the signal stops the LEDs fade rather than stopping immediately. I also added a startup and shutdown sequence so that the user can see that the sax light is operational or shutting down.

Shutdown. The Pi Zero does not have an off switch to close it down safely and obviously just detaching the power is not a good solution (as it can damage the Pi Zero SD card). I used a simple push button installed on the bottom of the gutter guard to allow the saxophone light to be shutdown (using subprocess).

Optimisation. As well as the experimentation required to find appropriate software (and hardware) solutions the various settings required optimisation to ensure that the saxophone light performed well. This included setting the volume threshold, sampling rate, buffer size, tolerance (associated with the accuracy of tone measurement), saturation & lightness as well as the dimming rate and cut-off.

Python. All software is written python as it provided or enabled all the necessary modules and tools.

Downloads

Testing

Sax Light Colour Analysis.jpg
Demo photo.jpg

Testing took place during the design and build using sample music recorded from the target saxophone. This was used to validate the hardware design and enabled various components such as processors, microphones and LEDs to be discounted. The testing using saxophone recordings also allowed the software design to be iterated. A prototype with all the hardware components on a breadboard and an early software version were tested using an actual saxophone. This provided the proof of concept for the overall design and allowed the hardware to be finalised and further software iterations to be completed. The final version was then fully tested in the saxophone; only minor adjustments to some of the settings was required at this stage. The saxophone light is now being used in anger in sessions and gigs with extremely positive feedback..