Alan Wang
Published © CC BY-SA

Retro FM Radio with TEA5767 and WeMos D1 mini

A FM radio built inside a wooden retro-radio style smartphone rack. Programmed in MicroPython.

BeginnerShowcase (no instructions)6,900
Retro FM Radio with TEA5767 and WeMos D1 mini

Things used in this project

Hardware components

Wemos D1 Mini
Espressif Wemos D1 Mini
×1
TEA5767 FM radio module
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
KY-040 rotary encoder
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
TDA2030A Audio Amplifier Module
×1
Breadboard (generic)
Breadboard (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×20
Power Supply Module
×1

Software apps and online services

MicroPython
MicroPython

Story

Read more

Schematics

MicroPython Retro FM Radio

You'll need to attach your own audio amplifier if you want to play music directly to a speaker.

Code

MicroPython Retro FM Radio

MicroPython
See https://github.com/alankrantas/micropython-TEA5767 for more info. Also, al built-inl frequencies in the code are local stations around Taipei, Taiwan.
# FM Radio on ESP8266 and TEA5767 by Alan Wang
# TEA5767 driver: https://github.com/alankrantas/micropython-TEA5767
from machine import Pin, I2C
import utime, ssd1306, TEA5767

# frequency range and default frequency
freq_limit = (87.5, 108.0)
freq = freq_limit[0]

# read freq saved from last time if possible
try:
    with open('station.text', 'r') as file:
        freq = float(file.read())
except:
    pass

# pins for rotary encoder
# CLK (clock) -> D5 (GPIO 14)
# dta (data) -> D6 (GPIO 12)
# sw (switch) -> D7 (GPIO 13)
rotary_clk = Pin(14, Pin.IN, Pin.PULL_UP)
rotary_dta = Pin(12, Pin.IN, Pin.PULL_UP)
rotary_sw = Pin(13, Pin.IN, Pin.PULL_UP)
rotary_clk_prev = rotary_clk

# pins for LED (D0, GPIO 16)
led = Pin(16, Pin.OUT)

# I2C
# SCL -> D1 (GPIO 5)
# SDA -> D2 (GPIO 4)
i2c = I2C(scl=Pin(5, Pin.IN, Pin.PULL_UP), sda=Pin(4, Pin.IN, Pin.PULL_UP), freq=400000)

# SSD1306 OLED
oled = ssd1306.SSD1306_I2C(128, 64, i2c)

# TEA5767 radio
radio = TEA5767.Radio(i2c, freq=freq, stereo=False)

# display current frequency
def display_freq():
    oled.fill(0)
    oled.text('Retro FM Radio', 16, 4)
    oled.text('- ' + '{:>5}'.format(str(round(freq, 1))) + ' MHz -', 32, 20)
    oled.show()
    
# update radio
def update_radio():
    global freq
    freq = round(freq, 1)
    if freq < freq_limit[0]:
        freq = freq_limit[1]
    elif freq > freq_limit[1]:
        freq = freq_limit[0]
    led.off()
    radio.set_frequency(freq=freq)
    display_freq()
    led.on()

update_radio()

while True:

  # save current freq to local text file
  # when the switch of rotary encoder is pressed
  if rotary_sw.value() == 0:
      try:
          with open('station.text', 'w') as file:
              file.write(str(freq))
          oled.fill(0)
          oled.text('Station saved...', 0, 12)
          oled.show()
      except:
          pass
      utime.sleep_ms(500)
      display_freq()

  # rotary encoder rotatoin status (change freq and update radio)
  if rotary_clk_prev == 0 and rotary_clk.value() == 1:
      if rotary_dta.value() == 0:
          freq += 0.1
          update_radio()
      else:
          freq -= 0.1
          update_radio()
            
  rotary_clk_prev = rotary_clk.value()
  utime.sleep_ms(1)

Credits

Alan Wang

Alan Wang

32 projects • 102 followers
Please do not ask me for free help for school or company projects. My time is not open sourced and you cannot buy it with free compliments.

Comments