HackerBoxes 0007: Digital Soundscapes

by HackerBoxes in Circuits > Electronics

11230 Views, 43 Favorites, 0 Comments

HackerBoxes 0007: Digital Soundscapes

WholeBoxSk00l.png

Soundscape! This month, HackerBox Hackers are exploring digital soundscapes. Music, beeps, buzzes, and audio signals of all sorts may be generated by a variety of modern electronic devices. Let's have a look at simple 8bit sounds "bit banged" from a microcontroller, right through the more complex solutions for storing, encoding, compressing, and analyzing audio signals.

This Instructable contains information for working with HackerBoxes #0007. HackerBoxes is the monthly subscription box service for electronics hobbyists, makers, and hackers. Even if you are not a HackerBoxes subscriber, you can always join in the fun using your own materials and equipment. Of course, if you would like to receive a box like this right to your mailbox each month, please SUBSCRIBE HERE and join the HackerBoxes movement. Hack the Planet!

HackerBoxes #0007: Box Contents

WholeBoxMarketing.png
HackerBoxes #0007 - (Un)Boxing Video
  • HackerBox #0007 Collectible Reference Card
  • Arduino MP3 and Music Shield
    • VLSI VS1053B CODEC Chip (MP3/AAC/WMA/MIDI)
    • TF Card Slot
    • Microphone
  • RobotDynUNO - Arduino UNO Compatible
  • Solder Kit: VU Meter (Audio Level Indicator)
  • MP3 Player Board with card reader and speaker driver
  • Digital-to-Analog Converter Module (MCP4725)
  • Audio Power Amplifier Module (LM386)
  • 8GB MicroSD Card
  • USB adapter for MicroSD Card
  • 9v Battery Clip
  • DuPont Male-Female Jumper Wires
  • Two 3.5mm audio cables
  • Speaker (8ohm, 0.5W)
  • Piezo Buzzer
  • 1K resistors
  • 330nF Capacitor
  • Exclusive HackerBoxes Soundscape "Poetry" Magnets

RobotDyn UNO CH340G/ATmega328P

RobotDyn UNO.jpg

Veteran Arduino hacker? Feel free to skip this step.

We use these UNO style microcontroller boards for everything. They are readily available, and of course they have countless tools, libraries, and tutorials available online. This RobotDyn design was new for 2016. We love it. It features an SMD-version of the ATmega328P, a CH340G serial-to-USB interface chip, and of course the Arduino bootloader for use with the Arduino IDE. We especially love the microUSB cable interface. This is the same cable that is used for almost all Android phones and tablets. You probably have one already, but they are very readily available and inexpensive.

All of these newer boards use the CH340/CH341 serial-to-USB interface. The drivers for these are quite common by now, but you may still need to install the driver on your computer to allow the Arduino IDE to communicate to these boards. There are drivers for the CH340/CH341 serial-to-USB interface chip available for OS X, Windows, and Linux. Here is a video on the topic.

If you haven't used an Arduino before, you can find a lot of tutorials online. To get started, install the IDE on your computer (just search the web for Arduino IDE and your OS type). Hook the UNO up to your computer using a microUSB cable, and then load the "blink" sketch from under the examples menu. You don't even need to hook up an LED (although you can if you like) since there is one on the board already. Once the blink program works, you can change the values of the delay() calls from 1000 to 100 and see that the LED blinks much faster. You have just hacked your first code. It's just that easy. If you'd like a little more step-by-step detail on this process, here is a very nice reference: blink.

Making Simple Tones - Bit Banging

ArduinoBuzzer.jpg
square wave.png

The simplest way to generate sounds in the digital realm is to "click" or "bit bang" a speaker on and off with a digital I/O line. This is how it was done on a lot of old-school video games and computers prior to sound cards.

The simplest option is to plug a piezo buzzer into the Arduino UNO such that the negative terminal is in the ground port and the positive terminal is connected to an I/O line. You can also use a DuPont jumper of you'd like to use a different I/O pin. This video goes through the step-by-step basics of coding an Arduino to click the speaker at different frequencies. Follow along and give it a try.

A shortcut to coding simple sounds is using the tone() function. This function generates a square wave of the specified frequency on a specified I/O pin. This tutorial demonstrates using the tone() function to play a melody. This same approach can be used to generate the Mario Brothers Theme.

Can't get enough? Have a listen to 1-Bit Symphony or some retro Atari 8-bit Music.

From Digital to Analog

sampled analog wave.gif
MCP4725-Module-Pin-Outs.png

As you might imagine, there are numerous benefits and challenges in the evolution from simply clicking a speaker on and off to the more refined approach of generating rich analog signals more like those encountered in the natural world. You may want to have a look at this Make: article on "Advanced Arduino Sound Synthesis" which is packed with great background information.

We can start our adventure in Digital to Analog Conversion (DAC) using the tiny, but awesome, MCP4725 (datasheet) Integrated Circuit. SparkFun has a great hookup guide for getting the MCP4725 DAC module interfaced to your UNO board along with some code to start generating analog signals.

Remember that the Arduino has a built in ADC, which is the opposite of the DAC on this module. An interesting experiment to perform with the built in ADC and your new DAC module is to code the DAC to generate various voltages and then sample those voltages back into the ADC. The code-generated output values can then be compared against the measured input voltages. There are additional details as well as very nice example code right here for doing this quite easily. How accurate are your converters?

LM386 Audio Power Amplifier Module

LM386 Module.jpeg
LM386 Schem.png

If you want to drive a line-level analog audio signal (for example, from a DAC) into a speaker or headphones, it may be necessary to amplify the signal a bit. The LM386 Integrated Circuit a very common low voltage audio power amplifier. It is useful for radios, guitar amplifiers, and various hobby electronics projects. The screw terminals of the module can be wired directly to a speaker.

Pump up the Volume!

MP3 Player Module With MicroSD Card Reader

MP3 Module.png
speaker.png
SD Card and Reader.jpg

The MP3 decoder board can play MP3 files from a USB flash drive or from a MicroSD flash card. The player has decent sound quality, an on-board 2W mono amplifier, and can be directly connected to a speaker. It also features a 3.5mm gold plated headphone jack that can connect headphones or an external audio amplifier.

Power Supply: There is a MicroUSB port for powering the board through a standard MicroUSB (mobile phone) cable. There are also solder terminals for connecting a 3.7V lithium battery pack. The battery terminals can handle up to 5.5V DC. Power applied to the MicroUSB port can also charge the attached 3.7V lithium battery. Please note that some USB sticks require 5V minimum and will not work with the 3.7V power supply option.

Flash Memory: The player supports files stored on both a USB flash drive (tested up to 32GB) and a MicroSD flash card (tested up to 16GB). If both are installed, the SD card plays first, but can be overridden by the "mode" button. The tracks will load and start playing automatically upon power up. The chip appears to be able to automatically traverse through folders off of the root to find MP3 files.

LED: When an MP3 is playing, the red LED flashes.

Prev / V-- Button: Short Press for previous track. Long Press for volume down.

Next / V++ Button: Short Press for next track. Long Press for volume up.

P / P / Mode Button: Short Press for Play/Pause. Long Press for USB/microSD toggle.

Repeat Button: Single Track / Cycle All Tracks toggle (powers up into cycle mode).

(Long Press is approximately two seconds.)

DIY Buddha Machine

buddha machines.jpg
buddha3.jpg

Ready for an interesting DIY Low-Fi fun-time for your new MP3 player module? How about a DIY version of the FM3 Buddha Machine? The original device was an inexpensive, brightly colored, pocket-sized musical loop player. According to Wikipedia, "The Buddha Machine fulfills certain criteria of a generative music device, while the idea of layering loops of ambient sound is credited to Brian Eno, who worked similarly using tape machines for installations. Eno was himself an early supporter of the Buddha Machine." The New Yorker published an interesting article about this crazy little box, while Boing Boing suggests, "If You Meet the Buddha Machine on the Road, Hack It."

Before going DIY, you can play with a web version of the Buddha Machine. For DIY, you can download the original sound files from various locations. For example, a zip of wav files is available from the original manufacturer. They can be easily converted to MP3 files, or of course you can transfer any of your favorite ambient music tracks onto the micro SD card if the FM3 loops don't do it for you. Enjoy a little psycho-emotional biohacking by building some simple, calming, meditative tunes into your environment.

Arduino MP3 Music Shield

shield.jpg
shield schem.png
shield wired.jpg

The MP3 music shield board is based the on the VS1053B CODEC chip (datasheet) from VLSI. The shield can be plugged directly unto an Arduino UNO/MEGA with no need to hook up any jumpers or wires.

  • Supports various formats:
    • Ogg Vorbis
    • MP3
    • AAC
    • WMA
    • MIDI
  • Supports OGG encoded real-time recording
  • SPI control interface
  • Built-in microphone for recording
  • 3.5mm stereo headphone output
  • 3.5mm stereo line-in interface
  • Power indicator LED
  • 12.288 Mhz crystal oscillator
  • MicroSD card slot

Getting started with this shield is easy with this detailed tutorial and code from SparkFun. It works a bit like the stand-alone MP3 player board, but it can be controlled by the Arduino and it features much broader file format support.

VU (volume Unit) Meter - Soldering Kit

VU Mete Kit Parts.jpg
Level Meter 2.png

A Volume Unit Meter (VU meter) is a device for displaying a representation of signal level in audio equipment. While standardized for use in telephone installation and radio broadcast stations, consumer audio equipment often feature VU meters for reasons both practical and aesthetic (they look cool).

  • Printed Circuit Board (PCB) 62 x 27 mm
  • LM3915 18pin DIP Integrated Circuit (datasheet)
  • 18pin DIP Socket
  • Two (2) Dual Pin Male Sockets
  • Two (2) Dual Pin Connector Leads
  • Two (2) Red LEDs
  • Eight (8) Yellow LEDs
  • 50K Potentiometer (3296 package)
  • 10K Resistor (brown, black, black, red, brown)
  • 10 ohm Resistor (brown, black, black, gold, brown)
  • 560 ohm Resistor (green, blue, black, black, brown)
  • 20K Resistor (red, black, black, red, brown)
  • 100 ohm Resistor (brown, black, black, black, brown)
  • Three (3) 1K Resistors (brown, black, black, brown, brown)
  • Two (2) 100nF Ceramic Capacitors

The LM3915 is a monolithic integrated circuit that senses analog voltage levels and drives ten LEDs providing a logarithmic 3dB/step analog display. While the chip is specified to operate at 3-25V, the board design suggests a 9-12V DC supply. A 9V battery clip is provided as one easy option for a power source.

Soldering: Start with the smaller items (resistors and capacitors). Solder the components in and trim the extra leads off from the back of the PCB. Follow the photo and the silk screen on the board as a guide. Take your time.

The different resistor values are not interchangeable. Put them where they belong. It is wise to double check the values with a color code chart or better yet with a meter. The last brown stripe on these resistors indicates that they are 1% tolerance (accuracy). The capacitors are labeled 104 indicating "10 x 10 to the power of 4" (in pF) which is an odd, but efficient, way of saying 100 nF. Work the math before it works you! The resistors and these particular capacitors are not polarized. They can be inserted in either direction.

The LEDs are polarized. The longer pin needs to go into the positive hole (marked with a +). The LEDs can go straight into the board, or they can be bent to the side as shown in the photo. It just depends how you want to orient the board while viewing the output. This isn't particularly important unless you intend to mount the a board within a housing.

Solder the 18pin socket without the IC inserted. Then insert the IC after the solder work has cooled. The half circle "pin 1" indicator on the PCB silkscreen, on the socket, and on the IC should all be oriented to the same side.

The LM3915 has two modes: bar and dot. It defaults to dot mode. You can short the two pins of jumper J3 (solder in a bent piece of wire or a lead trimmed off of a component) to put the LM3915 into bar mode. In dot mode, it may appear that some of the lower LEDs are not lighting up. This tutorial provides some additional details on the subject.

Are you new to soldering? There are a lot of great guides and videos online about soldering. Here is one example. If you feel that you need additional assistance, try to find a local makers group or hacker space in your area. Also, amateur radio clubs are always excellent sources of electronics experience.

Some small minority commentary on this design indicates that the sensitivity is not very good on some boards and can be improved by replacing the 560 ohm resistor with a larger value (suggested around 2.2K). This should not be an issue with your kit, but the information is included here for completeness.

Passive Filters - Maniulating Audio Signals in Circuit

filter_high_pass.png
filter_low_pass.png
RC.png

Electronic filters, according to Wikipedia, are circuits which perform signal processing functions. They remove unwanted frequency components from a signal, enhance desired frequencies, or possibly do both.

Passive filters are implementations of linear filters based on combinations of resistors (R), inductors (L), and capacitors (C). They are collectively known as passive filters, because they do not depend upon an external power supply and they do not contain active components such as transistors.

The first passive filter for audio that most encounter is an audio crossover from a stereo speaker system. Most individual loudspeaker drivers are incapable of covering the entire audio spectrum from low frequencies to high frequencies without distortion. Instead, most hi-fi speaker systems use a combination of multiple loudspeaker drivers, each catering to a different frequency band. Audio crossovers use filters to split the audio signal into separate frequency bands that can be separately routed to loudspeakers optimized for those bands.

The graphics shown here are inspired from a fantastic instructable demonstrating how to make several different passive filter circuits including low pass filters, high pass filters, notch/trap filters, and band-pass filters.

Note that the illustrated high pass and low pass filters are fairly simple and only differ by having the R and C components swapped. A 1K resistor and a 330nF capacitor from the electronics kit bag can be used to form either circuit depending upon how you solder them together. Using these R and C values, the cuttoff frequency of 1/2piRC can be calculated as 1/(2pi(1000)(330E-9)) or 480 Hz. The resultant filter circuits can be tested by coding up a short program that slowly switches between generating a tone in the pass band and then a tone in the stop band. For example, 250Hz and 2000Hz. Then one can listen to how the output level changes when the filter is inserted and removed from between the ADC and the speaker.

If you'd like to know a little more, this video has a full blown academic presentation on passive low pass filter theory. This online cutoff calculator is interesting to play around with.

Active Filters and Digital Signal Processing (DSP)

DSP_block_diagram.png
Dig Signal Plot.png

The topics of active filters and digital filters will be addressed in detail with future editions of HackerBoxes. For now, please consider this step as optional for advanced or extremely eager hardware hackers. Of course, according to the hacker ethos, that is pretty much all of us, right?

Digital (DSP) Filters: Here is a quick start to playing with digital signals and digital filters on a computer using MATLAB (Matrix Laboratory). Since MATLAB is widely used in research and academics, there are endless examples of cool things online that you can explore in MATLAB. It is worth the time to learn. If you want to explore this area but do not have access to MATLAB (it is quite expensive), consider installing GNU Octave. For general DSP questions, it is useful to access the free copy of the book Scientist and Engineer's Guide to Digital Signal Processing.

To get started with DSP in an embedded environment, there is an Arduino library available from Jon Hub for implementing DSP filters. There is another such library available from Jeroen Doggen. A great experiment would be to use one of the DSP filter libraries to implement a High (or Low) Pass Filter with a 500Hz cutoff and examine how its performance compares to the passive analog 500Hz filters that we build in the last step. Remember that when working with digital signals, signal frequency is not absolute since it is always relative to your sampling frequency.

Active Filters: Section 5.6 of this free book entitled Op Amp Applications Handbook has a really nice introduction that weaves our passive filters from the previous step into active circuits using operational amplifiers.

Sonic Pi - Live Play With Digital Audio

sonic_pi_1.png
sonic_pi_2.png

Click on over to the Sonic Pi project. Sonic Pi is very cool and a ton of fun. It's a live coding environment originally designed to support both computing and music lessons in schools. It was developed at the University of Cambridge Computer Laboratory in collaboration with Raspberry Pi Foundation.

You can download a free PDF of the book Code Music with Sonic Pi if you want to dive deeper with this awesome tool.

Hack the Planet

Hack The Planet.png

So how did that sound? What did you create? If you enjoyed this Instrucable and you would like to have a box like this delivered right to your mailbox each month, please SUBSCRIBE HERE.

Please share your success (below and/or on the HackerBoxes Facebook Page) and certainly let us know if you have any questions. Thank you for being part of the HackerBoxes adventure. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!