---

Showing posts with label si4703. Show all posts
Showing posts with label si4703. Show all posts

Friday, September 16, 2011

New Arduino Library for Sparkfun Si4703 FM Receiver Breakout Board

The Sparkfun Si4703 FM Receiver Breakout Board is a great little FM radio, complete with RDS and a 100mW stereo amp.



There is example code for using it and top marks to Nathan Seidle from Sparkfun for working out how to use the pesky thing from the largely opaque datasheet for the receiver chip.

I have been making myself the 'ultimate' FM receiver. Arduino-based and using nice controls, solar-charging of battery with charging data and an LCD display for the RDS data. I will post on this when its finished.

The software engineer in me railed at just hacking away at Nathan's example. So I put his code in a library and also fixed some of the problems with RDS and did a bit of tidying.

You can download it from here. Continuing Nathan's licensing arrangement, I also offer it as 'Beer-ware'. If you are feeling extremely grateful then by all means buy one of my books (see right panel).

Here is an example app, just connect up the three pins at the top of the sketch but remember Vcc for the breakout board is 3.3V NOT 5V. 5V will kill it:


#include <Si4703_Breakout.h>
#include <Wire.h>


int resetPin = 2;
int SDIO = A4;
int SCLK = A5;


Si4703_Breakout radio(resetPin, SDIO, SCLK);
int channel;
int volume;
char rdsBuffer[10];


void setup()
{
  Serial.begin(9600);
  Serial.println("\n\nSi4703_Breakout Test Sketch");
  Serial.println("===========================");  
  Serial.println("a b     Favourite stations");
  Serial.println("+ -     Volume (max 15)");
  Serial.println("u d     Seek up / down");
  Serial.println("r       Listen for RDS Data (15 sec timeout)");
  Serial.println("Send me a command letter.");
  


  radio.powerOn();
  radio.setVolume(0);
}


void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch == 'u') 
    {
      channel = radio.seekUp();
      displayInfo();
    } 
    else if (ch == 'd') 
    {
      channel = radio.seekDown();
      displayInfo();
    } 
    else if (ch == '+') 
    {
      volume ++;
      if (volume == 16) volume = 15;
      radio.setVolume(volume);
      displayInfo();
    } 
    else if (ch == '-') 
    {
      volume --;
      if (volume < 0) volume = 0;
      radio.setVolume(volume);
      displayInfo();
    } 
    else if (ch == 'a')
    {
      channel = 930; // Rock FM
      radio.setChannel(channel);
      displayInfo();
    }
    else if (ch == 'b')
    {
      channel = 974; // BBC R4
      radio.setChannel(channel);
      displayInfo();
    }
    else if (ch == 'r')
    {
      Serial.println("RDS listening");
      radio.readRDS(rdsBuffer, 15000);
      Serial.print("RDS heard:");
      Serial.println(rdsBuffer);      
    }
  }
}


void displayInfo()
{
   Serial.print("Channel:"); Serial.print(channel); 
   Serial.print(" Volume:"); Serial.println(volume); 
}



Here is the public part of the class definition.


class Si4703_Breakout
{
  public:
    Si4703_Breakout(int resetPin, int sdioPin, int sclkPin);
    void powerOn(); // call in setup
void setChannel(int channel);   // 3 digit channel number
int seekUp(); // returns the tuned channel or 0
int seekDown();
void setVolume(int volume); // 0 to 15
void readRDS(char* message, long timeout);
// message should be at least 9 chars
// result will be null terminated
// timeout in milliseconds




About the Author
These are my books. Click on the image below to find out more about them.