Simple test

Ensure your device works with this simple test.

examples/si4713_simpletest.py
 1# SPDX-FileCopyrightText: 2018 Tony DiCola for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of using the SI4743 RDS FM transmitter.
 5
 6import time
 7import board
 8import digitalio
 9import adafruit_si4713
10
11# Specify the FM frequency to transmit on in kilohertz.  As the datasheet
12# mentions you can only specify 50khz steps!
13FREQUENCY_KHZ = 102300  # 102.300mhz
14
15# Initialize I2C bus.
16i2c = board.I2C()  # uses board.SCL and board.SDA
17# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
18
19# Initialize SI4713.
20# si4713 = adafruit_si4713.SI4713(i2c)
21
22# Alternatively you can specify the I2C address of the device if it changed:
23# si4713 = adafruit_si4713.SI4713(i2c, address=0x11)
24
25# If you hooked up the reset line you should specify that too.  Make sure
26# to pass in a DigitalInOut instance.  You will need the reset pin with the
27# Raspberry Pi, and probably other devices:
28si_reset = digitalio.DigitalInOut(board.D5)
29
30print("initializing si4713 instance")
31si4713 = adafruit_si4713.SI4713(i2c, reset=si_reset, timeout_s=0.5)
32print("done")
33
34# Measure the noise level for the transmit frequency (this assumes automatic
35# antenna capacitance setting, but see below to adjust to a specific value).
36noise = si4713.received_noise_level(FREQUENCY_KHZ)
37# Alternatively measure with a specific frequency and antenna capacitance.
38# This is not common but you can specify antenna capacitance as a value in pF
39# from 0.25 to 47.75 (will use 0.25 steps internally).  If you aren't sure
40# about this value, stick with the default automatic capacitance above!
41# noise = si4713.received_noise_level(FREQUENCY_KHZ, 0.25)
42print("Noise at {0:0.3f} mhz: {1} dBuV".format(FREQUENCY_KHZ / 1000.0, noise))
43
44# Tune to transmit with 115 dBuV power (max) and automatic antenna tuning
45# capacitance (default, what you probably want).
46si4713.tx_frequency_khz = FREQUENCY_KHZ
47si4713.tx_power = 115
48
49# Configure RDS broadcast with program ID 0xADAF (a 16-bit value you specify).
50# You can also set the broadcast station name (up to 96 bytes long) and
51# broadcast buffer/song information (up to 106 bytes long).  Setting these is
52# optional and you can later update them by setting the rds_station and
53# rds_buffer property respectively.  Be sure to explicitly specify station
54# and buffer as byte strings so the character encoding is clear.
55si4713.configure_rds(0xADAF, station=b"AdaRadio", rds_buffer=b"Adafruit g0th Radio!")
56
57# Print out some transmitter state:
58print("Transmitting at {0:0.3f} mhz".format(si4713.tx_frequency_khz / 1000.0))
59print("Transmitter power: {0} dBuV".format(si4713.tx_power))
60print(
61    "Transmitter antenna capacitance: {0:0.2} pF".format(si4713.tx_antenna_capacitance)
62)
63
64# Set GPIO1 and GPIO2 to actively driven outputs.
65si4713.gpio_control(gpio1=True, gpio2=True)
66
67# Main loop will print input audio level and state and blink the GPIOs.
68print("Broadcasting...")
69while True:
70    # Print input audio level and state.
71    print("Input level: {0} dBfs".format(si4713.input_level))
72    print("ASQ status: 0x{0:02x}".format(si4713.audio_signal_status))
73    # 'Blink' GPIO1 and GPIO2 alternatively on and off.
74    si4713.gpio_set(gpio1=True, gpio2=False)  # GPIO1 high, GPIO2 low
75    time.sleep(0.5)
76    si4713.gpio_set(gpio1=False, gpio2=True)  # GPIO1 low, GPIO2 high
77    time.sleep(0.5)