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