RDA5807 Arduino Library

repository·master·Indexed 41 days ago

https://github.com/pu2clr/rda5807

A cross-platform Arduino library for controlling RDA5807 and RDA7088 FM radio tuner ICs via I2C. It supports features such as RDS (Radio Data System), AGC, and digital audio. The library includes implementation examples for various hardware, including ATTiny84, ATTiny85, and the LilyGO T-Embed (ESP32-S3), as well as interfacing with MAX98357A I2S DACs and TM1638 display modules.

Tokens
13.5K
Snippets
20
Records
49
Agent score
51%

What's inside RDA5807

  1. Overview of the RDA5807 Arduino Library

    master

    The RDA5807 Arduino Library is a cross-platform library designed to control the RDA5807 and RDA7088 family of FM DSP integrated circuit receivers from RDA Microelectronics. It uses the I2C protocol to provide an interface for controlling features such as frequency tuning (76–108 MHz), RDS/RBDS processing, volume, bass, and noise suppression.

    It is compatible with a wide range of hardware, including official Arduino boards, ATtiny, STM32, ESP32, and ESP8266.

  2. Choosing between RDA5807M and RDA5807FP

    master

    When selecting your hardware, consider the following:

    • RDA5807M Breakout: Easier to use for most applications as it is a pre-made breakout. However, documentation regarding GPIO2, GPIO3, and RCLK functions on some M-based breakouts is inconsistent and may not work.
    • RDA5807FP (Standalone IC): Recommended if you need to use I2S digital audio configuration or GPIO setup (such as stereo indicators or interrupts). This library fully supports these features on the FP model.
    • RDA7088: While it has the same pinout as the RDA5807FP, some library functions like RDS, Seek, and Stereo may not work properly on this chip.
  3. Extend the RDA5807 class for custom functionality

    master

    If you need to implement features not present in the library or modify existing behavior, extend the RDA5807 class using C++ inheritance. This allows you to keep your custom logic synchronized with future library updates.

    Use cases:

    1. Adding new commands: Implement methods that call getDirectRegister() to access specific RDA5807 registers not exposed by the base class.
    2. Overwriting existing methods: Redefine methods like setFrequencyUp() or setFrequencyDown() to include custom logic (e.g., custom frequency boundary limits).
    #include <RDA5807.h>
    
    class MyCustomRDA5807 : public RDA5807 {
    public:
      // 1. Adding a new method using direct register access
      int getSoftBlendEnable() {
        rda_reg07 tmp;
        tmp.raw = this->getDirectRegister(0x07).raw;
        return tmp.refined.SOFTBLEND_EN;
      }
    
      // 2. Overwriting an existing method to change behavior
      void setFrequencyUp() {
        // Custom logic here...
        setFrequency(this->currentFrequency + step);
      }
    };
    
    MyCustomRDA5807 radio;
  4. Install the RDA5807 library via Arduino IDE

    master

    The easiest way to install the library is through the Arduino IDE Library Manager:

    1. Open the Tools menu.
    2. Select Manage Libraries.
    3. In the search box, type PU2CLR or RDA5807.
    4. Locate and select PU2CLR RDA5807 to install.
  5. Wire up RDA5807 with Nokia 5110 Display and Buttons

    master

    For an Arduino Nano using a Nokia 5110 display, RDA5807, buttons, and an encoder:

    Device nameNokia 5110 Pin functionArduino Nano Pin
    NOKIA 5110(1) RST (RESET)8
    (2) CE or CS9
    (3) DC or DO10
    (4) DIN or DI or MOSI11
    (5) CLK13
    (6) VCC (3V-5V)+VCC
    (7) BL/DL/LIGHT+VCC
    (8) GNDGND
    RDA5807VCC3.3V
    SDIO (pin 8)A4
    SCLK (pin 7)A5
    ButtonsVolume Up4
    Volume Down5
    Stereo/Mono6
    RDS ON/off7
    SEEK (encoder button)A0/14
    EncoderA2
    B3
    | Device name               | Nokia 5110                |  Arduino  |
    | --------------------------| --------------------      | ------------  |
    | NOKIA 5110                | Pin function              |  Nano Pin     |
    |                           | (1) RST (RESET)           |     8         |
    |                           | (2) CE or CS              |     9         |
    |                           | (3) DC or DO              |     10        |
    |                           | (4) DIN or DI or MOSI     |     11        |
    |                           | (5) CLK                   |     13        |
    |                           | (6) VCC (3V-5V)            |     +VCC      |
    |                           | (7) BL/DL/LIGHT           |     +VCC      |
    |                           | (8) GND                   |     GND       |
    | --------------------------| ---------------------------|--------------|
    | RDA5807                   | Pin Function               |              |
    |                           | VCC                       |     3.3V      |
    |                           | SDIO (pin 8)              |     A4       |
    |                           | SCLK (pin 7)              |     A5       |
    | --------------------------| ----------------------------|--------------|
    | Buttons                   |                           |              |
    |                           | Volume Up                 |      4       |
    |                           | Volume Down               |      5       |
    |                           | Stereo/Mono               |      6       |
    |                           | RDS ON/off                |      7       |
    |                           | SEEK (encoder button)     |      A0/14    |
    | --------------------------| ----------------------------|--------------|
    | Encoder                   |                           |              |
    |                           | A                         |      2       |
    |                           | B                         |      3       |
  6. Wire up RDA5807 with ATtiny84

    master

    For projects using the ATtiny84 microcontroller, use the following pin mapping for the RDA5807 breakout, encoder, and buttons:

    RDA5807 pinAttiny84 REF pinPhysical pin
    SEEK_UP310
    SEEK_DOWN58
    ENCODER_PIN_A013
    ENCODER_PIN_B112
    SDIO / SDASDA7
    SCLK / CLKSCL9
  7. Set up Arduino IDE for LilyGO T-Embed (ESP32-S3)

    master

    To use the LilyGO T-Embed with the RDA5807 library, you must first configure the Arduino IDE to support ESP32-S3 boards:

    1. Add ESP32 Board URL: In Arduino IDE, go to Preferences and add the following URL to the "Additional Boards Manager URLs" field: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
    2. Install ESP32 Platform: Open the Tools menu, select Board: "Boards Manager...", search for esp32, and install it.
    3. Install Required Libraries:
      • FastLED: Install via the Arduino IDE Library Manager.
      • Battery 18650 Stats: Install from GitHub.
      • RotaryEncoder and TFT_eSPI: Download these from the LilyGo T-Embed GitHub repository, unzip them, and manually copy the folders from the __lib__ directory into your Arduino libraries folder (typically Documents/Arduino/libraries/).
  8. Basic usage of the RDA5807 library

    master

    To use the library, include RDA5807.h and instantiate an RDA5807 object. The core workflow involves calling .setup() to initialize the receiver, followed by configuration methods like .setVolume() and .setFrequency().

    Frequency Note: Frequencies are passed as integers. For example, 10390 represents 103.9 MHz.

    #include <RDA5807.h>
    
    RDA5807 rx;
    
    void setup() {
        // Start your receiver here
        rx.setup();
        rx.setVolume(6);
        rx.setFrequency(10390); // Example: 103.9 MHz
    }
    
    void loop() {
        // Control your receiver here 
    }
  9. Control the RDA5807 via MQTT

    master

    You can control the radio remotely using MQTT topics. Start the client with python3 mqtt_client.py and publish messages to the following topics:

    Topics

    • /home/RDA5807/frequency: Control frequency.
    • /home/RDA5807/volume: Control volume.
    • /home/RDA5807/command: General commands.
    • /home/RDA5807/status: Request radio status.

    Supported Commands

    Frequency Commands:

    • <value>: Set frequency in MHz (e.g., 103.9).
    • up or +: Increment frequency.
    • down or -: Decrement frequency.

    Volume Commands:

    • <value>: Set volume (0-15).
    • up or +: Increment volume.
    • down or -: Decrement volume.

    General Commands:

    • mute_toggle: Toggle mute.
    • bass_toggle: Toggle bass boost.
    • seek_up / seek_down: Station seeking.
    • status: Request current status.
    • reset: Restart radio.
    # Example commands via mosquitto_pub
    mosquitto_pub -h localhost -t /home/RDA5807/frequency -m "103.9"
    mosquitto_pub -h localhost -t /home/RDA5807/volume -m "10"
    mosquitto_pub -h localhost -t /home/RDA5807/command -m "seek_up"
  10. Wire up RDA5807 with Arduino UNO/Nano and TFT ST7735 1.8" Display

    master

    To use the RDA5807_02_TFT_display example, connect the components as follows. This setup uses an Atmega328-based board (like UNO or Nano) and an SPI TFT display.

    DevicePin / DescriptionArduino Pin
    Display TFTRST (RESET)8
    RS or DC9
    CS or SS10
    SDI11
    CLK13
    RDA5807VCC3.3V
    SDIO (pin 8)A4
    SCLK (pin 7)A5
    ButtonsVolume Up4
    Volume Down5
    Stereo/Mono6
    RDS ON/off7
    SEEK (encoder button)A0/14
    EncoderA2
    B3
  11. Use the RDA5807 Python API

    master

    The Python driver replicates the C/C++ Arduino library interface. To use it, create an instance of RDA5807, call setup() to initialize, and then use the provided methods to control the radio.

    Basic Workflow:

    1. Import rda5807.
    2. Instantiate rx = rda5807.RDA5807().
    3. Initialize with rx.setup().
    4. Control frequency, volume, and audio settings.
    import rda5807
    
    # Create instance
    rx = rda5807.RDA5807()
    
    # Initialize
    rx.setup()
    
    # Configure frequency (e.g., 103.9 MHz) and volume
    rx.setFrequency(10390)
    rx.setVolume(8)
    
    # Controls
    rx.setFrequencyUp()
    rx.setVolumeDown()
    rx.setMute(True)
    rx.setBass(True)
    
    # Get status
    freq = rx.getFrequency()
    vol = rx.getVolume()
    status = rx.getStatus()