Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FM transmitter app for initialization and configuration on the badge central expansion port. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/fm_transmitter/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"menu_item": "FM Transmitter",
"author": "Pavel Ferencz",
"main": "rtx.py"
}
Binary file added apps/fm_transmitter/icon.bmp
Binary file not shown.
60 changes: 60 additions & 0 deletions apps/fm_transmitter/rtx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from arambadge import badge
from adafruit_si4713 import SI4713
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_display_shapes.rect import Rect
import board
from digitalio import DigitalInOut
from time import time

class RadioTx:
def __init__(self):
self.fm = SI4713(badge.i2c, reset = DigitalInOut(board.GPIO2), timeout_s = 0.5)
self.fm.reset()
self.fm.tx_frequency_khz = 106800
self.fm.tx_power = 115

def process_input(self):
buttons = badge.gamepad.get_pressed()
if buttons & badge.BTN_LEFT:
return True
if buttons & badge.BTN_RIGHT:
return True
if buttons & badge.BTN_UP:
return True
if buttons & badge.BTN_DOWN:
return True
if buttons & badge.BTN_ACTION:
self.running = False
return True
return False

def render(self):
screen = displayio.Group()

screen.append(Rect(0, 0, badge.display.width, 32, fill=0xffffff))
banner_image = displayio.OnDiskBitmap(open("/apps/radio/icon.bmp", "rb"))
banner = displayio.TileGrid(banner_image, pixel_shader=displayio.ColorConverter(), x=4, y=-2)
screen.append(banner)

app_label = label.Label(terminalio.FONT, text="FM Transmitter", color=0x0)
app_label_group = displayio.Group(scale=2, x=40, y=14)
app_label_group.append(app_label)
screen.append(app_label_group)

badge.display.show(screen)

def run(self):
display = badge.display
self.running = True

while self.running:
self.render()
if self.process_input():
display.refresh()
while display.time_to_refresh > 0:
pass

def main():
return RadioTx()
2 changes: 1 addition & 1 deletion apps/radio/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 39 additions & 0 deletions tools/find_quietest_fm_freq.py
Original file line number Diff line number Diff line change
@@ -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)