close

本篇使用Arduino 及 TEA5767 模組DIY一個FM 接收器

 

 

Connect TEA 5767 to Arduino Uno in the following way:
        SDA of TEA5767 breakout board to A4 of Arduino.
        SCL of TEA5767 breakout board to A5 of Arduino.
        GND of TEA5767 breakout board to GND of Arduino
        VCC of TEA5767 breakout board to VCC of Arduino.

 

 Here is the sketch. Note you need Arduino 1.0

#include <Wire.h>

unsigned char frequencyH = 0;
unsigned char frequencyL = 0;

unsigned int frequencyB;
double frequency = 0;

void setup()
{
  Wire.begin();
  frequency = 93.0; //starting frequency
  setFrequency();
  Serial.begin(9600);
}

void loop()
{
  int reading = analogRead(0);
  //frequency = map((float)reading, 0.0, 1024.0, 87.5, 108.0);
 
  frequency = ((double)reading * (108.0 - 87.5)) / 1024.0 + 87.5;
  frequency = ((int)(frequency * 10)) / 10.0;
 
  setFrequency();
  Serial.println(frequency);
}

void setFrequency()
{
  frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
  frequencyH = frequencyB >> 8;
  frequencyL = frequencyB & 0XFF;
  delay(100);
  Wire.beginTransmission(0x60);
  Wire.write(frequencyH);
  Wire.write(frequencyL);
  Wire.write(0xB0);
  Wire.write(0x10);
  Wire.write((byte)0x00);
  Wire.endTransmission();
  delay(100); 
}

 

Anther code example

 

The Arduino code is as below:

/// Original from Arduino FM receiver with TEA5767 http://www.electronicsblog.net
// Modified by Jingfeng Liu
//  LinkSprite.com
//
#include <Wire.h>
#include <LiquidCrystal.h>

unsigned char search_mode=0;

int b=0;
int c=0;

#define Button_next 6
#define Button_prev 7

unsigned char frequencyH=0;
unsigned char frequencyL=0;

unsigned int frequencyB;
double frequency=0;

double freq_available=0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()   {

  Wire.begin();
  lcd.begin(16, 2);

  /// buttons

  pinMode(Button_next, INPUT);
  digitalWrite(Button_next, HIGH); //pull up resistor

  pinMode(Button_prev, INPUT);
  digitalWrite(Button_prev, HIGH); //pull up resistor

  frequency=87.5; //starting frequency

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

  frequencyH=frequencyB>>8;

  frequencyL=frequencyB&0XFF;

  delay(100);

  Wire.beginTransmission(0x60);   //writing TEA5767

  Wire.write(frequencyH);
  Wire.write(frequencyL);
  Wire.write(0xB0);
  Wire.write(0x10);
  Wire.write(0x00);
  Wire.endTransmission();

  delay(100);

}

void loop()
{

  unsigned char buffer[5];

  lcd.setCursor(0, 0);

  Wire.requestFrom(0x60,5); //reading TEA5767

  if (Wire.available())

  {
    for (int i=0; i<5; i++) {

      buffer[i]= Wire.read();
    }

    freq_available=(((buffer[0]&0x3F)<<8)+buffer[1])*32768/4-225000;

    lcd.print("FM ");

    lcd.print((freq_available/1000000));

    frequencyH=((buffer[0]&0x3F));

    frequencyL=buffer[1];

    if (search_mode) {

      if(buffer[0]&0x80) search_mode=0;

    }

    if (search_mode==1) lcd.print(" SCAN");
    else {
      lcd.print("       ");
    }

    lcd.setCursor(0, 1);

    lcd.print("Level: ");
    lcd.print((buffer[3]>>4));
    lcd.print("/16 ");

    if (buffer[2]&0x80) lcd.print("STEREO   ");
    else lcd.print("MONO   ");

  }

  ///// buttons read

  //////////// button_next//////////
  if (!digitalRead(Button_next)&&!b) {

    frequency=(freq_available/1000000)+0.05;

    frequencyB=4*(frequency*1000000+225000)/32768+1;

    frequencyH=frequencyB>>8;
    frequencyL=frequencyB&0XFF; 

    Wire.beginTransmission(0x60); 

    Wire.write(frequencyH);
    Wire.write(frequencyL);
    Wire.write(0xB0);
    Wire.write(0x1F);
    Wire.write(0x00);

    Wire.endTransmission();

    //////////////////////

    b=100;

  };

  if (!digitalRead(Button_next)&&b==1) {

    ///scannnn UP

    search_mode=1;

    Wire.beginTransmission(0x60); 

    Wire.write(frequencyH+0x40);
    Wire.write(frequencyL);
    Wire.write(0xD0);
    Wire.write(0x1F);
    Wire.write(0x00);

    Wire.endTransmission();

    /////////////////

    b=100;

  };  

  if (!b==0) b--;

  //////////// button_prev//////////
  if (!digitalRead(Button_prev)&&!c) {

    frequency=(freq_available/1000000)-0.05;

    frequencyB=4*(frequency*1000000+225000)/32768+1;

    frequencyH=frequencyB>>8;
    frequencyL=frequencyB&0XFF;

    Wire.beginTransmission(0x60); 

    Wire.write(frequencyH);
    Wire.write(frequencyL);
    Wire.write(0xB0);
    Wire.write(0x1F);
    Wire.write(0x00);

    Wire.endTransmission();

    c=100;

  };

  if (!digitalRead(Button_prev)&&c==1) {

    ///scannnn DOWN

    search_mode=1;

    Wire.beginTransmission(0x60); 

    Wire.write(frequencyH+0x40);
    Wire.write(frequencyL);

    Wire.write(0x50);
    Wire.write(0x1F);
    Wire.write(0x00);
    Wire.endTransmission(); 

    c=100;

  };        

  if (!c==0) c--;

  ////////////////////

}

Another code from

http://www.instructables.com/id/How-to-use-the-TEA5767-FM-Radio-module-Arduino-Tut/ 

/* How to use the TEA5767 FM radio Module with Arduino
   More info: http://www.ardumotive.com/how-to-use-the-tea5767-fm-radio-module-en.html
   Dev: Vasilakis Michalis // Date: 21/9/2015 // www.ardumotive.com    */

//Libraries:
#include <TEA5767.h>
#include <Wire.h>

//Constants:
TEA5767 Radio; //Pinout SLC and SDA - Arduino uno pins A5 and A4


//Variables:
double old_frequency;
double frequency;
int search_mode = 0;
int search_direction;
unsigned long last_pressed;
unsigned char buf[5];
int stereo;
int signal_level;
double current_freq;
unsigned long current_millis = millis();
int inByte;
int flag=0;

void setup () {
  //Init
  Serial.begin(9600);
  Radio.init();
  Radio.set_frequency(95.2); //On power on go to station 95.2

}

void loop () {
 
  if (Serial.available()>0) {
    inByte = Serial.read();
    if (inByte == '+' || inByte == '-'){  //accept only + and - from keyboard
     flag=0;
    }
  }


  if (Radio.read_status(buf) == 1) {
     current_freq =  floor (Radio.frequency_available (buf) / 100000 + .5) / 10;
     stereo = Radio.stereo(buf);
     signal_level = Radio.signal_level(buf);
     //By using flag variable the message will be printed only one time.
     if(flag == 0){
      Serial.print("Current freq: ");
      Serial.print(current_freq);
      Serial.print("MHz Signal: ");
      //Strereo or mono ?
     if (stereo){
       Serial.print("STEREO ");
      }
  else{
    Serial.print("MONO ");
  }
     Serial.print(signal_level);
     Serial.println("/15");
     flag=1;
     }
  }
  
  //When button pressed, search for new station
  if (search_mode == 1) {
      if (Radio.process_search (buf, search_direction) == 1) {
          search_mode = 0;
      }
  }
  //If forward button is pressed, go up to next station
  if (inByte == '+') {
    last_pressed = current_millis;
    search_mode = 1;
    search_direction = TEA5767_SEARCH_DIR_UP;
    Radio.search_up(buf);
  }
  //If backward button is pressed, go down to next station
  if (inByte == '-') {
    last_pressed = current_millis;
    search_mode = 1;
    search_direction = TEA5767_SEARCH_DIR_DOWN;
    Radio.search_down(buf);
  }
  delay(500);
  
}

 

參考資料

TEA5767 datasheet

Arduino FM receiver with TEA5767(*)

MicroPython ESP8266 I2C documentation(*)

How to Use the TEA5767 FM Radio Module - Arduino Tutorial

TEA5767 FM Radio Breakout Board for Arduino

https://www.electronicsblog.net/arduino-fm-receiver-with-tea5767/

Use TEA5767 FM Module to Create an Arduino Based FM Radio

http://www.raspberry-pi-geek.com/Archive/2016/16/Remote-controlled-Arduino-FM-radio
http://www.ardumotive.com/how-to-use-the-tea5767-fm-radio-module-en.html

 

 

arrow
arrow
    文章標籤
    TEA5767 Arduino FM transmittter
    全站熱搜
    創作者介紹
    創作者 stanley 的頭像
    stanley

    史坦利Stanley程式Maker的部落格

    stanley 發表在 痞客邦 留言(1) 人氣()