Skip to content

fixes for cpython & pi: hard reset before i2c init, tighten struct.unpack() #5

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

Merged
merged 5 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 15 additions & 3 deletions adafruit_si4713.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
22 changes: 13 additions & 9 deletions examples/simpletest.py → examples/si4713_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
reset = digitalio.DigitalInOut(board.D5)

print('initializing si4713 instance')
si4713 = adafruit_si4713.SI4713(i2c, reset=reset, timeout_s=0.5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename 'reset' to si_reset or reset_pin so you dont have 'reset=reset' :)

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).
Expand Down