diff --git a/adafruit_si4713.py b/adafruit_si4713.py index 6514753..204b581 100644 --- a/adafruit_si4713.py +++ b/adafruit_si4713.py @@ -120,11 +120,24 @@ class SI4713: def __init__(self, i2c, *, address=_SI4710_ADDR1, reset=None, timeout_s=0.1): self._timeout_s = timeout_s - self._device = i2c_device.I2CDevice(i2c, address) + # Configure reset line if it was provided. self._reset = reset + if self._reset is not None: self._reset.switch_to_output(value=True) + + # Toggle reset line low to reset the chip and then wait a bit for + # startup - this is necessary before initializing as an i2c device + # on at least the Raspberry Pi, and potentially elsewhere: + self._reset.value = True + time.sleep(0.01) + self._reset.value = False + time.sleep(0.01) + self._reset.value = True + time.sleep(0.25) + + self._device = i2c_device.I2CDevice(i2c, address) self.reset() # Check product ID. if self._get_product_number() != 13: @@ -382,8 +395,7 @@ def input_level(self): """ # Perform ASQ request, then parse out 8 bit _signed_ input level value. self._asq_status() - return struct.unpack('bbbbb', self._BUFFER)[4] - + return struct.unpack('bbbbb', self._BUFFER[0:5])[4] @property def audio_signal_status(self): """Retrieve the ASQ or audio signal quality status value from the chip. diff --git a/docs/examples.rst b/docs/examples.rst index 1af3138..b789f62 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -3,6 +3,6 @@ Simple test Ensure your device works with this simple test. -.. literalinclude:: ../examples/simpletest.py - :caption: examples/simpletest.py +.. literalinclude:: ../examples/si4713_simpletest.py + :caption: examples/si4713_simpletest.py :linenos: diff --git a/examples/simpletest.py b/examples/si4713_simpletest.py similarity index 85% rename from examples/simpletest.py rename to examples/si4713_simpletest.py index 685dba4..d4adf50 100644 --- a/examples/simpletest.py +++ b/examples/si4713_simpletest.py @@ -4,27 +4,31 @@ import board import busio +import digitalio import adafruit_si4713 - # Specify the FM frequency to transmit on in kilohertz. As the datasheet # mentions you can only specify 50khz steps! FREQUENCY_KHZ = 102300 # 102.300mhz - # Initialize I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialize SI4713. -si4713 = adafruit_si4713.SI4713(i2c) +# si4713 = adafruit_si4713.SI4713(i2c) + # Alternatively you can specify the I2C address of the device if it changed: -#si4713 = adafruit_si4713.SI4713(i2c, address=0x11) -# Also if you hooked up the reset line you can specify that too. Make sure -# to pass in a DigitalInOut instance: -#import digitalio -#reset = digitalio.DigitalInOut(board.D5) -#si4713 = adafruit_si4713.SI4713(i2c, reset=reset) +# si4713 = adafruit_si4713.SI4713(i2c, address=0x11) + +# If you hooked up the reset line you should specify that too. Make sure +# to pass in a DigitalInOut instance. You will need the reset pin with the +# Raspberry Pi, and probably other devices: +si_reset = digitalio.DigitalInOut(board.D5) + +print('initializing si4713 instance') +si4713 = adafruit_si4713.SI4713(i2c, reset=si_reset, timeout_s=0.5) +print('done') # Measure the noise level for the transmit frequency (this assumes automatic # antenna capacitance setting, but see below to adjust to a specific value).