Very simple Raspberry Pi Radio

Discussion about my Wifi Radio project at http://mightyohm.com/wifiradio/ or my WL-520gU talk at NOTACON.
Schwabinger
Posts: 49
Joined: Sat Dec 04, 2010 12:04 am
Location: Munich, Germany

Very simple Raspberry Pi Radio

Postby Schwabinger » Sat Dec 08, 2012 4:13 am

Hello Everybody,

as my NSLU2/Arduino based radio broke down after some month of operation, I now wanted to build something more simple and stable. (no extra microcontroller, as few as possible electric parts and wires ...)

I bought myself a Raspberry Pi; with the following command line command you declare two of the gpio pins to be input pins:

Code: Select all

echo "15" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio15/direction
echo "7" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio7/direction


Connect two push button to those two pins; with the following command you test the buttons's state:

Code: Select all

BUTTON=$(cat /sys/class/gpio/gpio7/value)
BUTTON1=$(cat /sys/class/gpio/gpio15/value)


So when BUTTON is pressed, the next station in the playlist will be played. BUTTON1 plays the previous station.
Pressing both together restarts mpd.

RaspRadio works like a charm with more than 30 stations in the list.
The only thing I will still add is a led to signal the station number that is currently playing.

http://www.flickr.com/photos/rigasw/sets/72157632507768131/


Schwabinger
Last edited by Schwabinger on Sun Nov 10, 2013 7:55 am, edited 1 time in total.

User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Very simple Raspberry Pi Radio

Postby gerben » Sat Dec 08, 2012 6:44 am

I'm too using my Pi as a internet radio. I have the Pi in my livingroom. The WL520GU is in my bedroom. I added 4 push-buttons to the pi (with a 1k resistor, just for insurance). I'm using python and the RPi.GPIO library to readout the button state. CPU usage is minimal, even when polling every 100ms.

But I'm not using the buttons at all, ever since I added a IR-receiver to the pi. A 1.62EURO part (TSOP1838) combined with lirc_rpi, LIRC and irexec. Works perfectly. Took some time to figure out how to get it working, reading commandcode sent by my remote, and configuring.
I can now just press the numbers on my remote to play that station.

If anyone is interested, I can post the instructions here!

Are you using the build in audio jack, or are you using a usb-sound-card?

Also, how are you going to show which of the 30 stations in playing, using just one LED? I'm intrigued as to how one could do this.

Schwabinger
Posts: 49
Joined: Sat Dec 04, 2010 12:04 am
Location: Munich, Germany

Re: Very simple Raspberry Pi Radio

Postby Schwabinger » Sat Dec 08, 2012 8:05 am

I use I 10 KOhm resistor as well for the push buttons.

The led blinks: long blink for every five, short blink for a single number:

LONG LONG short short --> 12

A printed version of the station list lies next to the radio.

User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Very simple Raspberry Pi Radio

Postby gerben » Sat Dec 08, 2012 9:09 am

The high numbers are going to be hard to read though. 29 would be LONG LONG LONG LONG LONG SHORT SHORT SHORT SHORT

You could just add a second led, just for the the 10's, and use the other for the single number (using LONG SHORT)

Thanks for sharing. I might add some leds later. I was planning to add a RGB led, but the one I ordered was using to many amps to add directly to the GPIO pins :-).

Schwabinger
Posts: 49
Joined: Sat Dec 04, 2010 12:04 am
Location: Munich, Germany

Re: Very simple Raspberry Pi Radio

Postby Schwabinger » Sat Dec 08, 2012 2:47 pm

I ordered a TSOP1838 today. What kind of remote do you need? Is it difficult to implement?

Greetings from Munich!

Schwabinger

User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Very simple Raspberry Pi Radio

Postby gerben » Sun Dec 09, 2012 6:26 am

Any remote will do.
I'm using a logitech universal remote (harmony 300), which is programmed to replace my sony-stereo's remote. The Pi's audio is connected to my stereo. If my stereo is set to AUX, most of the button on the remote don't do anything. So I use those buttons to control the Pi.
Kind of a strange setup, but it works for me.
I did run into one problem, that is, that the sony remote sent out 2 different lengths of pulses. I don't think many remotes will have this though. I fixed by making lirc think that the shorter code where from a different remote (you can setup LIRC to use multiple remotes at the same time).

So here come the instructions for how I set up things:

Connect the TSOP plus to the 3.3V, and ground to ground. I connected the OUT to GPIO 4, which is pin 7 on the board. I added a 2.2K resister just to be sure. Note that lirc_rpi defaults to using PIN12 (GPIO18) for input, and PIN11 (GPIO17) for output. If these pins are free, using those pins would be preferable. The output is for a IR blaster, but I don't need that. So I set output to GPIO 7 as that one isn't connected in my setup.

You'll need the lirc_rpi module. This is available in the latest kernel. Check if it is available in your system by running `find /lib/modules/ -name *lirc_rpi*`. If nothing is found do the following to upgrade the kernel

Code: Select all

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
sudo apt-get install git-core
sudo rpi-update

Install lirc

Code: Select all

sudo apt-get install lirc


Now load the lirc_rpi module (change gpio number is you are using different ones. note that these are gpio numbers, not pin numbers)

Code: Select all

sudo modprobe lirc_rpi gpio_in_pin=4 gpio_out_pin=7


Now to test run

Code: Select all

sudo mode2 -d /dev/lirc0

Now press some buttons on the remote. You should see a whole lot of space and pulse lines.

Now config lirc. run `sudo pico /etc/lirc/hardware.conf` and change the following lines

Code: Select all

         ...
         LIRCD_ARGS="--uinput"
         ...
         DRIVER="default"
         ...
         DEVICE="/dev/lirc0"

If you are using the default pins, you could also change `MODULES=""` to MODULES="lirc_rpi"

Now we need to led lirc learn the IR-commands sent by the remote.

Code: Select all

sudo /etc/init.d/lirc stop
irrecord -n -d /dev/lirc0 ~/lircd.conf
#follow the instructions on the screen
#just learn a few button. Do the rest once everything is working.
#now copy this newly created conf file
sudo mv ~/lircd.conf /etc/lirc/lircd.conf
#start lirc
sudo /etc/init.d./lirc start
#now run irw to check everything
irw
#now press the button on the remote you just learned. The commands should appear on the screen


If all this works go and create some actions to be performed on IR-input. Run `pico ~/.lircrc` and type something like:

Code: Select all

begin
        prog = irexec
        button = pause
        config = mpc toggle
end
begin
        prog = irexec
        button = nextsong
        config = mpc next;mpc play
end
begin
        prog = irexec
        button = prevsong
        config = mpc prev;mpc play
end
begin
        prog = irexec
        button = stop
        config = mpc stop
end

Change the `button=xxx` so xxx is the name you provided when running irrecord. Add more when needed.

Next we need to run irexec as a background process

Code: Select all

irexec -d


Now press e.g. the play button and see/hear what happens.

Final this to do is have modprob and irexec run on startup. To do this edit /etc/rc.local. `sudo pico /etc/rc.local`

Code: Select all

#before exit 0 past the following
(sleep 5;
sudo modprobe lirc_rpi gpio_in_pin=4 gpio_out_pin=7
sleep 5;
sudo -u pi irexec -d
#note: irexec can't run as root. Also note it shuts down if lircd is restarted
)&

(skip the modeprobe line I you are using default pins, and have set `MODULES=lirc_rpi` in hardware.conf)

I think that is about it. Please let me now if you run into any problems. Or if you get it working, of course.
Good luck

Schwabinger
Posts: 49
Joined: Sat Dec 04, 2010 12:04 am
Location: Munich, Germany

Re: Very simple Raspberry Pi Radio

Postby Schwabinger » Sun Dec 09, 2012 11:00 am

Thanks a lot for this detailed description.

Is on my agenda for one of the next weekends!

Schwabinger
Posts: 49
Joined: Sat Dec 04, 2010 12:04 am
Location: Munich, Germany

Re: Very simple Raspberry Pi Radio

Postby Schwabinger » Sun Dec 16, 2012 5:48 am

Just a question: where do I have to integrate the resistor? Between Out and the GPIO-Pin?

Thanks for your help!

Schwabinger

User avatar
gerben
Posts: 164
Joined: Sat Oct 16, 2010 8:41 am
Location: Netherlands

Re: Very simple Raspberry Pi Radio

Postby gerben » Sun Dec 16, 2012 11:47 am

Exactly. Between the IR-out and the GPIO-input pin. Anywhere else will decrease the voltage even more, and the TSOP isn't even rated for 3.3v (only 5V and up).

This is just in case you accidentally set the GPIO pin to output. I don't know how the IR reacts when you apply voltage to the OUT. It could burn out, short, and take the Pi with it. Probably not, but I'm very new to circuit building...

Schwabinger
Posts: 49
Joined: Sat Dec 04, 2010 12:04 am
Location: Munich, Germany

Re: Very simple Raspberry Pi Radio

Postby Schwabinger » Sun Dec 16, 2012 12:38 pm

Thanks for your answer. Just one more question ... the 2.2K ... how did you calculate that value
Greetings

Schwabinger


Return to “Wifi Radio Project / Hacking the Asus WL-520gU”

Who is online

Users browsing this forum: No registered users and 1 guest