Skip to content

Commit 928f298

Browse files
author
Brennen Bearnes
committed
fixes for cpython & pi: hard reset before i2c init, tighten struct.unpack()
It's necessary to hook up the reset pin and toggle it before initializing the i2c device, at least with some hardware (including the Raspberry Pi). struct.unpack() is stricter about inputs on CPython than under CircuitPython.
1 parent 942eb5d commit 928f298

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

adafruit_si4713.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,24 @@ class SI4713:
120120

121121
def __init__(self, i2c, *, address=_SI4710_ADDR1, reset=None, timeout_s=0.1):
122122
self._timeout_s = timeout_s
123-
self._device = i2c_device.I2CDevice(i2c, address)
123+
124124
# Configure reset line if it was provided.
125125
self._reset = reset
126+
126127
if self._reset is not None:
127128
self._reset.switch_to_output(value=True)
129+
130+
# Toggle reset line low to reset the chip and then wait a bit for
131+
# startup - this is necessary before initializing as an i2c device
132+
# on at least the Raspberry Pi, and potentially elsewhere:
133+
self._reset.value = True
134+
time.sleep(0.01)
135+
self._reset.value = False
136+
time.sleep(0.01)
137+
self._reset.value = True
138+
time.sleep(0.25)
139+
140+
self._device = i2c_device.I2CDevice(i2c, address)
128141
self.reset()
129142
# Check product ID.
130143
if self._get_product_number() != 13:
@@ -382,8 +395,7 @@ def input_level(self):
382395
"""
383396
# Perform ASQ request, then parse out 8 bit _signed_ input level value.
384397
self._asq_status()
385-
return struct.unpack('bbbbb', self._BUFFER)[4]
386-
398+
return struct.unpack('bbbbb', self._BUFFER[0:5])[4]
387399
@property
388400
def audio_signal_status(self):
389401
"""Retrieve the ASQ or audio signal quality status value from the chip.

examples/simpletest.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@
1212
# mentions you can only specify 50khz steps!
1313
FREQUENCY_KHZ = 102300 # 102.300mhz
1414

15-
1615
# Initialize I2C bus.
1716
i2c = busio.I2C(board.SCL, board.SDA)
1817

1918
# Initialize SI4713.
20-
si4713 = adafruit_si4713.SI4713(i2c)
19+
# si4713 = adafruit_si4713.SI4713(i2c)
20+
2121
# 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)
22+
# si4713 = adafruit_si4713.SI4713(i2c, address=0x11)
23+
24+
# If you hooked up the reset line you should specify that too. Make sure
25+
# to pass in a DigitalInOut instance. You will need the reset pin with the
26+
# Raspberry Pi, and probably other devices:
27+
import digitalio
28+
reset = digitalio.DigitalInOut(board.D5)
29+
30+
print('initializing si4713 instance')
31+
si4713 = adafruit_si4713.SI4713(i2c, reset=reset, timeout_s=0.5)
32+
print('done')
2833

2934
# Measure the noise level for the transmit frequency (this assumes automatic
3035
# antenna capacitance setting, but see below to adjust to a specific value).

0 commit comments

Comments
 (0)