RDA5807M Radio

RDA5807M 腳位配置圖

http://goods.ruten.com.tw/item/show?21643107650948

Arduino NANO 腳位配置圖

關於I2C腳位,Arduino UNO 與 NANO SDA腳都在A4 SCL腳都在A5

Arduino UNO 腳位配置圖

關於I2C腳位,Arduino UNO 與 NANO SDA腳都在A4 SCL腳都在A5

接線圖

Arduino 與 RDA5870M 需靠四條線連接 3.3V GND SDA SCL

另兩條灰線可以連接音訊擴大器到喇叭輸出

AHTEHA是天線,直接拉出來

PAM8403 音訊功率放大模組

http://goods.ruten.com.tw/item/show?21444615471874
http://goods.ruten.com.tw/item/show?21444615471874

1602 I2C LCD 模組

基本程式碼

/*

* RDA5807M Example Sketch

*

* This example sketch illustrates how to use some of the basic commands in the

* RDA5807M Library. The sketch will start the RDA5807M in West-FM mode

* (87-108MHz) and then wait for user commands via the serial port.

* More information on the RDA5807M chip can be found in the datasheet.

*

* HARDWARE SETUP:

* This sketch assumes you are using the RRD-102 (V2.0) breakout board.

*

* The board should be connected to a 3.3V Arduino's I2C interface.

* Alternatively, a 5V Arduino can be used if a proper I2C level translator is

* used (see the README for an example).

* You will need an audio amplifier as the RDA5807M is too weak to directly drive

* a pair of headphones. Immediate candidates would be a pair of active

* (multimedia) speakers that you're probably already using with your computer.

* You will also need a proper antenna connected to breakout board. Luckily

* for you, this is a very forgiving chip when it comes to "proper" antennas,

* so for FM only you will be able to get away with just a 2ft (60cm) length of

* wire connected to the FM antenna pad on the shield. Decent results can

* probably be obtained using a 6" breadboard jumper wire too.

*

* USING THE SKETCH:

* Once you've connected the RRD-102 to your Arduino board (and antenna(s), as

* appropriate), connect the Arduino to your computer, select the corresponding

* board and COM port from the Tools menu and upload the sketch. After the sketch

* has been updated, open the serial terminal using a 9600 baud speed. The sketch

* accepts single character commands (just enter the character and press 'send').

* Here is a list of the acceptable commands:

* v/V - decrease/increase the volume

* s/S - seek down/up with band wrap-around

* m/M - mute/unmute audio output

* f - display currently tuned frequency

* q - display RSSI for currently tuned station

* t - display decoded status register

* ? - display this list

*

*/

//Due to a bug in Arduino, this needs to be included here too/first

#include <Wire.h>

//Add the RDA5807M Library to the sketch.

#include <RDA5807M.h>

//Create an instance of the RDA5807M named radio

RDA5807M radio;

//Other variables we will use below

char command;

word status, frequency;

void setup()

{

//Create a serial connection

Serial.begin(9600);

//Initialize the radio to the West-FM band. (see RDA5807M_BAND_* constants).

//The mode will set the proper receiver bandwidth.

radio.begin(RDA5807M_BAND_WEST);

}

void loop()

{

//Wait until a character comes in on the Serial port.

if(Serial.available()){

//Decide what to do based on the character received.

command = Serial.read();

switch(command){

case 'v':

if(radio.volumeDown()) Serial.println(F("Volume decreased"));

else Serial.println(F("ERROR: already at minimum volume"));

Serial.flush();

break;

case 'V':

if(radio.volumeUp()) Serial.println(F("Volume increased"));

else Serial.println(F("ERROR: already at maximum volume"));

Serial.flush();

break;

case 's':

Serial.println(F("Seeking down with band wrap-around"));

Serial.flush();

radio.seekDown();

break;

case 'S':

Serial.println(F("Seeking up with band wrap-around"));

Serial.flush();

radio.seekUp();

break;

case 'm':

radio.mute();

Serial.println(F("Audio muted"));

Serial.flush();

break;

case 'M':

radio.unMute();

Serial.println(F("Audio unmuted"));

Serial.flush();

break;

case 'f':

frequency = radio.getFrequency();

Serial.print(F("Currently tuned to "));

Serial.print(frequency / 100);

Serial.print(".");

Serial.print(frequency % 100);

Serial.println(F("MHz FM"));

Serial.flush();

break;

case 'q':

Serial.print(F("RSSI = "));

Serial.print(radio.getRSSI());

Serial.println("dBuV");

Serial.flush();

break;

case 't':

status = radio.getRegister(RDA5807M_REG_STATUS);

Serial.println(F("Status register {"));

if(status & RDA5807M_STATUS_RDSR)

Serial.println(F("* RDS Group Ready"));

if(status & RDA5807M_STATUS_STC)

Serial.println(F("* Seek/Tune Complete"));

if(status & RDA5807M_STATUS_SF)

Serial.println(F("* Seek Failed"));

if(status & RDA5807M_STATUS_RDSS)

Serial.println(F("* RDS Decoder Synchronized"));

if(status & RDA5807M_STATUS_BLKE)

Serial.println(F("* RDS Block E Found"));

if(status & RDA5807M_STATUS_ST)

Serial.println(F("* Stereo Reception"));

Serial.println("}");

Serial.flush();

break;

case '?':

Serial.println(F("Available commands:"));

Serial.println(F("* v/V - decrease/increase the volume"));

Serial.println(F("* s/S - seek down/up with band wrap-around"));

Serial.println(F("* m/M - mute/unmute audio output"));

Serial.println(F("* f - display currently tuned frequency"));

Serial.println(F("* q - display RSSI for current station"));

Serial.println(F("* t - display decoded status register"));

Serial.println(F("* ? - display this list"));

Serial.flush();

break;

}

}

}

由上述程式碼可整理出下列動作函式:

1. radio.volumeDown() 降低音量

2. radio.volumeUp() 提高音量

3. f=radio.getFrequency() 得到頻率

Serial.print(F("Currently tuned to "));

Serial.print(frequency / 100);

Serial.print(".");

Serial.print(frequency % 100);

Serial.println(F("MHz FM"));

4. radio.mute()

5.radio.unMute()

6.radio.getRSSI()

7. status = radio.getRegister(RDA5807M_REG_STATUS);

Serial.println(F("Status register {"));

if(status & RDA5807M_STATUS_RDSR)

Serial.println(F("* RDS Group Ready"));

if(status & RDA5807M_STATUS_STC)

Serial.println(F("* Seek/Tune Complete"));

if(status & RDA5807M_STATUS_SF)

Serial.println(F("* Seek Failed"));

if(status & RDA5807M_STATUS_RDSS)

Serial.println(F("* RDS Decoder Synchronized"));

if(status & RDA5807M_STATUS_BLKE)

Serial.println(F("* RDS Block E Found"));

if(status & RDA5807M_STATUS_ST)

Serial.println(F("* Stereo Reception"));

8. radio.seekDown();

9. radio.seekUp();

收音機程式碼 第一版

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3f,16,2);

//Add the RDA5807M Library to the sketch.

#include <RDA5807M.h>

//Create an instance of the RDA5807M named radio

RDA5807M radio;

//Other variables we will use below

char command;

word status, frequency;

int Vol = 0;

void setup()

{

//Create a serial connection

Serial.begin(9600);

pinMode(12,INPUT);

pinMode(9,INPUT);

pinMode(6,INPUT);

pinMode(3,INPUT);

pinMode(10,OUTPUT);

pinMode(7,OUTPUT);

pinMode(4,OUTPUT);

pinMode(2,OUTPUT);

digitalWrite(10,1);

digitalWrite(7,1);

digitalWrite(4,1);

digitalWrite(2,1);

lcd.init();

lcd.backlight();

lcd.clear();

radio.begin(RDA5807M_BAND_WEST);

delay(50);

radio.seekDown();

delay(50);

radio.seekUp();

delay(50);

frequency=radio.getFrequency(); // 得到頻率

lcd.setCursor(0,0);

lcd.print(F("FM "));

lcd.print(frequency / 100);

lcd.print(".");

lcd.print(frequency % 100);

lcd.print(" MHz");

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

radio.volumeDown() ;

lcd.setCursor(0,1);

lcd.print(F("Vol "));

lcd.print(Vol);

lcd.print(" ");

}

void loop(){

if(digitalRead(12)==1&&digitalRead(9)==0&&digitalRead(6)==0&&digitalRead(3)==0){

delay(100);

if(digitalRead(12)==1){

radio.seekDown();

frequency=radio.getFrequency(); // 得到頻率

lcd.setCursor(0,0);

lcd.print(F("FM "));

lcd.print(frequency / 100);

lcd.print(".");

lcd.print(frequency % 100);

lcd.print(" MHz");

lcd.print(" ");

delay(500);

}

}

if(digitalRead(9)==1&&digitalRead(12)==0&&digitalRead(6)==0&&digitalRead(3)==0){

delay(100);

if(digitalRead(9)==1){

radio.seekUp();

frequency=radio.getFrequency(); // 得到頻率

lcd.setCursor(0,0);

lcd.print(F("FM "));

lcd.print(frequency / 100);

lcd.print(".");

lcd.print(frequency % 100);

lcd.print(" MHz");

lcd.print(" ");

delay(500);

}

}

if(digitalRead(6)==1&&digitalRead(12)==0&&digitalRead(9)==0&&digitalRead(3)==0){

delay(100);

if(digitalRead(6)==1){

if(radio.volumeDown()){

Vol=Vol-10 ;

}else{

Vol=0;

}

frequency=radio.getFrequency(); // 得到頻率

lcd.setCursor(0,1);

lcd.print(F("Vol "));

lcd.print(Vol);

lcd.print(" ");

delay(500);

}

}

if(digitalRead(3)==1&&digitalRead(12)==0&&digitalRead(9)==0&&digitalRead(6)==0){

delay(100);

if(digitalRead(3)==1){

if( radio.volumeUp()){

Vol=Vol+10 ;

}else{

Vol=150;

}

frequency=radio.getFrequency(); // 得到頻率

lcd.setCursor(0,1);

lcd.print(F("Vol "));

lcd.print(Vol);

lcd.print(" ");

delay(500);

}

}

}