From 8c0242bb24f69c93c0ee574213cc67f8c3619750 Mon Sep 17 00:00:00 2001 From: Pavel Ferencz Date: Tue, 15 Jun 2021 19:38:46 +0300 Subject: [PATCH] FM transmitter app for initialization and configuration on the badge central expansion port. An FM scanning tool that looks for two quietest frequencies in the FM broadcast spectrum (76-108 MHZ) --- apps/fm_transmitter/app.json | 5 +++ apps/fm_transmitter/icon.bmp | Bin 0 -> 190 bytes apps/fm_transmitter/rtx.py | 60 +++++++++++++++++++++++++++++++++ apps/radio/radio.py | 2 +- requirements.txt | 1 + tools/find_quietest_fm_freq.py | 39 +++++++++++++++++++++ 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 apps/fm_transmitter/app.json create mode 100644 apps/fm_transmitter/icon.bmp create mode 100644 apps/fm_transmitter/rtx.py create mode 100644 tools/find_quietest_fm_freq.py diff --git a/apps/fm_transmitter/app.json b/apps/fm_transmitter/app.json new file mode 100644 index 0000000..fe6b3d4 --- /dev/null +++ b/apps/fm_transmitter/app.json @@ -0,0 +1,5 @@ +{ +"menu_item": "FM Transmitter", +"author": "Pavel Ferencz", +"main": "rtx.py" +} \ No newline at end of file diff --git a/apps/fm_transmitter/icon.bmp b/apps/fm_transmitter/icon.bmp new file mode 100644 index 0000000000000000000000000000000000000000..a939c84cc76b5471b726fac2585b6c112226cde3 GIT binary patch literal 190 zcmY++u?c`M5Czbm%F+o$OQ%qyg-e=lK}^L~ zQt>b_JOM&e7KQnZs)Bymfz$y>RI&G@lOM(UQ3 0: + pass + +def main(): + return RadioTx() \ No newline at end of file diff --git a/apps/radio/radio.py b/apps/radio/radio.py index 723e9d2..e0423a1 100644 --- a/apps/radio/radio.py +++ b/apps/radio/radio.py @@ -13,7 +13,7 @@ class RadioApp: def __init__(self): self.fm = SI4703(badge.i2c, DigitalInOut(board.D2), channel=103) self.fm.reset() - self.fm.volume = 7 + self.fm.volume = 1 def render(self): screen = displayio.Group() diff --git a/requirements.txt b/requirements.txt index 7f071b4..cf63550 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ neopixel==6.0.3 adafruit_ble==8.0.0 adafruit_display_text==2.18.3 adafruit_display_shapes==2.0.8 +adafruit_si4713==1.2.6 \ No newline at end of file diff --git a/tools/find_quietest_fm_freq.py b/tools/find_quietest_fm_freq.py new file mode 100644 index 0000000..f272825 --- /dev/null +++ b/tools/find_quietest_fm_freq.py @@ -0,0 +1,39 @@ +# Run this code through shell in interactive mode in order to find the quietest +# Frequency available in the area, use an RF-choked USB cable in order to +# avoid measuring the noise of the laptop power supply. +from arambadge import badge +from si4703 import SI4703 +import board +from digitalio import DigitalInOut +from time import sleep +fm = SI4703(badge.i2c, DigitalInOut(board.D2), channel=106.8) +fm.reset() +fm.volume=0 +sleep(0.2) +freq_to_rssi = {} + +# This loop might take about 1.5 minutes to finish +# The theoretical optimum is 64 seconds, but actually +# it takes about a minute and a half, because setting +# the channel takes time. +for i in map(lambda x: x/10.0, range(760, 1080, 1)): + fm.channel=i + # Let the noise stabilize after changing the RX frequency + sleep(0.2) + freq_to_rssi[i] = fm.read_registers()['STATUSRSSI'] & 0xff + + + + +for i in sorted(freq_to_rssi, key=freq_to_rssi.get): + print('%5.1f\t%d' % (i, freq_to_rssi[i])) + + + + +quietest_freq_1 = min(freq_to_rssi, key=freq_to_rssi.get) +del freq_to_rssi[quietest_freq_1] +quietest_freq_2 = min(freq_to_rssi, key=freq_to_rssi.get) +print("Quietest frequency 1:", quietest_freq_1) +print("Quietest frequency 2:", quietest_freq_2) +