Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32 and TEA5767 FM Radio with ILI9341 Display and Potentiometer Tuning

View and Edit Project In Cirkit DesignerImage of ESP32 and TEA5767 FM Radio with ILI9341 Display and Potentiometer Tuning

Circuit Documentation

Summary

This circuit integrates an ESP32 microcontroller, a TEA5767 FM radio module, an ILI9341 TFT display, and a rotary potentiometer. The ESP32 controls the FM radio module and displays the current frequency on the TFT display. The rotary potentiometer is used to adjust the frequency.

Component List

TEA5767

ESP32

ILI9341

PR-Rotary Potentiometer

Wiring Details

TEA5767

ESP32

ILI9341

PR-Rotary Potentiometer

Code Documentation

ESP32 Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

#define TEA5767_I2C_ADDRESS 0x60
#define POT_PIN VP // Analog pin connected to potentiometer

// Define ILI9341 pins
#define TFT_CS   5
#define TFT_RST  18
#define TFT_DC   19
#define TFT_MOSI 23
#define TFT_CLK  18
#define TFT_MISO 19

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  Wire.begin();
  Serial.begin(115200);
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
}

void loop() {
  int potValue = analogRead(POT_PIN);
  float frequency = map(potValue, 0, 4095, 875, 1080) / 10.0; // Map to FM frequency range 87.5 - 108.0 MHz
  setFrequency(frequency);
  displayFrequency(frequency);
  delay(1000); // Update frequency every second
}

void setFrequency(float frequency) {
  uint16_t frequencyB = (4 * (frequency * 1000000 + 225000)) / 32768;
  byte frequencyH = frequencyB >> 8;
  byte frequencyL = frequencyB & 0xFF;
  
  Wire.beginTransmission(TEA5767_I2C_ADDRESS);
  Wire.write(frequencyH);
  Wire.write(frequencyL);
  Wire.write(0xB0); // High side LO injection
  Wire.write(0x10); // Mute off
  Wire.write(0x00); // No search mode
  Wire.endTransmission();
}

void displayFrequency(float frequency) {
  tft.fillScreen(ILI9341_BLACK);
  tft.setCursor(0, 0);
  tft.print("Frequency: ");
  tft.print(frequency);
  tft.print(" MHz");
}

This code initializes the ESP32, sets up the ILI9341 display, and reads the analog value from the potentiometer to adjust the frequency of the TEA5767 FM radio module. The current frequency is displayed on the TFT screen.