Listen to the Radio from ANYWHERE

Since I moved to South Florida I’ve noticed that there aren’t any appropriate radio stations anywhere down here. They’re all mindless Clear Channel-type Top 40 or country stations. Unacceptable. There weren’t this many country stations when I lived in South Carolina or Tennessee. Anyway! I thought maybe I could build a radio that would get radio stations from far away, and it would let me listen to independently-owned and happily non-country stations 105.5 The Bridge from Charleston and Lightning 100 from Nashville.

My idea was to interface a parallel port port in a computer to a set of buttons. Each button would launch Firefox which would then load the online stream of one of these stations. The computer controlling it would be headless and hidden, so the visible hardware would look and perform just like a regular radio. The only downside to this is that I can’t get 95.7 The Ride out of Charlotte with this build because they don’t have an online stream anymore.

At boot, the computer executes a script that starts a C program called “launcher”. The C program is necessary to take control of the printer port, and therefore it must be run as root. To allow the computer to execute the script as root, I added the following line to the sudoer’s file with the command “sudo visudo”:

ALL    ALL = (root) NOPASSWD: /home/bryan/programs/radio/launcher

The script is very simple:

#!/bin/bash
sudo /home/bryan/programs/radio/launcher

I also ran “chmod 755 startup.sh” on the script to make it executable. Next is the C program that will actually handle the parallel port and launch the browser when a button press is detected:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#include <time.h>

#define base 0x378 // printer port base address
#define status 0x379 //printer port status register

//Define button push events. Status register default 0x78 = 0b01111000.
#define PUSH1 0x70 //0x70 = 0b01110000
#define PUSH2 0x68 //0x68 = 0b01101000

int A=1;
int lastA=0;
int B=1;
int lastB=0;
int regval=0;
int lastregval=1;

int main(int argc, char **argv) {
//make sure the program has access to the parallel port
if (ioperm(base,1,1))
fprintf(stderr, "Couldn't get the port at %xn", base), exit(1);
if (ioperm(status,1,1))
fprintf(stderr, "Couldn't get the port at %xn", status), exit(1);

//write 0b00000001 to the output lines to get +5V for the switches
outb(1, base);

while(1) { //run forever
//print status register if and only if it changes
/* regval=inb(status);
if(regval != lastregval) {
printf("%xn",regval);
lastregval=regval;
} */

if (inb(status)==PUSH1 && A!=lastA) {
//enable other button pushes
B++;
// printf("button 1 pushed!n");
//call script
system("/bin/bash /home/bryan/programs/radio/script1.sh");
//disable a second button 1 push event to debounce and to
//prevent closing of browser and opening the same page it was on
A=lastA;
}

if (inb(status)==PUSH2 && B!=lastB) {
//enable other button pushes
A++;
// printf("button 2 pushed!n");
system("/bin/bash /home/bryan/programs/radio/script2.sh");
//disable a second button 2 push event to debounce and to
//prevent closing of browser and opening the same page it was on
B=lastB;
}
}
}

No problem. I complied it using “gcc -O launcher.c -o launcher”. Compiling with these options is necessary for proper functionality of the parallel port.

This program only handles two stations now but it could be expanded for more if 95.7 WXRC ever decided to have an online stream again. I believe the next step is to program this on my Raspberry Pi when it gets here, and install it in the radio that I have that has been the subject of previous posts on this blog. I think I could rewire the memory buttons on the radio to be inputs to the Pi and have the radio display “105.5” or “100.1” on its LCD. This has some potential! If anyone has some tips on how I can be a better programmer, I am open to those suggestions. I’m an engineer, not a computer scientist.

Join the Conversation

2 Comments

Leave a comment

Your email address will not be published. Required fields are marked *