### Arduino CLI Setup Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example of setting up the Arduino CLI for building projects. This is an alternative to the Arduino IDE. ```bash arduino-cli lib install --url https://github.com/pu2clr/SI4735 ``` -------------------------------- ### setup (advanced) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/class_s_i4735.html Starts the Si473X device with advanced configuration options. ```APIDOC ## setup(uint8_t resetPin, uint8_t ctsIntEnable, uint8_t defaultFunction, uint8_t audioMode=SI473X_ANALOG_AUDIO, uint8_t clockType=XOSCEN_CRYSTAL, uint8_t gpo2Enable=0) ### Description Starts the Si473X device. ### Method void ### Parameters #### Path Parameters - **resetPin** (uint8_t) - Description of resetPin - **ctsIntEnable** (uint8_t) - Description of ctsIntEnable - **defaultFunction** (uint8_t) - Description of defaultFunction - **audioMode** (uint8_t) - Optional - Default: SI473X_ANALOG_AUDIO - **clockType** (uint8_t) - Optional - Default: XOSCEN_CRYSTAL - **gpo2Enable** (uint8_t) - Optional - Default: 0 ``` -------------------------------- ### Install All Libraries and Boards Script (Windows) Source: https://github.com/pu2clr/si4735/blob/master/README.md Batch script to install all necessary libraries and boards for the SI4735 examples on Windows. This script automates the setup process for the development environment. ```batch examples/__install_all_libraries_and_boards.bat ``` -------------------------------- ### Install All Libraries and Boards on macOS/Linux Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Installs all available boards (esp32, ESP8266, STM32 etc.) and libraries for SI473X examples on macOS and Linux, after the basic installation. ```bash curl -fsSL https://raw.githubusercontent.com/pu2clr/SI4735/master/examples/install_all_libraries_and_boards.sh | sh ``` -------------------------------- ### setup (basic) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/class_s_i4735.html Starts the Si473X device with a reset pin and default function. ```APIDOC ## setup(uint8_t resetPin, uint8_t defaultFunction) ### Description Starts the Si473X device. ### Method void ### Parameters #### Path Parameters - **resetPin** (uint8_t) - Description of resetPin - **defaultFunction** (uint8_t) - Description of defaultFunction ``` -------------------------------- ### Basic SI4735 Installation Script (Windows) Source: https://github.com/pu2clr/si4735/blob/master/README.md Batch script to install arduino-cli and essential libraries/boards for basic SI4735 examples on Windows. This script simplifies the initial setup process. ```batch examples/__lib_si4735_basic_install.bat ``` -------------------------------- ### Install All Libraries and Boards on Windows Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Configures the SI4735 Arduino Library for all libraries and boards used by the examples on Windows, after the basic installation. ```bash curl -fsSL https://raw.githubusercontent.com/pu2clr/SI4735/master/examples/install_all_libraries_and_boards.bat --output install_all_libraries_and_boards.bat . install_all_libraries_and_boards.bat ``` -------------------------------- ### SI4735::setup (overload 2) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group07.html Starts the Si473X device with a simplified setup, specifying only the reset pin and the default function. ```APIDOC ## SI4735::setup ### Description Starts the Si473X device with a simplified setup. ### Method void ### Parameters #### Arguments - **resetPin** (uint8_t) - The pin used for resetting the device. - **defaultFunction** (uint8_t) - The default function for the device. ``` -------------------------------- ### Basic SI4735 Installation Script (macOS/Linux) Source: https://github.com/pu2clr/si4735/blob/master/README.md Shell script to install arduino-cli and essential libraries/boards for basic SI4735 examples on macOS or Linux. This is a streamlined setup for getting started. ```bash examples/__lib_si4735_basic_install.sh ``` -------------------------------- ### Example SI4735 Setup Source: https://github.com/pu2clr/si4735/wiki/Home Demonstrates how to initialize the SI4735 library with specific reset and interrupt pins, and sets the function to FM reception. ```cpp #include #define INTERRUPT_PIN 2 #define RESET_PIN 12 SI4735 si4735; void setup() { si4735.setup(RESET_PIN, INTERRUPT_PIN, FM_FUNCTION); } ``` -------------------------------- ### Setup Si473X Device (Basic Configuration) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group07.html Starts the Si473X device with essential parameters: reset pin and default function. ```cpp void SI4735::setup(uint8_t resetPin, uint8_t defaultFunction) ``` -------------------------------- ### Install All Libraries and Boards Script (macOS/Linux) Source: https://github.com/pu2clr/si4735/blob/master/README.md Shell script to install all necessary libraries and boards for the SI4735 examples on macOS or Linux. This is a convenient way to set up the development environment. ```bash examples/__install_all_libraries_and_boards.sh ``` -------------------------------- ### OLED Display Initialization and "Hello, World!" Source: https://github.com/pu2clr/si4735/blob/master/examples/SI47XX_07_STM32/NUCLEO_F103RB/README.md This example shows how to initialize an SSD1306 OLED display using the U8g2 library and display "Hello, World!". It requires the U8g2 library and I2C communication setup. The display is updated every second. ```cpp #include #include // Initialize U8g2 library U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); void setup() { // Initialize the OLED display u8g2.begin(); } void loop() { // Draw the "Hello, World!" message u8g2.firstPage(); do { u8g2.setFont(u8g2_font_ncenB14_tr); u8g2.drawStr(0,24,"Hello,"); u8g2.drawStr(0,48,"World!"); } while ( u8g2.nextPage() ); // Add a delay delay(1000); } ``` -------------------------------- ### Setup SI4735 with External Clock Source: https://github.com/pu2clr/si4735/blob/master/examples/SI47XX_11_NO_CRYSTAL/README.md Example of setting up the SI4735 device within the `setup` function to use an external clock source with a reference clock of 32768 Hz and a prescaler of 1. ```cpp void setup(void) { . . . si4735.setRefClock(32768); si4735.setRefClockPrescaler(1); // will work with 32768 si4735.setup(RESET_PIN, -1, POWER_UP_FM, SI473X_ANALOG_AUDIO, XOSCEN_RCLK); . . . } ``` -------------------------------- ### Example Usage for getRdsAllData Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group16.html Demonstrates the correct way to call getRdsAllData and handle the returned pointers. Includes setup and checks for NULL values. ```cpp void setup() { rx.setup(RESET_PIN, FM_FUNCTION); rx.setFM(8400, 10800, [currentFrequency](class_s_i4735.html#a4439c40db789f02371ea0fb9b22650c5), 10); delay(500); rx.setRdsConfig(3, 3, 3, 3, 3); rx.setFifoCount(1); } char *utcTime; char *stationName; char *programInfo; char *stationInfo; void showStationName() { if (stationName != NULL) { // do something } } void showStationInfo() { if (stationInfo != NULL) { // do something } } void showProgramaInfo() { if (programInfo != NULL) { // do something } } void showUtcTime() { if (rdsTime != NULL) { ``` -------------------------------- ### SI47XX LCD 20x4 I2C Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example using the SI47XX library with a 20x4 I2C LCD, an encoder, and buttons. This setup allows for interactive control of the radio. ```c++ #include #include #include // Define the I2C address of the LCD #define LCDADDR 0x27 // Define the pins for the encoder #define ENCODER_PIN_A 2 #define ENCODER_PIN_B 3 // Define the pin for the button #define BUTTON_PIN 4 SI4735 radio; LiquidCrystal_I2C lcd(LCDADDR, 20, 4); volatile int encoderPos = 0; volatile bool encoderMoved = false; void setup() { Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB } Serial.println("SI4735 Arduino Library"); Serial.println("--------------------------"); // Initialize the LCD lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("SI4735 Radio"); // Initialize the SI4735 device radio.setup(); radio.set_mode(SI4735_MODE_FM); radio.tune_fm(99.9); radio.set_volume(40); // Initialize the encoder and button pinMode(ENCODER_PIN_A, INPUT_PULLUP); pinMode(ENCODER_PIN_B, INPUT_PULLUP); pinMode(BUTTON_PIN, INPUT_PULLUP); // Attach interrupts for the encoder attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_A), updateEncoder, CHANGE); attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_B), updateEncoder, CHANGE); } void loop() { if (encoderMoved) { encoderMoved = false; // Update frequency based on encoder position radio.tune_fm(99.9 + encoderPos * 0.1); // Update LCD lcd.setCursor(0, 1); lcd.print("Freq: " + String(radio.get_frequency(), 1) + " MHz "); } if (digitalRead(BUTTON_PIN) == LOW) { // Button pressed, change mode or perform action delay(50); if (digitalRead(BUTTON_PIN) == LOW) { // Toggle between FM and AM or other modes // For simplicity, just print to serial Serial.println("Button Pressed!"); while (digitalRead(BUTTON_PIN) == LOW); } } } void updateEncoder() { int readingA = digitalRead(ENCODER_PIN_A); int readingB = digitalRead(ENCODER_PIN_B); if (readingA != lastEncodedA) { if (readingA != readingB) { encoderPos++; } else { encoderPos--; } encoderMoved = true; lastEncodedA = readingA; } } ``` -------------------------------- ### Setup Si473X Device (Full Configuration) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group07.html Initializes and starts the Si473X device with a comprehensive set of parameters including reset pin, CTS interrupt enable, default function, audio mode, clock type, and GPO2 enable. ```cpp void SI4735::setup(uint8_t resetPin, uint8_t ctsIntEnable, uint8_t defaultFunction, uint8_t audioMode=SI473X_ANALOG_AUDIO, uint8_t clockType=XOSCEN_CRYSTAL, uint8_t gpo2Enable=0) ``` -------------------------------- ### setup Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/functions_func_s.html Initializes and sets up the SI4735 chip for operation. ```APIDOC ## setup() ### Description Initializes and sets up the SI4735 chip for operation. ### Method Not specified (likely a function call in an SDK) ### Endpoint Not applicable (SDK function) ### Parameters Not specified in the source. ### Request Example ``` SI4735.setup(); ``` ### Response Not specified in the source. ``` -------------------------------- ### SI4735::setup (2/2) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group07.html Starts the Si473X device without interrupt resource, defaulting to analog audio mode if not specified. Suitable for basic setup using Arduino digital pins. ```APIDOC ## void SI4735::setup (uint8_t resetPin, uint8_t defaultFunction) ### Description Starts the Si473X device. Use this setup if you are not using interrupt resource. If the audio mode parameter is not entered, analog mode will be considered. You can use any Arduino digital pin. Be sure you are using less than 3.6V on Si47XX RST pin. ### Parameters #### Path Parameters - **resetPin** (uint8_t) - Description: Digital Arduino Pin used to RESET command. - **defaultFunction** (uint8_t) - Description: 0 = FM mode; 1 = AM ``` -------------------------------- ### Compile All Examples Script (Windows) Source: https://github.com/pu2clr/si4735/blob/master/README.md Batch script to compile all provided examples for the SI4735 library on Windows. The compiled binaries will be saved in your Downloads folder. ```batch examples/__compile_all.bat ``` -------------------------------- ### Install Arduino CLI on Linux/macOS using Script Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Installs the arduino-cli tool on Linux or macOS by downloading and executing an installation script. ```bash $ curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh ``` -------------------------------- ### Compile All Examples Script (macOS/Linux) Source: https://github.com/pu2clr/si4735/blob/master/README.md Shell script to compile all provided examples for the SI4735 library on macOS or Linux. The compiled binaries will be saved in your Downloads folder. ```bash examples/__compile_all.sh ``` -------------------------------- ### Install ESP32 Core with arduino-cli Source: https://github.com/pu2clr/si4735/blob/master/examples/SI47XX_06_ESP32/README.md Use the arduino-cli to configure additional board manager URLs, update the core index, and install the ESP32 core. ```bash arduino-cli config set board_manager.additional_urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json arduino-cli core update-index arduino-cli core install esp32:esp32 ``` -------------------------------- ### Install SI4735 Library on Windows via arduino-cli Source: https://github.com/pu2clr/si4735/blob/master/README.md Installs the latest development version of the SI4735 Arduino Library using curl and arduino-cli on Windows. This involves downloading the arduino-cli, extracting it, and then running the library installation command. ```bash echo off curl -fsSL https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip --output arduinocli.zip tar -xf arduinocli.zip set ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true .\arduino-cli lib install --git-url https://github.com/pu2clr/SI4735 ``` -------------------------------- ### List Installed Cores with Arduino CLI Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Displays the cores installed in your environment, along with their versions and available updates. ```bash $ arduino-cli core list Board Name FQBN 3D printer boards STM32:stm32:3dprinter 4D Systems gen4 IoD Range esp8266:esp8266:gen4iod AI Thinker ESP32-CAM esp32:esp32:esp32cam . . . Arduino Due (Native USB Port) arduino:sam:arduino_due_x Arduino Due (Programming Port) arduino:sam:arduino_due_x_dbg . . . Arduino Nano arduino:avr:nano Arduino Nano 33 BLE arduino:mbed_nano:nano33ble . . . Arduino Uno arduino:avr:uno ``` ```bash $ arduino-cli core list ID Installed Latest Name arduino:avr 1.8.5 1.8.5 Arduino AVR Boards arduino:mbed_nano 3.0.0 3.0.0 Arduino Mbed OS Nano Boards arduino:mbed_rp2040 3.0.0 3.0.0 Arduino Mbed OS RP2040 Boards arduino:sam 1.6.12 1.6.12 Arduino SAM Boards (32-bits ARM Cortex-M3) arduino:samd 1.8.13 1.8.13 Arduino SAMD Boards (32-bits ARM Cortex-M0+) atmel-avr-xminis:avr 0.6.0 0.6.0 Atmel AVR Xplained-minis attiny:avr 1.0.2 1.0.2 ATtiny Microcontrollers ATTinyCore:avr 1.5.2 1.5.2 ATTinyCore esp32:esp32 2.0.2 2.0.2 ESP32 Arduino esp8266:esp8266 3.0.2 3.0.2 ESP8266 Boards (3.0.2) MegaCore:avr 2.1.3 2.1.3 MegaCore MightyCore:avr 2.1.3 2.1.3 MightyCore MiniCore:avr 2.1.3 2.1.3 MiniCore rp2040:rp2040 1.13.0 1.13.0 Raspberry Pi RP2040 Boards(1.13.0) Seeeduino:samd 1.8.2 1.8.2 Seeed SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) Boards STM32:stm32 1.9.0 1.9.0 STM32 Boards (selected from submenu) teensy:avr 1.56.1 1.56.1 Teensyduino ``` -------------------------------- ### Install Arduino CLI and SI4735 Library on Windows Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Installs arduino-cli.exe, the SI4735 Arduino Library, and basic libraries/boards for Windows 10 and 11 using a batch script. ```bash curl -fsSL https://raw.githubusercontent.com/pu2clr/SI4735/master/examples/lib_si4735_basic_install.bat --output lib_si4735_basic_install.bat . lib_si4735_basic_install.bat ``` -------------------------------- ### SI47XX TFT Touch Screen Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example demonstrating the SI47XX library with a TFT display and touch screen. This allows for a graphical user interface for radio control. ```c++ #include #include #include // Assuming a TFT library is available // Define TFT pins and touch screen pins // These will vary depending on the specific TFT and touch screen used #define TFT_DC 9 #define TFT_RST 8 #define TFT_MOSI 11 #define TFT_SCLK 13 #define TFT_CS 10 #define YP A2 #define XM A1 #define YM A3 #define XP A0 // Define touch screen calibration values // These need to be determined experimentally for your specific screen #define TS_MINX 150 #define TS_MAXX 900 #define TS_MINY 120 #define TS_MAXY 920 SI4735 radio; // Initialize TFT and TouchScreen objects (specific to your libraries) // TFT tft = TFT(TFT_CS, TFT_DC, TFT_RST); // TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); void setup() { Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB } Serial.println("SI4735 Arduino Library"); Serial.println("--------------------------"); // Initialize TFT display // tft.begin(); // tft.setRotation(1); // Adjust rotation as needed // tft.fillScreen(TFT_BLACK); // Initialize the SI4735 device radio.setup(); radio.set_mode(SI4735_MODE_FM); radio.tune_fm(99.9); radio.set_volume(40); } void loop() { // Read touch screen input // TSPoint p = ts.getPoint(); // pinMode(XP, OUTPUT); // pinMode(XM, OUTPUT); // pinMode(YP, OUTPUT); // pinMode(YM, OUTPUT); // if (p.z > __PRESENCE_THRESHOLD__) { // Check if touched // Convert touch coordinates to screen coordinates // int x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width()); // int y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height()); // Check which button was pressed and perform actions // e.g., change frequency, volume, mode // } // Update TFT display with current radio status // tft.setCursor(0, 0); // tft.print("Frequency: "); // tft.println(radio.get_frequency()); // tft.setCursor(0, 10); // tft.print("Volume: "); // tft.println(radio.get_volume()); } ``` -------------------------------- ### SI47XX ESP32 Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example of using the SI47XX library with an ESP32 microcontroller. This example leverages the ESP32's capabilities for more advanced projects. ```c++ #include #include #include SI4735 radio; WebServer server(80); void handleRoot() { String html = "

SI4735 Radio Control

"; html += "

Frequency: " + String(radio.get_frequency(), 1) + " MHz

"; html += "

Volume: " + String(radio.get_volume()) + "

"; html += "Tune to 99.9
"; html += "Set Volume to 50
"; html += ""; server.send(200, "text/html", html); } void handleTune() { String freq = server.arg("freq"); if (!freq.isEmpty()) { radio.tune_fm(freq.toFloat()); } server.sendHeader("Location", "/"); server.send(303); } void handleVolume() { String vol = server.arg("vol"); if (!vol.isEmpty()) { radio.set_volume(vol.toInt()); } server.sendHeader("Location", "/"); server.send(303); } void setup() { Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB } Serial.println("SI4735 Arduino Library on ESP32"); Serial.println("--------------------------"); // Initialize the SI4735 device radio.setup(); radio.set_mode(SI4735_MODE_FM); radio.tune_fm(99.9); radio.set_volume(40); // Connect to WiFi WiFi.begin("YOUR_SSID", "YOUR_PASSWORD"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nWiFi connected"); Serial.println("IP address: " + WiFi.localIP()); // Setup web server routes server.on("", HTTP_GET, handleRoot); server.on("/tune", HTTP_GET, handleTune); server.on("/volume", HTTP_GET, handleVolume); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); // Other tasks can be performed here } ``` -------------------------------- ### Install Arduino CLI and SI4735 Library on macOS/Linux Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Installs arduino-cli, the SI4735 Arduino Library, and basic libraries/boards for macOS and Linux systems using a shell script. ```bash curl -fsSL https://raw.githubusercontent.com/pu2clr/SI4735/master/examples/lib_si4735_basic_install.sh | sh ``` -------------------------------- ### Set Frequency Step Example Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group08.html Demonstrates how to set the frequency step size for tuning. The example shows setting a 1MHz step for FM mode and a 1kHz step for AM or SSB mode. Note that this function does not validate band limits. ```cpp setFM(6400,10800,10390,10); setFrequencyStep(100); // the step will be 1MHz (you are using FM mode) // ... (other code) ... setAM(7000,7600,7100,5); setFrequencyStep(1); // the step will be 1kHz (you are usin AM or SSB mode) ``` -------------------------------- ### Install SI4735 Library on macOS/Linux via arduino-cli Source: https://github.com/pu2clr/si4735/blob/master/README.md Installs the latest development version of the SI4735 Arduino Library using curl and arduino-cli on macOS or Linux. Ensure you have arduino-cli installed or follow the provided installation command. ```bash curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh export ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true ./bin/arduino-cli lib install --git-url https://github.com/pu2clr/SI4735 ``` -------------------------------- ### SI47XX ATTINY85 Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example of using the SI47XX library with an ATTINY85 microcontroller. This is suitable for low-power or space-constrained projects. ```c++ #include SI4735 radio; void setup() { // ATTINY85 has limited resources, so Serial is not typically used. // Use other methods for debugging if needed (e.g., blinking LEDs). // Initialize the SI4735 device radio.setup(); // Set the radio to FM mode radio.set_mode(SI4735_MODE_FM); // Set the frequency to 99.9 MHz radio.tune_fm(99.9); // Set volume to 40 radio.set_volume(40); } void loop() { // ATTINY85 loop might control other components or react to external triggers. // For this basic example, the radio is set up and left running. // You might add code here to change frequency or volume based on button presses or other inputs. } ``` -------------------------------- ### Basic SI47XX Serial Monitor Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Demonstrates basic usage of the SI47XX library with the Arduino Serial Monitor. This example is suitable for initial testing and learning. ```c++ #include SI4735 radio; void setup() { Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB } Serial.println("SI4735 Arduino Library"); Serial.println("--------------------------"); // Initialize the SI4735 device radio.setup(); // Set the radio to FM mode radio.set_mode(SI4735_MODE_FM); // Set the frequency to 99.9 MHz radio.tune_fm(99.9); // Set volume to 40 radio.set_volume(40); } void loop() { // Nothing to do in the loop for this example } ``` -------------------------------- ### Install Arduino CLI on macOS using Homebrew Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Installs the arduino-cli tool on macOS using the Homebrew package manager. ```bash $ brew update $ brew install arduino-cli ``` -------------------------------- ### SI47XX STM32 Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example of using the SI47XX library with an STM32 microcontroller. This demonstrates compatibility with ARM-based platforms. ```c++ #include SI4735 radio; void setup() { // Serial output might require specific STM32 board configurations (e.g., using USART) // Serial.begin(57600); // while (!Serial) { // ; // } // Serial.println("SI4735 Arduino Library on STM32"); // Serial.println("--------------------------"); // Initialize the SI4735 device radio.setup(); // Set the radio to FM mode radio.set_mode(SI4735_MODE_FM); // Set the frequency to 99.9 MHz radio.tune_fm(99.9); // Set volume to 40 radio.set_volume(40); } void loop() { // Similar to other examples, the loop can be used for further control or interaction. // For instance, reading analog pins for potentiometers or digital pins for buttons. } ``` -------------------------------- ### SI47XX OLED I2C Example Source: https://github.com/pu2clr/si4735/blob/master/README.md Example using the SI47XX library with an OLED I2C display, an encoder, and a button. This provides a compact interface for radio control. ```c++ #include #include #include #include // Define the OLED display dimensions and I2C address #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C // Define the pins for the encoder #define ENCODER_PIN_A 2 #define ENCODER_PIN_B 3 // Define the pin for the button #define BUTTON_PIN 4 SI4735 radio; Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); volatile int encoderPos = 0; volatile bool encoderMoved = false; void setup() { Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB } Serial.println("SI4735 Arduino Library"); Serial.println("--------------------------"); // Initialize the OLED display if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for (;;); } display.display(); delay(1000); display.clearDisplay(); // Initialize the SI4735 device radio.setup(); radio.set_mode(SI4735_MODE_FM); radio.tune_fm(99.9); radio.set_volume(40); // Initialize the encoder and button pinMode(ENCODER_PIN_A, INPUT_PULLUP); pinMode(ENCODER_PIN_B, INPUT_PULLUP); pinMode(BUTTON_PIN, INPUT_PULLUP); // Attach interrupts for the encoder attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_A), updateEncoder, CHANGE); attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_B), updateEncoder, CHANGE); } void loop() { display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.println("SI4735 Radio"); if (encoderMoved) { encoderMoved = false; // Update frequency based on encoder position radio.tune_fm(99.9 + encoderPos * 0.1); display.setCursor(0, 10); display.print("Freq: "); display.print(radio.get_frequency(), 1); display.println(" MHz"); } display.setCursor(0, 20); display.print("Volume: "); display.println(radio.get_volume()); if (digitalRead(BUTTON_PIN) == LOW) { // Button pressed, change mode or perform action delay(50); if (digitalRead(BUTTON_PIN) == LOW) { // Toggle between FM and AM or other modes Serial.println("Button Pressed!"); while (digitalRead(BUTTON_PIN) == LOW); } } display.display(); } void updateEncoder() { int readingA = digitalRead(ENCODER_PIN_A); int readingB = digitalRead(ENCODER_PIN_B); if (readingA != lastEncodedA) { if (readingA != readingB) { encoderPos++; } else { encoderPos--; } encoderMoved = true; lastEncodedA = readingA; } } ``` -------------------------------- ### Setup SI4735 with 100kHz External Clock Source: https://github.com/pu2clr/si4735/blob/master/extras/schematic/README.md Configure the SI4735 to use a 100kHz external clock source. Select a reference clock of 33333Hz and a prescaler of 3. The XOSCEN_RCLK parameter in setup() is required. ```cpp rx.setRefClock(33333); rx.setRefClockPrescaler(3); rx.setup(RESET_PIN, 0, POWER_UP_AM, SI473X_ANALOG_AUDIO, XOSCEN_RCLK); ``` -------------------------------- ### setup (overload 2) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/class_s_i4735-members.html Initializes the SI4735 with detailed configuration options. ```APIDOC ## setup ### Description Provides a comprehensive setup for the SI4735 module, allowing configuration of reset pin, interrupt enable, default function, audio mode, clock type, and GPO2 enable. ### Method (Not specified, likely a class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **resetPin** (uint8_t) - Required - The GPIO pin used for resetting the device. - **ctsIntEnable** (uint8_t) - Required - Enables or disables CTS interrupts. - **defaultFunction** (uint8_t) - Required - The default function to set for the device. - **audioMode** (uint8_t) - Optional - Sets the audio output mode. Defaults to SI473X_ANALOG_AUDIO. - **clockType** (uint8_t) - Optional - Specifies the clock type. Defaults to XOSCEN_CRYSTAL. - **gpo2Enable** (uint8_t) - Optional - Enables or disables GPO2 output. Defaults to 0. ``` -------------------------------- ### setup (overload 1) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/class_s_i4735-members.html Initializes the SI4735 with basic reset and default function settings. ```APIDOC ## setup ### Description Initializes the SI4735 module with a specified reset pin and a default function. This is a basic setup configuration. ### Method (Not specified, likely a class method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **resetPin** (uint8_t) - Required - The GPIO pin used for resetting the device. - **defaultFunction** (uint8_t) - Required - The default function to set for the device. ``` -------------------------------- ### Setup SI4735 with 4.9152MHz External Clock Source: https://github.com/pu2clr/si4735/blob/master/extras/schematic/README.md Configure the SI4735 to use a 4.9152MHz external clock source. Use a reference clock of 32768Hz and a prescaler of 150. The XOSCEN_RCLK parameter in setup() is necessary. ```cpp rx.setRefClock(32768); // Ref = 32768Hz rx.setRefClockPrescaler(150); // prescaler = 150 ==> 32768 x 150 = 4915200Hz (4.9152MHz) rx.setup(RESET_PIN, 0, POWER_UP_AM, SI473X_ANALOG_AUDIO, XOSCEN_RCLK); ``` -------------------------------- ### Get Current Signed Frequency Offset Source: https://github.com/pu2clr/si4735/wiki/Home Returns the signed frequency offset in kHz. No setup required. ```cpp inline byte SI4735::getCurrentSignedFrequencyOffset() ``` -------------------------------- ### Get Current Valid Channel Status Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if the current channel is valid. No setup required. ```cpp inline bool SI4735::getCurrentValidChannel() ``` -------------------------------- ### setup Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/_s_i4735_8h_source.html Initializes the SI4735 chip with advanced configuration options. This function provides more control over the chip's startup behavior. ```APIDOC ## setup ### Description Initializes the SI4735 chip with advanced configuration options. This function provides more control over the chip's startup behavior. ### Method void ### Endpoint setup(uint8_t resetPin, uint8_t ctsIntEnable, uint8_t defaultFunction, uint8_t audioMode = SI473X_ANALOG_AUDIO, uint8_t clockType = XOSCEN_CRYSTAL, uint8_t gpo2Enable = 0) ### Parameters * **resetPin** (uint8_t) - The GPIO pin used for reset. * **ctsIntEnable** (uint8_t) - Enable/disable CTS interrupt. * **defaultFunction** (uint8_t) - The default function to set for the chip. * **audioMode** (uint8_t) - The audio mode to use (default: SI473X_ANALOG_AUDIO). * **clockType** (uint8_t) - The type of clock to use (default: XOSCEN_CRYSTAL). * **gpo2Enable** (uint8_t) - Enable/disable GPO2 output (default: 0). ### Request Example None ### Response None ``` -------------------------------- ### Get Current Pilot Presence Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if a stereo pilot signal is currently detected. No setup required. ```cpp inline bool SI4735::getCurrentPilot() ``` -------------------------------- ### SI4735::setup (1/2) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group07.html Starts the Si473X device with specified parameters, including audio mode and clock type. It allows configuration for crystal oscillators or external RCLK. ```APIDOC ## void SI4735::setup (uint8_t resetPin, uint8_t ctsIntEnable, uint8_t defaultFunction, uint8_t audioMode = [SI473X_ANALOG_AUDIO], uint8_t clockType = [XOSCEN_CRYSTAL], uint8_t gpo2Enable = 0) ### Description Starts the Si473X device. Use this function to start the device up with the parameters shown below. If the audio mode parameter is not entered, analog mode will be considered. You can use any Arduino digital pin. Be sure you are using less than 3.6V on Si47XX RST pin. ### Parameters #### Path Parameters - **resetPin** (uint8_t) - Description: Digital Arduino Pin used to RESET de Si47XX device. - **ctsIntEnable** (uint8_t) - Description: CTS Interrupt Enable. - **defaultFunction** (uint8_t) - Description: is the mode you want the receiver starts. - **audioMode** (uint8_t) - Optional - Description: default SI473X_ANALOG_AUDIO (Analog Audio). Use SI473X_ANALOG_AUDIO or SI473X_ANALOG_AUDIO. - **clockType** (uint8_t) - Optional - Description: 0 = Use external RCLK (crystal oscillator disabled); 1 = Use crystal oscillator - **gpo2Enable** (uint8_t) - Optional - Description: GPO2OE (GPO2 Output) 1 = Enable; 0 Disable (defult) ``` -------------------------------- ### getStatusCTS Source: https://github.com/pu2clr/si4735/wiki/Home Gets the Error flag of the status response. Refer to Si47XX Programming Guide AN332, page 63. ```APIDOC ## getStatusCTS ### Description Gets the Error flag of the status response. Refer to Si47XX Programming Guide AN332, page 63. ### Method `inline bool SI4735::getStatusCTS()` ### Returns - `bool`: The status response error flag. ``` -------------------------------- ### SI4735::setup (overload 1) Source: https://github.com/pu2clr/si4735/blob/master/extras/apidoc/html/group__group07.html Starts the Si473X device with specified configuration parameters including reset pin, CTS interrupt enable, default function, audio mode, clock type, and GPO2 enable. ```APIDOC ## SI4735::setup ### Description Starts the Si473X device with the specified configuration. ### Method void ### Parameters #### Arguments - **resetPin** (uint8_t) - The pin used for resetting the device. - **ctsIntEnable** (uint8_t) - Enables or disables the CTS interrupt. - **defaultFunction** (uint8_t) - The default function for the device. - **audioMode** (uint8_t) - The audio mode to use. Defaults to `SI473X_ANALOG_AUDIO`. - **clockType** (uint8_t) - The type of clock to use. Defaults to `XOSCEN_CRYSTAL`. - **gpo2Enable** (uint8_t) - Enables or disables GPO2. Defaults to 0. ``` -------------------------------- ### Get Current Blend Detect Interrupt Status Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if a blend detect interrupt has occurred. No setup required. ```cpp inline bool SI4735::getCurrentBlendDetectInterrupt() ``` -------------------------------- ### Get Current Soft Mute Indicator Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if the soft mute feature is currently engaged. No setup required. ```cpp inline bool SI4735::getCurrentSoftMuteIndicator() ``` -------------------------------- ### Get Current Multipath Detect High Status Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if the high multipath detection threshold is met. No setup required. ```cpp inline bool SI4735::getCurrentMultipathDetectHigh() ``` -------------------------------- ### Get Current Multipath Detect Low Status Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if the low multipath detection threshold is met. No setup required. ```cpp inline bool SI4735::getCurrentMultipathDetectLow() ``` -------------------------------- ### setup Source: https://github.com/pu2clr/si4735/wiki/Home Initializes the Si473X device. This method can be used with or without an interrupt pin, and allows specifying the receiver function and audio mode. ```APIDOC ## setup (with interrupt) ### Description Starts the Si473X device, configuring the reset and interrupt pins, default function, and audio mode. Use this version when interrupt functionality is required. ### Method `void SI4735::setup(uint8_t resetPin, int interruptPin, uint8_t defaultFunction, uint8_t audioMode = SI473X_ANALOG_AUDIO)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Example using interrupt pin 2 and reset pin 12 for FM function si4735.setup(12, 2, FM_FUNCTION); ``` ### Response None ``` ```APIDOC ## setup (without interrupt) ### Description Starts the Si473X device without utilizing an interrupt pin. This version is suitable when interrupt resources are not needed. ### Method `void SI4735::setup(byte resetPin, byte defaultFunction)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp // Example using reset pin 12 for FM function without interrupt si4735.setup(12, FM_FUNCTION); ``` ### Response None ``` -------------------------------- ### Control Volume with Keys Source: https://github.com/pu2clr/si4735/wiki/Home This example demonstrates using volumeUp() and volumeDown() based on key presses. '+' increases volume, and '-' decreases it. ```cpp switch (key) { case '+': si4735.volumeUp(); break; case '-': si4735.volumeDown(); break; . . . ``` -------------------------------- ### Get SI4735 Status Source: https://github.com/pu2clr/si4735/blob/master/extras/docbr/README.md Retrieves the current status of the Si4735, applicable to both AM and FM modes. Refer to the Si47XX Programming Guide for details. ```cpp /* * Gets the current status of the Si4735 (AM or FM) * See Si47XX PROGRAMMING GUIDE; AN332; pages 73 (FM) and 139 (AM) * */ void SI4735::getStatus() ``` ```cpp /* * Gets the current status of the Si4735 (AM or FM) * See Si47XX PROGRAMMING GUIDE; AN332; pages 73 (FM) and 139 (AM) * * @param byte INTACK Seek/Tune Interrupt Clear. If set, clears the seek/tune complete interrupt status indicator; * @param byte CANCEL Cancel seek. If set, aborts a seek currently in progress; * */ void SI4735::getStatus(byte INTACK, byte CANCEL) { ``` -------------------------------- ### Get Current Multipath Metric Source: https://github.com/pu2clr/si4735/wiki/Home Returns the current multipath metric, ranging from 0 (no multipath) to 100 (full multipath). No setup required. ```cpp inline byte SI4735::getCurrentMultipath() ``` -------------------------------- ### Get Current AFC Rail Indicator Source: https://github.com/pu2clr/si4735/wiki/Home Returns true if the Automatic Frequency Control (AFC) rail indicator is active. No setup required. ```cpp inline bool SI4735::getCurrentAfcRailIndicator() ``` -------------------------------- ### List All Available Boards with Arduino CLI Source: https://github.com/pu2clr/si4735/blob/master/examples/README.md Shows all boards available in your environment, providing FQBN information for compilation. ```bash $ arduino-cli board listall ``` -------------------------------- ### Example Usage of volumeUp() and volumeDown() Source: https://github.com/pu2clr/si4735/blob/master/extras/docbr/README.md Demonstrates increasing or decreasing the volume based on user input, using '+' for up and '-' for down. ```cpp switch (key) { case '+': si4735.volumeUp(); break; case '-': si4735.volumeDown(); break; . . . ``` -------------------------------- ### getFrequency Source: https://github.com/pu2clr/si4735/wiki/Home Gets the current frequency of the Si4735 (AM/SSB or FM). This method also performs a status check. Refer to the Si47XX Programming Guide for details. ```APIDOC ## getFrequency ### Description Gets the current frequency of the Si4735 (AM/SSB or FM). This method also performs a status check. ### Method `unsigned SI4735::getFrequency()` ### Returns - `unsigned`: The current frequency. ``` -------------------------------- ### Get Current Stereo Blend Amount Source: https://github.com/pu2clr/si4735/wiki/Home Returns the current stereo blend percentage, where 100% is full stereo and 0% is full mono. No setup required. ```cpp inline byte SI4735::getCurrentStereoBlend() ```