Components and supplies
RDA5807M
esp32 WROOM32
Apps and platforms
Arduino IDE
Project description
Code
FMRadioV2
arduino
Flash the esp using the Arduino IDE
1#include <BluetoothSerial.h> 2#include <Arduino.h> 3#include <Wire.h> 4#include <RDA5807M.h> 5 6 7#define FIX_BAND RADIO_BAND_FM 8#define BT_DISCOVER_TIME 10000 9 10BluetoothSerial SerialBT; 11RDA5807M radio; 12 13int stations[12] = {9110,9370,9580,9670,9740,9890,9890,10110,10280,10480,10540,10760}; 14int action = -1; 15static bool btScanAsync = true; 16static bool btScanSync = true; 17int Volume = 8; 18//int convert1 = 0; 19float convert = 0; 20void setup() { 21//String myString = ""; 22 Serial.begin(115200); 23 SerialBT.begin("ESP32FMRadio"); //Bluetooth device name 24 Serial.println("The device started, now you can pair it with bluetooth!"); 25 26 27 if (btScanAsync) { 28 Serial.print("Starting discoverAsync..."); 29 if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) { 30 Serial.println("Findings will be reported in \\"btAdvertisedDeviceFound\\""); 31 delay(10000); 32 Serial.print("Stopping discoverAsync... "); 33 SerialBT.discoverAsyncStop(); 34 Serial.println("stopped"); 35 } else { 36 Serial.println("Error on discoverAsync f.e. not workin after a \\"connect\\""); 37 } 38 } 39 40 if (btScanSync) { 41 Serial.println("Starting discover..."); 42 BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME); 43 if (pResults) 44 pResults->dump(&Serial); 45 else 46 Serial.println("Error on BT Scan, no result!"); 47 } 48 49 50 radio.init(); 51 radio.setBandFrequency(FIX_BAND, 9110); 52 radio.setVolume(Volume); 53 radio.setMono(false); 54 radio.setMute(false); 55} 56 57void loop() { 58 action = SerialBT.read(); 59 if (action > 0) { 60 if (action < 11) { 61 convert = stations[action]; 62 convert = convert / 100; 63 64 String myString = String (convert,1); 65 if (myString.length() == 4) { 66 myString = (myString + " "); 67 } 68 69 Serial.println(myString ); 70 SerialBT.print(myString); 71 radio.setBandFrequency(FIX_BAND, stations[action]); 72 } 73else { 74 switch (action){ 75 case 11: 76 if (Volume >0) { 77 Volume --; 78 radio.setVolume(Volume); 79 } 80 break; 81 82 case 12: 83 if (Volume < 15) { 84 Volume ++; 85 radio.setVolume(Volume); 86 } 87 break; 88 89 case 13: 90 radio.seekDown(); 91 break; 92 93 case 14: 94 radio.seekUp(); 95 break; 96 97 case 15: 98 convert = radio.getFrequency(); 99 convert = convert / 100; 100 String myString = String (convert,1); 101 if (myString.length() == 4) { 102 myString = (myString + " "); 103 } 104 Serial.println(myString); 105 SerialBT.print(myString); 106 break; 107 } 108} 109 110 } 111} 112 113 114void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) { 115 Serial.printf("Found a device asynchronously: %s\ 116", pDevice->toString().c_str()); 117} 118
FMRadioV2
arduino
Flash the esp using the Arduino IDE
1#include <BluetoothSerial.h> 2#include <Arduino.h> 3#include <Wire.h> 4#include <RDA5807M.h> 5 6 7#define FIX_BAND RADIO_BAND_FM 8#define BT_DISCOVER_TIME 10000 9 10BluetoothSerial SerialBT; 11RDA5807M radio; 12 13int stations[12] = {9110,9370,9580,9670,9740,9890,9890,10110,10280,10480,10540,10760}; 14int action = -1; 15static bool btScanAsync = true; 16static bool btScanSync = true; 17int Volume = 8; 18//int convert1 = 0; 19float convert = 0; 20void setup() { 21//String myString = ""; 22 Serial.begin(115200); 23 SerialBT.begin("ESP32FMRadio"); //Bluetooth device name 24 Serial.println("The device started, now you can pair it with bluetooth!"); 25 26 27 if (btScanAsync) { 28 Serial.print("Starting discoverAsync..."); 29 if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) { 30 Serial.println("Findings will be reported in \\"btAdvertisedDeviceFound\\""); 31 delay(10000); 32 Serial.print("Stopping discoverAsync... "); 33 SerialBT.discoverAsyncStop(); 34 Serial.println("stopped"); 35 } else { 36 Serial.println("Error on discoverAsync f.e. not workin after a \\"connect\\""); 37 } 38 } 39 40 if (btScanSync) { 41 Serial.println("Starting discover..."); 42 BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME); 43 if (pResults) 44 pResults->dump(&Serial); 45 else 46 Serial.println("Error on BT Scan, no result!"); 47 } 48 49 50 radio.init(); 51 radio.setBandFrequency(FIX_BAND, 9110); 52 radio.setVolume(Volume); 53 radio.setMono(false); 54 radio.setMute(false); 55} 56 57void loop() { 58 action = SerialBT.read(); 59 if (action > 0) { 60 if (action < 11) { 61 convert = stations[action]; 62 convert = convert / 100; 63 64 String myString = String (convert,1); 65 if (myString.length() == 4) { 66 myString = (myString + " "); 67 } 68 69 Serial.println(myString ); 70 SerialBT.print(myString); 71 radio.setBandFrequency(FIX_BAND, stations[action]); 72 } 73else { 74 switch (action){ 75 case 11: 76 if (Volume >0) { 77 Volume --; 78 radio.setVolume(Volume); 79 } 80 break; 81 82 case 12: 83 if (Volume < 15) { 84 Volume ++; 85 radio.setVolume(Volume); 86 } 87 break; 88 89 case 13: 90 radio.seekDown(); 91 break; 92 93 case 14: 94 radio.seekUp(); 95 break; 96 97 case 15: 98 convert = radio.getFrequency(); 99 convert = convert / 100; 100 String myString = String (convert,1); 101 if (myString.length() == 4) { 102 myString = (myString + " "); 103 } 104 Serial.println(myString); 105 SerialBT.print(myString); 106 break; 107 } 108} 109 110 } 111} 112 113 114void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) { 115 Serial.printf("Found a device asynchronously: %s\ 116", pDevice->toString().c_str()); 117} 118
Downloadable files
ESP32FMRadio
The circuit diagram..
ESP32FMRadio
ESP32FMRadio
The circuit diagram..
ESP32FMRadio
Documentation
FMRadio app V2
FMRadio app V2
Comments
Only logged in users can leave comments