Tag Archives: music

Go back in time with a Raspberry Pi-powered radio

via Raspberry Pi

Take a musical trip down memory lane all the way back to the 1920s.

Sick of listening to the same dozen albums on repeat, or feeling stifled by the funnel of near-identical YouTube playlist rabbit holes? If you’re looking to broaden your musical horizons and combine that quest with a vintage-themed Raspberry Pi–powered project, here’s a great idea…

Alex created a ‘Radio Time Machine’ that covers 10 decades of music, from the 1920s up to the 2020s. Each decade has its own Spotify playlist, with hundreds of songs from that decade played randomly. This project with the look of a vintage radio offers a great, immersive learning experience and should throw up tonnes of musical talent you’ve never heard of.

In the comments section of their reddit post, Alex explained that replacing the screen of the vintage shell they housed the tech in was the hardest part of the build. On the screen, each decade is represented with a unique icon, from a gramophone, through to a cassette tape and the cloud. Here’s a closer look at it:

Now let’s take a look at the hardware and software it took to pull the whole project together…

Hardware:

  • Vintage Bluetooth radio (Alex found this affordable one on Amazon)
  • Raspberry Pi 4
  • Arduino Nano
  • 2 RGB LEDs for the dial
  • 1 button (on the back) to power on/off (long press) or play the next track (short press)

The Raspberry Pi 4 audio output is connected to the auxiliary input on the radio (3.5mm jack).

Software:

    • Mopidy library (Spotify)
    • Custom NodeJS app with JohnnyFive library to read the button and potentiometer values, trigger the LEDs via the Arduino, and load the relevant playlists with Mopidy

Take a look at the video on reddit to hear the Radio Time Machine in action. The added detail of the white noise that sounds as the dial is turned to switch between decades is especially cool.

How do you find ten decades of music?

Alex even went to the trouble of sharing each decade’s playlist in the comments of their original reddit post.

Here you go:

1920s
1930s
1940s
1950s
1960s
1970s
1980s
1990s
2000s
2010s

Comment below to tell us which decade sounds the coolest to you. We’re nineties kids ourselves!

The post Go back in time with a Raspberry Pi-powered radio appeared first on Raspberry Pi.

These loo rolls formed a choir

via Raspberry Pi

Have all of y’all been hoarding toilet roll over recent weeks in an inexplicable response to the global pandemic, or is that just a quirk here in the UK? Well, the most inventive use of the essential household item we’ve ever seen is this musical project by Max Björverud.

Ahh, the dulcet tones of wall-mounted toilet roll holders, hey? This looks like one of those magical ‘how do they do that?’ projects but, rest assured, it’s all explicable.

Max explains that Singing Toilet is made possible with a Raspberry Pi running Pure Data. The invention also comprises a HiFiBerry Amp, an Arduino Mega, eight hall effect sensors, and eight magnets. The toilet roll holders are controlled with the hall effect sensors, and the magnets connect to the Arduino Mega.

In this video, you can see the hall effect sensor and the 3D-printed attachment that holds the magnet:

Max measures the speed of each toilet roll with a hall effect sensor and magnet. The audio is played and sampled with a Pure Data patch. In the comments on his original Reddit post, he says this was all pretty straight-forward but that it took a while to print a holder for the magnets, because you need to be able to change the toilet rolls when the precious bathroom tissue runs out!

Max began prototyping his invention last summer and installed it at creative agency Snask in his hometown of Stockholm in December.

The post These loo rolls formed a choir appeared first on Raspberry Pi.

This maker turned an antique typewriter into a MIDI drum machine

via Arduino Blog

Vintage typewriters are truly amazing pieces of technology, but unlike modern keyboards, they are decidedly one-purpose machines. William Sun Petrus, however, had other ideas for his 1920s-era Remington Portable typewriter, augmenting hammers with wires as inputs to an Arduino Mega.

Input signals are produced when each key strikes a metallic “live plate” in the center, completing a circuit. This info is passed along as MIDI signals to a computer running Ableton digital audio software, allowing him to create the excellent beat seen in the video below. 

Typewriter code is available on GitHub, where you’ll certainly notice the lines from Green Eggs and Ham that are output on an LCD screen at the base of the almost 100-year-old device.

Greg’s Harp is an Arduino-powered robotic string instrument

via Arduino Blog

Frank Piesik recently designed a robotic three-stringed instrument for his friend, Gregor, that features a unique sound and mechanical arrangement. Notes are selected by an array of 12 servos — four for each string — which pull down using a loop mechanism. 

The aptly named Greg’s Harp is played by a solenoid-driven “KickUp” device that hits it from below and a small motor that continuously swipes with a “tape-propeller.” A coil assembly is also implemented to give the notes the ability to keep ringing for as long as needed (infinite sustain).

Everything is controlled by pair of Arduino Nano boards, which allow for the large number of outputs needed here, along with a Teensy 3.2 for audio processing and MIDI capabilities. You can see and hear this amazing project in the video below and more info is available in Piesik’s blog post.

How to play sound and make noise with your Raspberry Pi

via Raspberry Pi

If your amazing project is a little too quiet, add high-fidelity sound with Raspberry Pi and the help of this handy guide from HackSpace magazine, written by PJ Evans.

The PecanPi HAT features best-in-class components and dual DACs for superior audio reproduction

It’s no surprise that we love microcontrollers at HackSpace magazine. Their versatility and simplicity make them a must for electronics projects. Although a dab hand at reading sensors or illuminating LEDs, Arduinos and their friends do struggle when it comes to high-quality audio. If you need to add music or speech to your project, it may be worth getting a Raspberry Pi computer to do the heavy lifting. We’re going to look at the various audio output options available for our favourite small computer, from a simple buzz, through to audiophile bliss.

Get buzzing

Need to keep it simple and under a pound?
An active buzzer is what you need

The simplest place to start is with the humble buzzer. A cheap active buzzer can be quickly added to Raspberry Pi’s GPIO. It’s surprisingly easy too. Try connecting a buzzer’s red wire (positive) to GPIO pin 22 (Broadcom numbering) and the black wire (ground) to any GND pin. Now, install the GPIO Zero Python library by typing this at the command line:

sudo apt install python3-gpiozero

Create a file called buzz.py in your favourite editor and enter the following:

import time
from gpiozero import Buzzer
buzzer = Buzzer(22)
buzzer.on()
time.sleep(1)
buzzer.off()

Run it at the command line:

python3 buzz.py

You should hear a one-second buzz. See if you can make Morse code sounds by changing the duration of the sleep statement.

Passive but not aggressive

Raspberry Pi computers, with the exception of the Zero range, all have audio output on board. The original Raspberry Pi featured a stereo 3.5mm socket, and all A and B models since feature a four-pole socket that also includes composite video. This provides your cheapest route to getting audio from your Raspberry Pi computer.

A low-cost passive speaker can be directly plugged in to provide sound, albeit probably quieter than you’d like. Of course, add an amplifier or active speaker and you have sound as loud as you like. This is the most direct way of adding sound to your project, but how to get the sound out?

Need a simple solution? USB audio devices come in all shapes and sizes but are mostly plug-and-play

Normally, the Raspbian operating system will recognise that an audio device has been connected and route audio through it. Sometimes, especially if you’ve connected an HDMI monitor with sound capability (e.g. an HDMI TV), sound will not come out of the correct device.

To fix this, open up a terminal window and run sudo raspi-config. When the menu appears, go to Advanced Options and select Audio, then select the option to force the output through the audio jack. You may need to reboot Raspbian for all changes to take effect.

Plug and playback

A USB sound device is another simple choice for audio playback on Raspberry Pi. Literally hundreds are available, and a basic input/output device with better audio quality than the on-board system can be purchased for a few pounds online. Installation tends to be no more complicated than plugging the device into the USB port. You may need to select the new output, as the underlying audio system, ALSA (see the ALSA and PulseAudio section for more), may mute it by default. To fix this, run alsamixer from the command line, press F6 to select the new sound device, and if you see ‘MM’ at the bottom of the volume indicator, press M to unmute and adjust the volume with the cursor keys.

Many DACs also come with on-board amplifiers. Perfect for passive speakers

Unsurprisingly, when choosing your USB sound device, you can start at a few pounds and go right up to professional equipment costing hundreds. As they are low-power, USB devices do not tend to feature amplification, unless they have a separate power source.

Let’s play

The simplest way to play audio on Raspbian is to use OMXPlayer. This is a dedicated hardware-accelerated command-line tool that takes full advantage of Raspberry Pi’s capabilities. It sends audio to the analogue audio jack by default, so playing back an MP3 file is as simple as running:

omxplayer /path/to/audio/file.wav

There are many command-line options that allow you to control how the audio is played. Want the audio to loop forever? Just add --loop to the command. You’ll notice that when it’s running, OMXPlayer provides a user interface of sorts, allowing you to control playback from within the terminal. If you’d just like it to run in the background without user input, run the command like this:

omxplayer --no-keys example.wav &

Here, —-no-keys removes the interface, and the ampersand (&) tells the operating system to run the job ‘in the background’ so that it won’t block anything else you want to do.

OMXPlayer is a great choice for Raspbian, but other players such as mpg321 are available, so find the tool that’s best for you.

Another useful utility is speaker-test. This can produce white noise or vocal confirmation so you can check your speakers are working properly. It’s as simple as this:

speaker-test -t wav -c 2

The first parameter sets the sound to be a voice, and the -c tests stereo channels only: front left and front right.

Phat Beats

If space is an issue, a Raspberry Pi 4, amplifier, and speaker may not be what you have in mind. After all, your cool wearable project is going to be problematic if you’re trailing an amplifier on a cart with a 50-metre extension lead powering everything. Luckily, the clever people at Pimoroni have you covered. The Speaker pHAT is a Raspberry Pi Zero-sized HAT that not only adds audio capability to the smallest of the Raspberry Pi family, but also sports a 3 W speaker. Now you can play any audio with a tiny device and a USB battery pack.

Small, cheap, and fun, the Speaker pHat features a 3 W speaker and LED VU meter

The installation process is fully automated, so no messing around with drivers and config files. Once the script has completed, you can run any audio tool as before, and the sound will be routed through the speaker. No, the maximum volume won’t be troubling any heavy metal concerts, but you can’t knock the convenience and form factor.

Playing the blues

An easy way to get superior audio quality using a Raspberry Pi computer is Bluetooth. Recent models such as the 3B, 4, and even the Zero W support Bluetooth devices, and can be paired with most Bluetooth speakers, even from the command line. Once connected, you have a range of options on size and output power, plus the advantage of wireless connectivity.

Setting up a Bluetooth connection, especially if you are using the command line, can be a little challenging (see the Bluetooth cheatsheet section). There is a succinct guide here: hsmag.cc/N6p2IB. If you are using Raspbian Desktop, it’s a lot easier. Simply click on the Bluetooth logo on the top-right, and follow the instructions to pair your device.

If you find OMXPlayer isn’t outputting any audio, try installing mpg321:

sudo apt install mpg321

And try again:

mpg321 /path/to/audio/file.mp3

But seriously

If your project needs good audio, and the standard 3.5 mm output just isn’t cutting it, then it’s time to look at the wide range of DACs (digital-to-analogue converters) available in HAT format. It’s a crowded market, and the prices vary significantly depending on what you want from your device. Let’s start at the lower end, with major player HiFiBerry’s DAC+ Zero. This tiny HAT adds 192kHz/24-bit playback via two RCA phono ports for £12.50. If you’re serious about your audio, then you can consider the firm’s full HAT format high-resolution DAC+ Pro for £36, or really go for it with the DSP (digital sound processing) version for £67. All of these will require amplification, but the sound quality will rival audio components of a much higher price.

Money no object? The Allo Katana is a monster DAC, and weighs in at £240, but outperforms £1000 equivalents

If money is no object and your project requires the best possible reproduction, then you can consider going full audiophile. There are some amazing high-end HATs out there, but one of the best-performing ones we’ve seen is the PecanPi DAC. Its creator Leonid Ayzenshtat sourced each individual component carefully, always choosing the best-in-class. He even used a separate DAC for each audio channel. The resulting board may make your wallet wince at around £200 for the bare board, but the resulting audio is good enough to be used in professional recording studios. If you’ve restored a gorgeous old radio back to showroom condition, you could do a lot worse than add the board in with a great amp and speaker.

ALSA and PulseAudio

There’s often confusion between these two systems. Raspbian comes pre-installed with ALSA (Advanced Linux Sound Architecture), which is the low-level software that makes sound work. It comes with a range of utilities to control output device, volume, and more. PulseAudio is a software layer that sits on top of ALSA to provide more features, including streaming capabilities. Chances are, if you need to do something a bit more clever than just play audio, you’ll need to install a PulseAudio server.

Bluetooth cheatsheet

If you want to pair a Bluetooth audio device (A2DP) on the command line, it can be a little hairy. Here’s a quick guide:

First-time installation:

sudo apt-get install pulseaudio pulseaudio-module-bluetooth
sudo usermod -G bluetooth -a pi
sudo reboot

Start the PulseAudio server:

pulseaudio --start

Run the Bluetooth utility:

bluetoothctl

Put your speaker into pairing mode. Now, within the utility, run the following commands (pressing Enter after each one):

power on
agent on
scan on

Now wait for the list to populate. When you see your device…
pair <dev>
Where <dev> is the displayed long identifier for your device. You can just type in the first few characters and press Tab to auto-complete. Do the same for the following steps.

trust <dev>
connect <dev>

Wait for the confirmation, then enter:

quit <dev>

Now try to play some audio using aplay (for WAV files) or mpg321 (for mp3). These instructions are adapted from the guide by Actuino at hsmag.cc/N6p2IB.

File types

There are command-line players available for just about every audio format in common use. Generally, MP3 provides the best balance of quality and space, but lower bit-rates result in lower sound quality. WAV is completely uncompressed, but can eat up your SSD card. If you don’t want to compromise on audio quality, try FLAC, which is identical in quality to WAV, but much smaller. To convert between audio types, consider installing FFmpeg, a powerful audio and video processing tool.

HackSpace magazine

This article comes direct from HackSpace magazine issue 28, out now and available in print from your local newsagent, the Raspberry Pi Store in Cambridge, and online from Raspberry Pi Press.

If you love HackSpace magazine as much as we do, why not have a look at the subscription offers available, including the 12-month deal that comes with a free Adafruit Circuit Playground! Subscribers in the USA can now get a 12-month subscription for $60 when joining by the end of March!

And, as always, you can download the free PDF from the Raspberry Pi Press website.

The post How to play sound and make noise with your Raspberry Pi appeared first on Raspberry Pi.

Playing The Doors with a door (and a Raspberry Pi)

via Raspberry Pi

Floyd Steinberg is back with more synthy Raspberry Pi musical magic, this time turning a door into a MIDI controller.

I played The Doors on a door – using a Raspberry PI DIY midi controller and a Yamaha EX5

You see that door? You secretly want that to be a MIDI controller? Here’s how to do it, and how to play a cover version of “Break On Through” by The Doors on a door ;-) Link to source code and the DIY kit below.

If you don’t live in a home with squeaky doors — living room door, I’m looking at you — you probably never think about the musical potential of mundane household objects.

Unless you’re these two, I guess:

When Mama Isn’t Home / When Mom Isn’t Home ORIGINAL (the Oven Kid) Timmy Trumpet – Freaks

We thought this was hilarious. Hope you enjoy! This video has over 60 million views worldwide! Social Media: @jessconte To use this video in a commercial player, advertising or in broadcasts, please email kyle@scalemanagement.co

If the sound of a slammed oven door isn’t involved in your ditty of choice, you may instead want to add some electronics to that sweet, sweet harmony maker, just like Floyd.

Trusting in the melodic possibilities of incorporating a Raspberry Pi 3B+ and various sensory components into a humble door, Floyd created The Doors Door, a musical door that plays… well, I’m sure you can guess.

If you want to build your own, you can practice some sophisticated ‘copy and paste’ programming after downloading the code. And for links to all the kit you need, check out the description of the video over on YouTube. While you’re there, be sure to give the video a like, and subscribe to Floyd’s channel.

And now, to get you pumped for the weekend, here’s Jim:

The Doors – Break On Through HQ (1967)

recorded fall 1966 – lyrics: You know the day destroys the night Night divides the day Tried to run Tried to hide Break on through to the other side Break on through to the other side Break on through to the other side, yeah We chased our pleasures here Dug our treasures there But can you still recall The time we cried Break on through to the other side Break on through to the other side Yeah!

The post Playing The Doors with a door (and a Raspberry Pi) appeared first on Raspberry Pi.