Skip to content

Commit c5697ad

Browse files
authored
Merge pull request #5 from adafruit/raspi_fixen
fixes for cpython & pi: hard reset before i2c init, tighten struct.unpack()
2 parents 942eb5d + cfde317 commit c5697ad

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

adafruit_si4713.py

+15-3
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.

docs/examples.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ Simple test
33

44
Ensure your device works with this simple test.
55

6-
.. literalinclude:: ../examples/simpletest.py
7-
:caption: examples/simpletest.py
6+
.. literalinclude:: ../examples/si4713_simpletest.py
7+
:caption: examples/si4713_simpletest.py
88
:linenos:

examples/simpletest.py renamed to examples/si4713_simpletest.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@
44

55
import board
66
import busio
7+
import digitalio
78

89
import adafruit_si4713
910

10-
1111
# Specify the FM frequency to transmit on in kilohertz. As the datasheet
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+
si_reset = digitalio.DigitalInOut(board.D5)
28+
29+
print('initializing si4713 instance')
30+
si4713 = adafruit_si4713.SI4713(i2c, reset=si_reset, timeout_s=0.5)
31+
print('done')
2832

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

0 commit comments

Comments
 (0)