Piface

Piface

Sunday, March 2, 2014

Raspberry Pi Multi-room Audio Solved

Hi there-  I just spent a few hundred hours figuring out how to send my favorite Pandora stations to every room in my house simultaneously.  I tried every DIY solution that there was, and this is the final answer.  I will tell you what you need, and where to go to get the info.  This solution is under $500 for FOUR rooms, and may even be cheaper if you already have the things.

PLEASE NOTE:  NONE of this is my work. NONE.  I am standing on the shoulders of giants.  Please read to the end for credits.

This is actually much simpler than you would think:

SPEAKERS-
First, you need speakers in each room that have 1/8 jacks.  You can get male-male cables that will plug into the Raspberry Pis, so these do not need to be new speakers/ipod-ready.  ANY speakers will do.   We found a decent unit at Target for $30, but I challenge you to do better.  At Mallwart we found a 3 foot long speaker for under the TV that cost $70.  All you need is 4 powered speakers, on set for each room.  Old computer speakers would do fine.  You can always update this part later.

EST-  $200 if you don't already have the speakers

COMPUTERS-
You will need either 3 raspberry pi's and one old laptop, or 4 raspberry pi's (or one pi/computer for each room of your house).
I got the raspberry pi model B from Allied Electronics.  Individually, they were $40 with shipping and the Noobs OS 8GB SD Card.  The truth is, you only need a 4GB SD card for each, and you don't need Noobs/Raspbian, so you should shop around for the Pi's.
You will also need an Edimax Wifi dongle for each.  It looks like this:

http://www.amazon.com/Edimax-EW-7811Un-Wireless-Adapter-Wizard/dp/B003MTTJOY/ref=sr_1_1?ie=UTF8&qid=1393773311&sr=8-1&keywords=wifi+dongle+raspberry+pi

And you will need 3 microusb phone charger cables with wall-warts.  You may already have these around, or you can buy them for 5 bucks.  I got these because I thought I needed the extra juice at the time.  You should be cool with 1,000 mA:

http://www.amazon.com/Kootek-Raspberry-Supply-Charger-Adapter/dp/B00FIFYQMA/ref=sr_1_1?ie=UTF8&qid=1393773565&sr=8-1&keywords=raspberry+pi+power+supply


So, for me it was 3 pi's plus 3 wifi dongles plus 3 cables= $175 for the computers.  You could get this number down by getting JUST the model B pi's without the Noobs SD card, and buying a couple of your own cheaper 4 GB SD cards.

EST- $175 or maybe a schooch less... and dig up an old laptop that is Wifi ready to save on one room

SETUP GEAR-
You will need an HDMI cable, with an HDMI-ready TV.  You probably have SOME monitor somewhere that has an HDMI input.  If you don't, you should be able to use a yellow RCA jack from an old school TV, although I haven't tested this.

You will need a keyboard, but you will NOT need a mouse for this method.  You will also need an ethernet cable connected to your house internet.

And don't forget those male-to-male 1/8 audio cables if you need them to connect to your speakers.

_________________________________________________________________________________
HOW TO:
_________________________________________________________________________________
Conceptual Overview:  You will have a raspberry pi in each room, and a "server" computer in the main room.  The raspberry pi computers are slaves- all they do is relay the audio signal to the speakers in that room.  The server computer is a server, but is also a slave.  That means it is A) broadcasting to the raspberry pis, and B) playing the broadcast locally.  In this way, you avoid having to get a raspberry pi for the room that the server is in.
...That's the basic idea...

The System:  Thanks to Thomas, over  at http://www.squeezeplug.de, what we are actually doing is turning this grouping of computers into the Logitech Media Squeezebox setup.
The server computer is running as a Squeezebox, and the raspberry pis are running as Squeezelite slaves, which Thomas has dubbed "squeezeplugs".
All of this runs headless, so it consumes very little resourceas, and it can be controlled by a browser open on your local network, or by a multitude of Apps available for your phone or tablet.  ALL SOFTWARE FOR THIS IS FREE FREE FREE

What do I actually do?:

SERVER
First, get an old laptop from your mom, or your neighbor, or whatever.  The perfect candidate is an old and slow machine that you used to love but now you hate.  Put UBUNTU on it.  Ubuntu is an operating system.  It is open source, it is amazing, and it is fast.  It will breathe new life into your old computer.  Google it.

Once you have ubuntu set up, which actually should be as simple as getting the newly ubuntu-ed machine to connect to your wifi, download the Squeezebox software (FREE) from here:
http://www.mysqueezebox.com/

Check in-  You should now have a crappy old computer that has been restored with the linux-based Ubuntu, and which is connected to your wifi network, and which has the Mysqueezebox software downloaded to it.
NOTE:  You can do this without putting ubuntu on the machine, just use the windows version of the software.

THE RASPBERRY PI's
Open up your new raspberry pis.  Look how cute they are.
Now, you need to image a few 4 GB SD cards.
If... you got the Noobs SD card with the pi's, you can format those cards and use them.
If... you bought new 4GB SD cards, you just have to burn the image to them.

Here is the image:  http://www.squeezeplug.eu/?page_id=52
AT THE TOP OF THE PAGE

So, unzip/unpack it, and then burn it to the SD cards.

**if you need help with this step on Ubuntu, let me know at monkmandolins@gmail.com and I will talk you through it**

Check in-  You should now have your Server computer set up with your wifi, and with the Squeezebox software installed on it.  You should also have one SD card for each raspberry pi with the correct SqueezePLUG image burned to it.

SETTING UP THE PI'S

Put the SD card in the Pi.  Connect the pi to your HDMI device (or the RCA-capable TV).  Connect your wifi dongle in one usb port, and connect the keyboard to the other.  Connect the ethernet cable from the Pi to the router.  Plug in the power.
And....
Follow the directions.  Basically, here is the list:
Update the pi,
Expand the filesystem
Change the timezone
Change the keyboard layout if you are in the states (US, 104 generic)
Enable Wifi
Install and enable VNCServer (lets you access the Pi desktops remotely)

Once you have all of the basics setup, install the player Squeezelite.
Follow the directions, and that is ALL you have to do to the Pi.

Check in- You should now have a Server computer set up, and however many raspberry pi computers setup with the Squeezeplug image (thanks Thomas) and configured to be players with Squeezelite.

WHERE IS THE MUSIC?

This is a headless server.  That means it is always running in the background unless you interact with it through the website or a phone app.

Using the www.mysqueezebox.com website, log in and enable all of the devices you just made.  Just poke around to get things setup.  You can also add Pandora, etc., here if you have the PAID Pandora account.
Now, go to the webpage of your server:

 http:// (IP ADDRESS OF THE SERVER COMPUTER WITH NO PARENTHESIS):9000

Mine is http://192.168.0.10:9000

And you have control over all of the Pis.  Poke around on the Logitech Media Server page there to add your local music files, etc.  But for instant gratification, just choose a radiostation to play.

By this time, your Pi's should be in their individual rooms, connected to speakers, and plugged in.

So, you have music playing now (hopefully) through 3 other rooms.  But not in the room you are sitting in (Server Room).

(IF YOU ARE USING UBUNTU, YOU MUST NOW ADD THE SERVER TO YOUR AUDIO GROUP:
                    sudo adduser squeezeboxserver audio

AND THEN RESTART THE SERVER COMPUTER)

The last step is to go to the webpage for your server, and under Settings>Plugins go to Other 3rd Party Plugins at the bottom (may need to enable these at the very bottom) and select
LOCAL PLAYER

Once this is configured, your Server computer should show up as a player and you can have simultaneous output through all the things!

EXTRAS, ETC:
This is just the tip of the iceberg, but it does make a working setup.
There is more to do:

I wasn't able to get an external USB soundcard working, but the quality is still pretty good with the Raspberry Pis native 1/8 jack, for now...

There is a bunch of other stuff you can get for the raspberry pi, and do with it, etc.

There is a better app for your Android phone called Squeeze Commander.  It costs 5 bucks, but allows you to control the volume in all of the rooms at the same time.

If you have a rooted Android phone, there is a .99cent Tasker plugin that will allow you to incorporate the Squeezebox into your Tasker routines, so that you could, for example, turn the music on immediately when you enter your house.

ALL CREDIT GOES TO:

THOMAS- here:         http://www.squeezeplug.de/
Do me, him, and you a favor and make a small donation to him.
He just saved us about $1,000 bucks on great home audio!!!!!

Thursday, August 16, 2012

Here is the code for the Arduino 8-Bit Delay guitar pedal.  It has been written to accommodate the using of 8 digital outputs through an R2R digital to analog conversion system.  Just follow the schematic and use this code.


This is the code for the Arduino Realtime Audio- DELAY EFFECT
-it corresponds to the schematic, and requires an R2R Digital to Analog converter on 8 digital pins of the Arduino

//Arduino Realtime Audio-  Delay Effect-
//R2R digital to analog converter on digital pins 0-7
//Guitar input from a preamp that delivers 0-5V on analog pin 1
//Potentiometer middle lug to analog 0 with pins to Arduino 5V and ground

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) //clearing registry bits
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))  //setting registry bits

boolean div32;
boolean div16;
// interrupt variables accessed globally
volatile boolean f_sample;
volatile byte badc0;
volatile byte badc1;
volatile byte ibb;

int cnta;
int icnt;
int cnt2;
int iw1;
int iw;
byte bb; //OUTPUT???
byte dd[1024]; // Audio Memory Array 8-Bit

int numberPin = 2; // analog pin to read the buttons
int numberVal;  //BUTTON VALUE

void setup()
{
//R2R: Initialize output ports  MAKES PINS 0-7 OUTPUT TO DAC
// PORTD = B11111111;
for(int i=0; i < 8; i++){
  pinMode(i, OUTPUT);
}

fill_sinewave();    // reload wave after 1 second


// set adc prescaler to 64 for 19kHz sampling frequency
//DETERMINES DIVISION FACTOR BETWEEN SYSTEM CLOCK FREQUENCY AND
//INPUT CLOCK OF ADC

cbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);

//ADMUX SELECTS ANALOG INPUT CHANNEL

sbi(ADMUX,ADLAR); // 8-Bit ADC in ADCH Register PRESENTED LEFT-ADJUSTED
sbi(ADMUX,REFS0); // VCC Reference
cbi(ADMUX,REFS1);
cbi(ADMUX,MUX0);  // Set Input Multiplexer to Channel 0
cbi(ADMUX,MUX1);
cbi(ADMUX,MUX2);
cbi(ADMUX,MUX3);

// Timer2 Clock Prescaler to : 1
sbi (TCCR2B, CS20);
cbi (TCCR2B, CS21);
cbi (TCCR2B, CS22);

//cli(); // disable interrupts to avoid distortion

//TIMER/COUNTER INTERRUPT MASK REGISTER
cbi (TIMSK0,TOIE0); // disable Timer0 !!! delay is off now  OVERFLOW INTERRUPT ENABLE
sbi (TIMSK2,TOIE2); // enable Timer2 Interrupt

iw1=badc1; //NO IDEA

  DDRB=B00111111;//SETS DIGITAL LED PINS AS OUTPUTS
  DDRC=B00100000;//SETS ANALOG 5 AS OUTPUT
}

void loop()
{
while (!f_sample) {  // wait for Sample Value from ADC  WHAT DOES THIS DO?
}  // Cycle 15625 KHz = 64uSec

f_sample=false;  //VALUE OF BOOLEAN "f_sample"

bb=dd[icnt] ; // read the delay buffer
iw = 127-bb ; // substract offset
iw = iw * badc0 / 255;  // scale delayed sample with potentiometer
iw1 = 127 - badc1; // substract offset from new sample
iw1=iw1+iw;  // add delayed sample and new sample

if (iw1 < -127) iw1=-127; // Audio limiter

if (iw1 > 127) iw1=127;  // Audio limiter

bb= 127+iw1; // add offset
dd[icnt]=bb; // store sample in audio buffer
icnt++;
icnt = icnt & 1023;  // limit bufferindex 0..511

PORTD=bb;  //Sends the output to the R2R digital to analog converter on digital pins 0-7

} // loop
//******************************************************************

void fill_sinewave(){
float pi = 3.141592;
float dx ;
float fd ;
float fcnt;
dx=2 * pi / 512; // fill the 512 byte bufferarry
for (iw = 0; iw <= 511; iw++){ // with 50 periods sinewawe
fd= 127*sin(fcnt); // fundamental tone
fcnt=fcnt+dx;  // in the range of 0 to 2xpi  and 1/512 increments
bb=127+fd; // add dc offset to sinewawe
dd[iw]=bb; // write value into array

}
}

//******************************************************************
// Timer2 Interrupt Service at 62.5 KHz
// here the audio and pot signal is sampled in a rate of: 16Mhz / 256 / 2 / 2 = 15625 Hz
// runtime : xxxx microseconds

//TIMER/COUNTER 2 OVERFLOW INTERRUPT

ISR(TIMER2_OVF_vect) {

  div32=!div32; // divide timer2 frequency / 2 to 31.25kHz
if (div32){
div16=!div16; //
if (div16) {  // sample channel 0 and 1 alternately so each channel is sampled with 15.6kHz
badc0=ADCH; // get ADC channel 0
sbi(ADMUX,MUX0);  // set multiplexer to channel 1
}
else
{
badc1=ADCH; // get ADC channel 1
cbi(ADMUX,MUX0);  // set multiplexer to channel 0
f_sample=true;
}
ibb++;
ibb--;
ibb++;
ibb--; // short delay before start conversion
sbi(ADCSRA,ADSC); // start next conversion
}

}

Wednesday, December 8, 2010

Build your own 8-bit pedal (if you can :)


Well, here is a schematic for a working 8-bit guitar pedal.  The cost in parts WITH the housing is pretty low.  Most of it is the Arduino that you must buy to program it.  It consists of two different preamp stages, with a switch to select between them.  The first is an Infrared optocoupler that sends a 0-5V guitar signal out.  The second is a BOOMY and BEEFY Darlington transistor that does the same.  The microcomputer runs a routine that blesses the amped guitar sound with a crazy delay and/or fuzz effect before outputting an 8-bit signal.  You can effect the software with the pot that goes to the Atmega.
I made a discreet Digital to Analog converter using an R2R resistor ladder, and I added a switch and a pot at the output to dial in the different tones.
All in all, this thing sounds fantastic.  It gives the signal a HUGE boost, and allows you to dial in everything from Nintendo sounds through deep booming octave bass notes (and all kinds of craziness in between).
In keeping with the Arduino mission, I am more than happy to share/help anyone that is interested in this project.
Hit me up.
Pete

Tuesday, November 9, 2010

Arduino Guitar with Delay

Here is the first attempt at an Arduino guitar pedal.
The guitar signal feeds through a PT2399 delay circuit, modified to include a JFET preamp phase.  The delay circuit has Echo and Delay knobs.
From there, it feeds into my optoisolated-Arduino-5V preamp, and out to the Arduino.
The output from the Arduino is filtered and sent to the amp.

The sound is much better than a typical 8-bit setup, but with some very interesting digital overtones on top of the regular guitar signal.

This whole setup will be consolidated onto one printed circuit board and installed inside of an old Conrad single pickup electric from the 1960's.  More pictures to come.

Thanks to

http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/


For the code and the idea.




Wednesday, November 3, 2010

Guitar Preamp for ARDUINO 0-5V

Thanks for visiting.  The purpose of this post is to share with you all a design for a working preamp that will output a guitar signal to an Arduino MCU that ranges between 0-5V.
I explored many options for how to do this, and scoured the internet trying to find a good solution.  Finally, with the enlightened help of master circuit designer James T. Hawes, I have solved this problem.
Let me be clear- the circuit is entirely his design.  My only contribution was in requesting that he help me solve this problem and then in the final breadboarding of the design.  Please take a look at his website for a whole bunch of awesome info on amps, TV's, and a myriad other useful things:
             
http://www.hawestv.com/

I am quite interested in pushing the limits of what the ATMega328 chip can do for audio processing.  There is quite a bit of information on the net, but it is not very easy to access and the 0-5V input issue is a big one.

Basically, the challenge was to come up with a way to input a guitar signal that the Arduino can read at an analog input pin and "do stuff with".
Initially, I wanted to make a preamp that would directly output 0-5V when the electric guitar is played through it, with the silence output at around 2.5V.  I am new to the Arduino, fairly new to electronics, and impossibly new to engineering, so my understanding of the underlying principles is very much oversimplified.

With the help of James Hawes, I attempted multiple preamp designs to boost the signal enough to get the Arduino to be able to read it.  Unfortunately, I fried a couple of chips because I didn't have enough control over what was happening.  I could run the preamp (FET driven, or NPN transistor-driven) off of a 5V supply and lose almost all of the gain, or I could run it off of a 9V battery and put the poor Arduino (UNO) in mortal danger.

Yesterday, James came up with the perfect solution- elegant, simple, readily available and VERY VERY EFFECTIVE.

All parts for this project can be acquired at Radio Shack.

The beauty of this design is in it's simplicity:

The first task was to boost the guitar signal.  A standard preamp was used that is copied from James design for an MPF102 (Radio Shack part) JFET preamp.  As a standalone preamp, this design is awesome and I have put it to a myriad of uses.  It is a very cool trick to have up your sleeve, for both electric and piezo pickups.  The standard part if you can't find the MPF102 is the 2N3819 JFET.

The output of the JFET preamp feeds into an NPN transistor circuit that uses the  2N3904 NPN transistor.  This part can be found in the Radio Shack NPN switching transistor mix pack- usually 5 are included in the package.

Basically, this entire circuit powers an infrared LED emitter.  So, the guitar signal goes in, gets boosted, and outputs at the emitter.  This is a 9V circuit.
The emitter is then aimed at the corresponding IR phototransistor which is connected to the Arduino at the analog input.  The IR emitter and the IR phototransistor are available as a pair from Radio Shack.  What I did was couple them together in the tube of a ballpoint pen, with their very tippy tops facing each other and no light permitted to enter.
The IR phototransistor runs off of the 5V pin of the Arduino and connects via a 10K resistor to the Arduino ground pin.

What we have done is separated the 9V circuit from the 5V circuit in such a way that the Arduino cannot be harmed (no more than 5V can enter the analog pin).

It is important to keep the two circuits separate, as that is the whole point of the project.

I repeat, the only place where the guitar signal interacts with the Arduino is OUT from the IR emitter and IN through the IR phototransistor.

Before hooking it up to the Arduino, I plugged the phototransistor directly into my amp and I was VERY impressed by the quality of the sound.  There is a natural warm fuzz that is interesting enough that it is worth exploring as an standalone analog circuit, and the entire sound is shockingly true and clean.

Upon hooking it up to the Arduino, I was amazed that the circuit does exactly what I wanted- namely converts the guitar signal into something that the Arduino can wrap it's little brain around.

So far, I have used this circuit to experiment with the Arduino Realtime Audio Processing writeup that can be found here:

http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/

And it sounds MUCH BETTER with this preamp than with the setup that is described on their website.

My hope is that as my technology improves I will be able to use this preamp to record a guitar part using the Adafruit Waveshield, and loop that part so that lead lines can be played over it.

I welcome your feedback, and hope you enjoy this very clever circuit from the genius Mr. James T. Hawes.

Thanks
Peter Laucks
Monk Soundworks
November 2010