Monday, January 14, 2013

Raspberry Pi and Sound Input

If you are a Ham Radio Operator you've probably been looking at the Raspberry Pi with a lot of possibilities.

One of it's downfalls if the lack of an on-board input.  But once you add a USB sound fob, Echolink, remote rig applications, IRLP, and decoding various digital modes like PSK, and so on, are all a reality.

Finding a USB sound device and setting it up can be aggravating.

I recommend the SYBA SD-CM-UAUD USB CM119 audio adapter.

If lsusb doesn't report it as below, you have the wrong one:

root@pi:~# lsusb 
Bus 001 Device 005: ID 0d8c:000e C-Media Electronics, Inc. Audio Adapter (Planet UP-100, Genius G-Talk) 

Next you need to make the usb sound card (0) the default audio device
Check yours like so: cat /proc/asound/modules
0 snd_bcm2835
1 snd_usb_audio

Edit /etc/modprobe.d/alsa-base.conf comment out "options snd-usb-audio index=-2"
You want ""options snd-usb-audio index=0"

After a reboot it should always appear in this order:
0 snd_usb_audio
1 snd_bcm2835

Take this one step further and comment out the kernel module for the onboard sound and add the usb

cat /etc/modules should look like:

While, I did not find the following necessary in my case, I have read to get better latencies out of USB audio devices, it is suggested to also add:

options snd-usb-audio nrpacks=1

Setup /etc/asound.conf to this:

 pcm.dmixer {  
   type dmix  
   ipc_key 1024  
   slave {  
     pcm "hw:0,0"  
     period_time 0  
     period_size 1024  
     buffer_size 8192  
   rate 48000  
   bindings {  
     0 0  
     1 1  
 pcm.asymed {  
     type asym  
     playback.pcm "dmixer"  
     capture.pcm "hw:0,0"  
 pcm.dsp0 {  
   type plug  
   slave.pcm "asymed"  
 pcm.!default {  
     type plug  
     slave.pcm "asymed"  
 pcm.default {  
   type plug  
   slave.pcm "asymed"  
 ctl.mixer0 {  
   type hw  
   card 0  

Since there are some USB issues, I suggest setting the device to boot the USB hub in  USB 1.0 mode, this should fix choppy audio. (I did not find this necessary in my case, but it's not a bad idea)
Add "dwc_otg.speed=1" to /boot/cmdline.txt.

Pulseaudio might be part of your raspberry wheezy default image.  Personally I am not a fan of it, and have read it wasn't working well on the Pi.  I am not sure if that still holds true.  I just removed it:
apt-get purge pulseaudio
I recommend replacing it with Alsa.  It has been around a bit longer:
apt-get install  sox alsa-oss alsa-utils alsa-tools  

Also, I suggest updating the firmware on your Pi.

This should be a good starting point for most.  Hopefully in the future, newer Raspberry wheezy images can make this a bit easier, and more kernel support for other USB sound FOBs.

For my fellow hams you may want to check out these places to congregate:

And for those of you still interested in D-Star: 

I have been running my Pi using a 5 volt, 1 amp supply via the micro USB power port.  I do not use a USB hub.  My model B rev 2 has been running reliably for a few weeks now.

Just as a note.  If you are making connections to the GPIO for keying a radio or whatever, check your local Radio Shack for "Schmartboard Jumpers ."  These are a new thing they are carrying, and are handy.

Sunday, January 6, 2013

Raspberry Pi Autofox?

I stumbled into a wiki on Turning the Raspberry Pi Into an FM Transmitter.

The code uses the hardware on the raspberry pi that is actually meant to generate spread-spectrum clock signals on the GPIO pins to output FM Radio energy.  Just add a quarter wave length of wire to GPIO 4 to act as an antenna.

root@raspberrypi:~# ./pifm
Usage:   program wavfile.wav [freq] [sample rate]

Looking at the source, it seems simple enough to narrow it a bit: 
In pifm.c look for:

float dval = sample*15.0;  // actual transmitted sample.  15 is bandwith (about 75 kHz)

Obviously this isn't a clean transmitter implementation, so don't expect much more than an autofox.

For a low power foxhunt it might amusing to wire a motion sensor to the other GPIO to adjust your transmit and announce timing cycle, when folks are getting close.

{Update 3/13}
Apparently some people think like me:

Plenty of folks using the basis of this for Weak Signal Propagation Reporting


It would also be interesting to use it as a Part 15 FM transmitter with modified code to allow a GPS for transmitter phase locking.