element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Controlling the RDA5807SP FM Radio Receiver with the Raspberry Pi
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: packetgeek
  • Date Created: 19 Jan 2014 6:33 AM Date Created
  • Views 8872 views
  • Likes 3 likes
  • Comments 37 comments
  • raspberry
  • pi
  • fm
  • proof-of-concept
  • radio
Related
Recommended

Controlling the RDA5807SP FM Radio Receiver with the Raspberry Pi

packetgeek
packetgeek
19 Jan 2014

I received a handful of gift certificates for Christmas.  I used one to purchase a few breakout boards, one of them an RDS5807SP-based FM radio receiver (see Amazon.com: FM Radio Receiver Module -- Arduino Compatible: Everything Else).  Although it's designed to work with the Arduino, it is possible to get it working with the Raspberry Pi.  The very nice part is that it comes with an I2C-based control interface.

 

Before you purchase one, there's a few limitations (keep in mind I paid less than $2 for the thing).  In short, the Raspberry Pi provides power and control signals and DOES NOT receive the audio back.  Instead, the audio is output through the headphone jack. (I have "connect to USB sound card" on my to-do list.)

 

In any case, following are my notes on getting it up and running for the first time.  It only took a few hours (4?) in doing the research and

 

1) Parts list

 

  • One Raspberry Pi (with the usual power supply and network connections)
  • One Cobber interface (for connecting the GPIO header to the breadboard)
  • One breadboard (thanks to Drew Fustini!)
  • The aforementioned FM Radio Receiver Module
  • A handful of breadboard wires

 

2) Initially, I attempted to use just the I2C software (described here) that gets installed by running

 

    apt-get install i2c-tools

 

Sadly, I couldn't figure out how to control the receiver with just the i2cset and i2cget commands.  Note: If anyone else plays with this, please omit this step and tell me if installation is still needed.  (I seem to think that it is.)

 

3) Frustrated, I turned to Google.  After some reading, I noticed a few people indicating that the RDA5807xx chip is a clone of the TEA5767, so I went looking for anyone who'd hooked that to the Raspberry Pi.  This led me to Emmanuel Granatello's page on setting up the FM Radio Receiver on Raspberry Pi.   He didn't provide his code, so I kept looking.  I also ran across a number of videos showing the same thing, along with using WiringPi's gpio tool to set up the connection to the receiver.  Mixing all of that together in another search, I finally stumbled across "Raspberry Pi • View topic - I2C, wiringPi & tea5767", which does have the basic code needed to get the receiver working.  Just in case the page disappears, the working code is:

#include <wiringPi.h>

#include <wiringPiI2C.h>

#include <stdio.h>

#include <stdlib.h>

int main( int argc, char *argv[]) {

  printf ("RPi - tea5767 Philips FM Tuner v0.3 \n") ;

  unsigned char radio[5] = {0};

  int fd;

  int dID = 0x60; // i2c Channel the device is on

  unsigned char frequencyH = 0;

  unsigned char frequencyL = 0;

  unsigned int frequencyB;

  double frequency = strtod(argv[1],NULL);

  frequencyB=4*(frequency*1000000+225000)/32768; //calculating PLL word

  frequencyH=frequencyB>>8;

  frequencyL=frequencyB&0XFF;

  printf ("Frequency = "); printf("%f",frequency);

  printf("\n"); // data to be sent

  radio[0]=frequencyH; //FREQUENCY H

  radio[1]=frequencyL; //FREQUENCY L

  radio[2]=0xB0; //3 byte (0xB0): high side LO injection is on,.

  radio[3]=0x10; //4 byte (0x10) : Xtal is 32.768 kHz

  radio[4]=0x00; //5 byte0x00)

 

if((fd=wiringPiI2CSetup(dID))<0){

printf("error opening i2c channel\n\r");

}

write (fd, (unsigned int)radio, 5) ;

return 0;

}

Save the above as "radio.c" and compile it with "gcc -o radio radio.c -lwiringPi".  Credit for the above code goes to "halfluck" on the Raspberry Pi web site.

 

Note: the above code is very limited and doesn't exploit all of the controls available on the chipset.  I plan on expanding the above, once I get a better idea of what's involved.

 

4) Once you've done all of the above, the receiver is connected to the Raspberry Pi, and the Pi has booted, you can test the interface by running "i2cdetect -y 1".  The output should look something like:

  root@raspberrypi:~/work# i2cdetect -y 1
       0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
  00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
  10: 10 11 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
  20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
  30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
  40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
  50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
  60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
  70: -- -- -- -- -- -- -- --  

Note: if you see only dashes in the above, the Pi is not "seeing" the receiver.  Check your connections.  (Initially, I had the Cobbler connected to the header backwards.)

 

If you see only "21 22" in the above, it means that your cable is likely connected properly.  You'll next want to run wiringPi's gpio tool and then the radio application.  I was able to hear a local radio station by running:

 

  gpio load i2c

  gpio i2cd

  ./radio 98.7

 

Note: the first line is required as it (supposedly) renumbers the headers and causes the i2c interface to reset.  The second line is optional.  I use it to "see" when the i2c interface is "online".  When "60" shows up in the output, it's okay to run the "radio" command.  The "98.7" in the above is the frequency (in MHz) of the local radio station.

 

That's about it.  The above code is halfluck's proof-of-concept.  I plan on doing horrible things to it (adding error detection and command line defaults, adding more controls, slapping a web front end on it, etc.), once I've dug into the chip specs and have figured out what the board will and won't support.  I'll eventually get back to editing this code.  Keep an eye out here.

 

Update (26 Dec 2014): The code for the various commands is attached. Updated notes to follow (they're a bit lengthy).

  • Sign in to reply
Parents
  • rohanxtreme
    rohanxtreme over 8 years ago

    Hi Tim,

    Thanks for posting the lovely article.

    I know its a bit dated article but it really helped me understand the internals.

     

    I'm using RPi3 with RASPBIAN JESSIE LITE and a .TEA5767.

     

    I was able to get everything setup from your article (except for the 'gpio load i2c' command which I guess is no longer used).

     

    I get proper output with "i2cdetect -y 1" command (image attached)

    image

     

    I'm also able to Mute & Un-mute as well as check 'status' using your updated code.

    But the problem is, all i hear is static noise and nothing else on any frequency.

     

    Did you encounter this issue while you were working on this project ? If so what do u think might be causing this ?

     

    I'm quiet new to electronics and not very good at soldering; but if i2cdetect is giving proper output that means all the connections are correct. Do we have to do any changes to code because of the updated internals of i2c for RPi ?

     

    Any suggestions would be highly appreciated image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • packetgeek
    packetgeek over 8 years ago in reply to rohanxtreme

    Rohan,

     

    Hearing static is a good sign.  I'm guessing but it might be a typo in the tune function.  Does the sound of static change with different frequencies?  If you change frequencies with the tune function, does the status function report the proper frequency?  Are you using headphones (which also act as the antenna)?

     

    If all else fails, you can attach your code here and I'll try it.

     

    - Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rohanxtreme
    rohanxtreme over 8 years ago in reply to packetgeek

    Hi Tim,

    The sound never changes irrespective of me sending the frequency explicitly (using radio2) or using the search-up & search-down feature.

    Every time I change the frequency and call the status function I always get the correct frequency back.

     

    I used headphones directly too as well as used a Amplifier module (PAM8403)  for speakers but both gave same result.

     

    As for using headphones as antennas,Nop... I have a separate 4 ft solid insulated wire which I'm using as Antenna.

     

    I used SUDO too.. but got the same output. As for the code... I'm using the same code you have uploaded in the article. 

     

    Just on a side note...it might be totally irrelevant.... but,

    1. I get small break in static when I type in my RPi.

    2. To connect the output/amplifier I used the same 'ground' connection (i.e. Pin 6)

    3. I checked the RPi docs/blogs and from my reading I came to know 'gpio load i2c' is no longer needed.

     

    Do u think there might be any fault with the chip or a issue with my soldering (I'm extremely newb when it comes to that)  ?

     

    Thanks again for the post and the reply regards, .

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to rohanxtreme

    Hi Rohan,

     

    You might want to have the board about 10cm or so away from the Pi, and disconnect the PAM8403 board for now (i.e. totally unpower it, not just disconnect the audio input), and insert headphones.

    If there is any improvement, then there is electrical noise which is interfering with your radio receiver. The noise between stations will likely

    sound the same, but if you tune to a known station then it should improve.

    If you get that far, then we can try to address ways to reduce the noise and increase the immunity to it.

    Also, a photo of your set-up will help.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • packetgeek
    packetgeek over 8 years ago in reply to rohanxtreme

    Because they're separate binaries, if the status command returns the same frequency as that provided to the tune command, the software is likely to be working correctly.  You may want to use "gpio readall" before and after running any code.

     

    It might just be a physical issue (solder joint issue or chip damage) or signal strength issue (the antenna gain with the headphones is quite poor).

     

    - Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rohanxtreme
    rohanxtreme over 8 years ago in reply to shabaz

    Hi Shabaz,

    I think my board and Pi were fairly at a distance.

    Also; I think during my first iteration I had used the output direxctly, but I don't remember exactly.

     

    I'll retry both the suggestions provided by you as soon as I get back home.

    Will update the thread with my findings soon.

     

    Thanks again for the suggestion

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rohanxtreme
    rohanxtreme over 8 years ago in reply to packetgeek

    Hi Tim,

    That's exactly what I was  thinking about the code  too...

    The only doubt was if RPi itself might have changed the architecture and that might have altered the way things work.

     

    I'll try the 'readall' function too as well as check my soldering's as well.

     

    Signal strength might be a issue in my area; I checked with my mobile and was able to receive atleast 3 stations of 12. So I guess my TEA should also be able to pickup those 3 stations atleast.

     

    I'll update the thread with the results once I'm back home in few days.

     

    Thanks again for the post and the tips image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • rohanxtreme
    rohanxtreme over 8 years ago in reply to packetgeek

    Hi Tim,

    That's exactly what I was  thinking about the code  too...

    The only doubt was if RPi itself might have changed the architecture and that might have altered the way things work.

     

    I'll try the 'readall' function too as well as check my soldering's as well.

     

    Signal strength might be a issue in my area; I checked with my mobile and was able to receive atleast 3 stations of 12. So I guess my TEA should also be able to pickup those 3 stations atleast.

     

    I'll update the thread with the results once I'm back home in few days.

     

    Thanks again for the post and the tips image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • packetgeek
    packetgeek over 8 years ago in reply to rohanxtreme

    Any luck?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rohanxtreme
    rohanxtreme over 8 years ago in reply to packetgeek

    Hi Tim,

    I was able to put in some time late night.

     

    I purchased a new TEA5767 and re-soldered all the connections from scratch and to my surprise it worked in the first go itself.

    The reception in my area is not good so had to use about a 15ft wire as antenna but the results were awesome.

    Even the amp worked and was able to listen to multiple channels for about 30-40 min.

     

    Unfortunately after which it all died-out.

    I restarted Pi and used 'i2cdetect' but didn't get the "60" value as I was getting previously.

    I think I somehow was able to fry the whole thing [:(]

     

    I'm not sure what happened. There is no physical damage I can see.

    Any ideas/precautions you guys think I should take to ensure this does not happen again ?

    (PS.. I was extremely careful about my solders this time... so we can ignore that possibility..plus it was working for a good while)

     

    I'll upload a pic of my setup (now dead setup ) in a day or two.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • packetgeek
    packetgeek over 8 years ago in reply to rohanxtreme

    Rohan,

     

    I enjoyed working with these boards.  I managed to acquire: TEA5767, Si4703, Si4707, RDA5807SP, and the Si4735.  The first four were acquired from Amazon, the Si4735 from eBay.  The easiest to work with was the TEA5767 (and RDA5807 in TEA5767 mode).  The Si4703 was also fun in that it has RDS capability (though I need to put more time in on the RDS decoder).  I've managed to control the TEA5767 to a Raspberry Pi and a Cubietruck.  I'm trying to work out how to connect it to a NodeMCU so that I can control it via Wi-Fi (and not tie up a RPi or the Cubietruck).  I've connected all of them to an old Squeezebox without issue.

     

      Keeping in mind that the receiver boards are designed to drive cheap headphones, there's a couple possibilities (I'm guessing here):

     

    1) Static electricity (from handling or even through the antenna)

     

    About the only countermeasure is care in handling. 

     

    2) Issues with the connection to the amplifier

     

    I'm thing that there might be sufficient impedance mismatch that the receiver is stressed enough that it stops working after awhile.  If it happens to your third board, this is a likely concern.  When it was working, was the receiver chip warm? 

     

    There may also be some sort of voltage feedback.  If you're using two separate power supplies, you might have a floating ground issue.

     

    I'm hoping that you have better luck with your effort.  For your next one, I'd recommend running the reciever, without the amplifier, for a few days.

     

    - Tim

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • rohanxtreme
    rohanxtreme over 8 years ago in reply to packetgeek

    Hi Tim,

    Thanks for the feedback...

    Wow.. seems like you've invested a good amount of time in to theses ...

     

    As for the amp, I had connected it to  one of the USB ports on Pi itself.

     

    For ground well, I had connected the TEA & Amp to Pi's ground so nothing special so to speak.

    Next time i'll just connect the 3.5 mm female to the TEA output, the only problem I see is that the volume was extremely low when I had tried that setup (during the first try when I was getting only static).

     

    But I guess it will be a good way to check if AMP was the culprit or not.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • packetgeek
    packetgeek over 8 years ago in reply to rohanxtreme

    Any luck?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube