User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

FM Transmitter dongle + software for your Pi :)

Fri Dec 21, 2012 10:05 am

There already exists a software based Pi FM transmitter and while this is very clever stuff it does have limitations though i.e. lack of stereo support and poor audio quality.
If you're interested in streaming high quality music via a FM Radio then all you need is a USB FM transmitter dongle based on the B-Link chipset.

I own one for my Pi and it has become my main way of streaming Digitally Imported music around my house and back garden. :)

They come under different names i.e. Keene, B-Link or unbranded all the same internals but have near identical black casings with lettering and 2 metal strips.
One of the metal strips hides a loose wire this you can attach to a proper antenna to boost your signal strength.

Keene sell them for £15 - http://www.keene.co.uk/multi.php?mycode=USBFMT *
*Keene have discontinued this product and have no plans to import more dongles.
I've seen some sold on Amazon or eBay however I would imagine you would have to bid for them now.

Or on eBay around £5 - http://www.ebay.co.uk/itm/230669438036? and usually shipped from China / Hong Kong **
** Sadly the only eBay seller has increased his original asking price 4 fold $33 / £20, not only that but he does not ship to UK or Europe (USA is fine).
For what it's worth the FMBerry project with MMR-60 would be a much cheaper alternative, however this device does require an analogue input signal.

As it stands B-Link doesn't provide software support for Linux however there exists a 3rd party tool you can download and compile on the Pi - https://github.com/kenchy/keene-usb-audio
Unfortunately there are many features missing from this tool i.e. no mono / stereo switching, 75us pre-emphasis(treble boost) mixer volume control and tx power control etc.
So today I took the liberty of re-writing most of the code to enable all the missing features - http://pastebin.com/bZs8NYjW (copy and paste the text to a file called fmtx.c)
Currently the transmission range is set between 87.5MHz to 108MHz it is possible to edit the source code and extend this all the way down to 76MHz providing you're legally allowed to do so.

As for playing music you just need to select "B-Link" as your audio device (in qmmp you'll need ALSA Plugin set to sysdefault:CARD=Audio otherwise the music plays at the wrong speed).
For mocp (Music On Console) to use the B-Link audio device you need to create the file config in your .moc folder with the following line: AlsaDevice = "hw:1,0"

Enjoy.

Richard S.
Last edited by redhawk on Sat Dec 14, 2013 6:05 pm, edited 1 time in total.

JustThisGuy
Posts: 114
Joined: Thu Jan 05, 2012 11:22 pm

Re: FM Transmitter dongle + software for your Pi :)

Fri Dec 21, 2012 9:42 pm

Thanks, redhawk. I just scarfed a few of these from ebay and am looking forward to playing with them when they arrive.
Any conversation about a sufficiently complex subject is indistinguishable from babble.

jazzy
Posts: 11
Joined: Tue Feb 26, 2013 12:06 am

Re: FM Transmitter dongle + software for your Pi :)

Tue Feb 26, 2013 11:32 pm

I can't seem to get this to work on raspbmc. I just get errors when trying to apt-get all of the things.

Should I be using different commands?

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: FM Transmitter dongle + software for your Pi :)

Tue Feb 26, 2013 11:52 pm

I don't use Raspbmc anymore however the follow post may provide useful regarding external USB audio dongles - http://forum.stmlabs.com/showthread.php ... 4#pid36764
If you can get it to work in XBMC (it should appear as B-Link or Logitech) then the only thing missing would be the FM transmitter software to set the frequency output.
There's no "apt-get install" for this because it's unofficial unsupported 3rd party software (or are you referring to libusb-dev??).
All instructions on how to compile is already included in the source code whether it works in Raspbmc would depend on how stripped down their operating system is.

Richard S.

jazzy
Posts: 11
Joined: Tue Feb 26, 2013 12:06 am

Re: FM Transmitter dongle + software for your Pi :)

Tue Feb 26, 2013 11:59 pm

When I mentioned apt-get install,

I was referring to update, upgrade and libusb-dev


At first I was running Weezy and was running into dependancy issues with XBMC , So i figured raspbmc would be easier.

User avatar
pauly
Posts: 12
Joined: Sat Mar 09, 2013 7:14 am
Location: Kent
Contact: Website

Re: FM Transmitter dongle + software for your Pi :)

Sat Mar 09, 2013 7:23 am

I'm getting this error trying this with mpg123 for mp3 playing from the command line:

Code: Select all

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.BRCM bcm2835 AL.pcm.front.0:CARD=0'
ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM front
what am I missing? Just something to do with setting the new B-Link / Keene usb device as the default audio device. Is there a command line option to pass to mpg123 to do this?

Thanks in advance if anyone can help.

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: FM Transmitter dongle + software for your Pi :)

Sat Mar 09, 2013 1:09 pm

I don't use mpg123 but I understand you need the -a option to output to a different audio device.
The B-Link should be assigned to card1 so you will need something like: mpg123 -a hw:1,0 myfile.mp3

If you still cannot get mpg123 to work then run aplay -l and find out if the B-Link device is listed and as which card number.

Richard S.

User avatar
pauly
Posts: 12
Joined: Sat Mar 09, 2013 7:14 am
Location: Kent
Contact: Website

Re: FM Transmitter dongle + software for your Pi :)

Sat Mar 09, 2013 10:30 pm

redhawk wrote:I don't use mpg123 but I understand you need the -a option to output to a different audio device.
The B-Link should be assigned to card1 so you will need something like: mpg123 -a hw:1,0 myfile.mp3
Perfectamundo, thanks a lot for your help.

I'm building a music player for my car, I will report back when I'm done.
pi@raspberrypi ~/radiopi $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 1: Audio [B-LINK USB Audio], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi@raspberrypi ~/radiopi $ mpg123 -a hw:1,0 /mnt/Music/Various/Adam\ and\ Joe/00\ -\ Adam\ Buxton\;\ Joe\ Cornish\ -\ Pirate_Classical.mp3
bin/ .git/ lib/ test/
pi@raspberrypi ~/radiopi $ mpg123 -a hw:1,0 /mnt/Music/Various/Adam\ and\ Joe/00\ -\ Adam\ Buxton\;\ Joe\ Cornish\ -\ Pirate_Classical.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
Title : Pirate_Classical Artist : Adam Buxton/Joe Cornish
Album : Adam and Joe Year :
Comment : 00000143 000000D3 000008F0 00 Genre : Comedy; Radio; Ringtone

Directory: /mnt/Music/Various/Adam and Joe
Playing MPEG stream from 00 - Adam Buxton; Joe Cornish - Pirate_Classical.mp3 ...
MPEG 1.0 layer III, 320 kbit/s, 44100 Hz joint-stereo

[0:08] Decoding of 00 - Adam Buxton; Joe Cornish - Pirate_Classical.mp3 finished.

AlexF1980
Posts: 3
Joined: Tue Jul 17, 2012 1:50 pm

Re: FM Transmitter dongle + software for your Pi :)

Wed Mar 13, 2013 10:08 pm

Woo hoo!

Thanks to the post(s) by redhawk and this page:

http://maketecheasier.com/play-mp3s-fro ... 2011/08/11

I am currently sat listening to "Real Eyes, Realize, Real Lies" by Machine Head streaming from my raspberry pi to my roberts radio on 88.00MHz.

This is awesome!

bullwinkle
Posts: 117
Joined: Wed Jan 09, 2013 12:14 pm

Re: FM Transmitter dongle + software for your Pi :)

Thu Aug 22, 2013 4:56 pm

redhawk wrote: So today I took the liberty of re-writing most of the code to enable all the missing features
Enjoy.
Richard S.
Hi and thanks for that.
It works for me and in fact I am very surprised with the results. For me, quick, easy, cheap and for the sound quality this gives I think it is a very viable solution. Currently running
  • Keene USB FM Transmitter
    MPD/MPC with Python & custom pygame music player
    2.8" TFT (thanks to Texy and Notro)
    MPDroid

mnoit
Posts: 8
Joined: Sat Aug 24, 2013 10:18 am
Location: Lille France

Re: FM Transmitter dongle + software for your Pi :)

Sat Aug 24, 2013 12:26 pm

Keene states that the tx power is 50nW.
As far as I know, there is a EC recommendation that allows this kind of device, up to 80nW.
Assuming this is the relevant line in the code, does it mean 120nW?

Code: Select all

int tx_pmax = 0x78; // 120
There's no "apt-get install" for this because it's unofficial unsupported 3rd party software
When I get one, I can try to package it. This means getting the original author and yourself agreeing on a DFSG-free license, eg GPL or BSD, to push it to debian.
http://people.debian.org/~bap/dfsg-faq.html

birdman
Posts: 21
Joined: Fri Nov 04, 2011 1:11 am
Contact: Website

Re: FM Transmitter dongle + software for your Pi :)

Thu Sep 12, 2013 7:57 pm

Brillaint, thanks.
I moved things around at home last night with the intention of getting this set-up to run from my RasPi (hence avoiding having to play straight through the metal-encased fridge on line of sight to the radio on the kitchen - not good for reception).
However, the keenectl didn't get it working. (It could talk to the USB sitck, but no broadcast reached the kitchen).
I've just tried this, and it works beautifully. mplayer can now play the BBC radio streams (our FM reception is poor, and don't even think about DAB).

BTW: the code mentions you need root to run it. You don't. You need write access to the device, which is not the same thing.
It's easy to set up udev to set the permission on the device so that you can manage it as yourself.

Add this file to /etc/udev/rules.d (call it 10-Keene-FM.rules, or similar):

Code: Select all

# The Keene FM USB dongle...
#
ATTRS{manufacturer}=="HOLTEK ", ATTRS{product}=="B-LINK USB Audio  ", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0a0e", MODE:="0660", GROUP:="audio", RUN+="/usr/bin/keenectl-init"
Then
  • create that /usr/bin/keenectl-init to run your command to set the freq, volume. etc., if you wish (or set it off until you need it)
    add yourself (plus any other accounts that need it) in the audio group.

birdman
Posts: 21
Joined: Fri Nov 04, 2011 1:11 am
Contact: Website

Re: FM Transmitter dongle + software for your Pi :)

Thu Sep 12, 2013 8:07 pm

>> However, the keenectl didn't get it working.

I forgot to mention where that came from (since it isn't the link you mentioned),.

This is from http://blog.mister-muffin.de/2011/03/14 ... ansmitter/
It worked fine on an Intel x64 system, and on a Plug, but not with the RasPi.

Here is a patch for the code, to stop is generating unnecessary syslog message, and to format some output with a missing new.line.

Code: Select all

--- keenectl.c.orig     2011-03-08 15:14:09.000000000 +0000
+++ keenectl.c  2013-01-26 00:05:30.841561410 +0000
@@ -52,7 +52,12 @@
                 fprintf(stderr, "error code: %d, message: %s\n", ret, strerror(ret));
         }
     } else {
+#ifdef ORIG_CODE
         fprintf(stderr, "successfully wrote %d bytes\n", ret);
+#else
+/* So we can redirect this but still see errors... */
+        fprintf(stdout, "successfully wrote %d bytes\n", ret);
+#endif
     }
 
     return ret;
@@ -94,6 +99,7 @@
         return 1;
     }
 
+#ifdef ORIG_CODE
     usb_handle = usb_open(usb_dev);
     if (usb_handle == NULL) {
         fprintf(stderr,
@@ -101,6 +107,27 @@
         usb_close(usb_handle);
         return 1;
     }
+#else
+
+/* Opening and claiming are successive, different stages (apparently)
+ * And we must claim interface 2 to stop getting syslog message like this:
+ *  kernel: usb 1-1.4: usbfs: process 16388 (keenectl) did not claim interface 2 before use
+ */
+
+    int err;
+    usb_handle = usb_open(usb_dev);
+    if (usb_handle == NULL) {
+        fprintf(stderr,
+             "Not able to open the USB device\n");
+        return 1;
+    }
+    if ((err = usb_claim_interface(usb_handle, 2))) {
+        fprintf(stderr,
+             "usb_claim_interface returned an error (%d)\n", err);
+        usb_close(usb_handle);
+        return 1;
+    }
+#endif
 
     if (argc != 8) {
         fprintf(stderr,
@@ -208,7 +235,7 @@
     } else if (!strcasecmp(argv[6], "disable")) {
         conf1[5] |= DISABLE;
     } else {
-        fprintf(stderr, "must be enable or disable");
+        fprintf(stderr, "must be enable or disable\n"); /* GML - add \n */
         return 1;
     }
 
@@ -235,7 +262,12 @@
         return 1;
     }
 
+#ifdef ORIG_CODE
     fprintf(stderr, "success! try playing audio eg. using `mplayer -ao alsa:device=hw=1.0 ...`\n");
-
+#else
+/* So we can redirect this but still see errors... */
+    fprintf(stdout,
+ "success! try playing audio eg. using `mplayer -ao alsa:device=hw=1.0 ...`\n");
+#endif
     return 0;
 }

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: FM Transmitter dongle + software for your Pi :)

Thu Sep 12, 2013 9:22 pm

int tx_pmax = 0x78; // 120
Keene states that the tx power is 50nW.
As far as I know, there is a EC recommendation that allows this kind of device, up to 80nW.
Assuming this is the relevant line in the code, does it mean 120nW?
To reverse engineer communications I used a USB sniffer program called Bus Hound the values of 30 and 120 were obtained from the Windows application as I changed the signal strength.
Whether these values are directly linked to nW of power I don't know but from what I can tell with my own dongle it does nothing to the actual power output except being high strength or low strength.

Btw thanks for info regarding running as a non-root account I've always wondered about a work around but my knowledge of handling Linux drivers is somewhat limited as is my coding in C. :)

Richard S.

neveryawns
Posts: 1
Joined: Fri Apr 10, 2015 9:50 pm

Re: FM Transmitter dongle + software for your Pi :)

Fri Apr 10, 2015 9:52 pm

I'm getting a high pitch tone when I tune to the frequency on a radio. Any ideas?

Edit: I Figured it out... I had two problems:
I didn't know that aplay couldn't play .mp3's
I set fmtx to v5 and it solved the issue

Return to “Add-ons”

Who is online

Users browsing this forum: No registered users and 5 guests