It is very easy to get started using the ScoutMakes FM radio board with the RDA5807M radio module. There is a CircuitPython library along with example code in the Adafruit community bundle
First you'll need to wire up the sensor for a basic I2C connection. The STEMMA QT connectors make it very easy to use the breakout with microcontroller board such as the Adafruit QT Py.
Connect the FM board with a STEMMA QT cable to the microcontroller. You will also need a pair of 3.5mm headphones or a connection to an external speaker for sound output.
Connect a type-C USB cable to your QT Py board for power. The LED on the back of the FM board will light up indicating power on.
Place the FM breakout library tinkeringtech_rda5807m.mpy from the Adafruit community bundle in your QT Py lib folder. You can find the library in the unzipped bundle in the lib folder as tinkeringtech_rda5807m.mpy.
An example CircuitPython sketch is located in the community bundle in the examples folder as rda5807m_simpletest.py. The latest version can also be found on GitHub.
The version as of December 2022 is reproduced below.
# SPDX-FileCopyrightText: Copyright (c) 2022 tinkeringtech for TinkeringTech LLC
import time
import board
import supervisor
from adafruit_bus_device.i2c_device import I2CDevice
import tinkeringtech_rda5807m
# Preset stations. 8930 means 89.3 MHz, etc.
presets = [8930, 9510, 9710, 9950, 10100, 10110, 10650]
i_sidx = 3 # Starting at station with index 3
# Initialize i2c bus
# If your board does not have STEMMA_I2C(), change as appropriate.
i2c = board.STEMMA_I2C()
# Receiver i2c communication
address = 0x11
vol = 3 # Default volume
band = "FM"
rds = tinkeringtech_rda5807m.RDSParser()
# Display initialization
toggle_frequency = (
5 # Frequency at which the text changes between radio frequnecy and rds in seconds
)
rdstext = "No rds data"
# RDS text handle
def textHandle(rdsText):
global rdstext
rdstext = rdsText
print(rdsText)
rds.attach_text_callback(textHandle)
# Initialize the radio classes for use.
radio_i2c = I2CDevice(i2c, address)
radio = tinkeringtech_rda5807m.Radio(radio_i2c, rds, presets[i_sidx], vol)
radio.set_band(band) # Minimum frequency - 87 Mhz, max - 108 Mhz
# Read input from serial
def serial_read():
if supervisor.runtime.serial_bytes_available:
command = input()
command = command.split(" ")
cmd = command[0]
if cmd == "f":
value = command[1]
runSerialCommand(cmd, int(value))
else:
runSerialCommand(cmd)
time.sleep(0.3)
print("-> ", end="")
def runSerialCommand(cmd, value=0):
# Executes a command
# Starts with a character, and optionally followed by an integer, if required
global i_sidx
if cmd == "?":
print(
"""\
? help
+ increase volume
- decrease volume
> next preset
< previous preset
. scan up
, scan down
f direct frequency input; e.g., 99.50 MHz is f 9950, 101.10 MHz is f 10110
i station statuss mono/stereo mode
b bass boost
u mute/unmute
r get rssi data
e softreset chip
q stops the program"""
)
# Volume and audio control
elif cmd == "+":
v = radio.volume
if v < 15:
radio.set_volume(v + 1)
elif cmd == "-":
v = radio.volume
if v > 0:
radio.set_volume(v - 1)
# Toggle mute mode
elif cmd == "u":
radio.set_mute(not radio.mute)
# Toggle stereo mode
elif cmd == "s":
radio.set_mono(not radio.mono)
# Toggle bass boost
elif cmd == "b":
radio.set_bass_boost(not radio.bass_boost)
# Frequency control
elif cmd == ">":
# Goes to the next preset station
if i_sidx < (len(presets) - 1):
i_sidx = i_sidx + 1
radio.set_freq(presets[i_sidx])
elif cmd == "<":
# Goes to the previous preset station
if i_sidx > 0:
i_sidx = i_sidx - 1
radio.set_freq(presets[i_sidx])
# Set frequency
elif cmd == "f":
radio.set_freq(value)
# Seek up/down
elif cmd == ".":
radio.seek_up()
elif cmd == ",":
radio.seek_down()
# Display current signal strength
elif cmd == "r":
print("RSSI:", radio.get_rssi())
# Soft reset chip
elif cmd == "e":
radio.soft_reset()
# Not in help
elif cmd == "!":
radio.term()
elif cmd == "i":
# Display chip info
s = radio.format_freq()
print("Station: ", s)
print("Radio info:")
print("RDS ->", radio.rds)
print("TUNED ->", radio.tuned)
print("STEREO ->", not radio.mono)
print("Audio info:")
print("BASS ->", radio.bass_boost)
print("MUTE ->", radio.mute)
print("SOFTMUTE ->", radio.soft_mute)
print("VOLUME ->", radio.volume)
print_rds = False
runSerialCommand("?", 0)
print("-> ", end="")
while True:
serial_read()
radio.check_rds()
new_time = time.monotonic()
serial_read()
To run this example, we used the Mu Python code editor. If the code is running correctly on your board, you will see an output like below on your serial monitor in Mu.
The menu allows for control of the FM module. Just type in the desired command to view an output or send a particular setting command to the module. For example, if you want to increase the volume, type + and hit enter on the serial console
By default, the FM board will tune to FM 99.5 MHz. If this is not a suitable channel for your area, you can scan for other stations by entering the > or < command on the serial console to scan for available frequencies in your area.
Here is a great resource for finding FM radio stations in your area in the US FM radio channel locator
If the FM radio station that you are tuned into has Radio Data System (RDS), you will start to see the output of RDS on the serial monitor in real-time. You may notice garbage data initially as reception improves. If the radio signal is weak, you will see continuous garbage RDS output. Move to an area with better reception, or tune to a frequency that has a stronger signal for your area. You may see the signal strength by issuing a "r" command on the console.
Have fun playing with this awesome FM module!
Page last edited March 08, 2024
Text editor powered by tinymce.