Skip to content

Commit 5a0bd23

Browse files
committed
Limit I2C address range
For some reason, the ATTiny85 on the board seems to brick itself when using any address in the range of 0x40 to 0x77. Have not been able to determine the root cause, but this workaround should help prevent that.
1 parent 8f53629 commit 5a0bd23

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

examples/Example2-Change_I2C_Address.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@
4444
import time
4545
import sys
4646

47+
# If you've already changed the I2C address, change this to the current address!
48+
currentAddress = qwiic_soil_moisture_sensor.SOIL_MOISTURE_SENSOR_DEFAULT_ADDRESS
49+
4750
def runExample():
4851

4952
print("\nSparkFun Qwiic Soil Moisture Sensor Example 2 - Change I2C Address\n")
50-
mySoilSensor = qwiic_soil_moisture_sensor.QwiicSoilMoistureSensor()
53+
mySoilSensor = qwiic_soil_moisture_sensor.QwiicSoilMoistureSensor(currentAddress)
5154

5255
if mySoilSensor.is_connected() == False:
5356
print("The Qwiic Soil Moisture Sensor device isn't connected to the system. Please check your connection", \
@@ -56,17 +59,17 @@ def runExample():
5659

5760
mySoilSensor.begin()
5861

59-
print("\nReady!")
60-
print("\nEnter a new I2C address for the Qwiic Soil Moisture Sensor to use.")
61-
print("\nDon't use the 0x prefix. For instance if you wanted to")
62-
print("\nchange the address to 0x5B, you would type 5B and hit enter.")
63-
62+
print("Ready!")
63+
print("Enter a new I2C address for the Qwiic Soil Moisture Sensor to use.")
64+
print("Any address from 0x08 to 0x3F works.")
65+
print("Don't use the 0x prefix. For instance if you wanted to")
66+
print("change the address to 0x3B, you would type 3B and hit enter.")
6467

6568
newAddress = input("\nNew Address: ")
6669
newAddress = int(newAddress, 16)
6770

6871
# Check if the user entered a valid address
69-
if newAddress > 0x08 and newAddress < 0x77:
72+
if newAddress >= 0x08 and newAddress <= 0x3F:
7073
print("\nCharacters received and new address valid!")
7174
print("\nAttempting to set Soil Moisture Sensor address...")
7275

qwiic_soil_moisture_sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# Some devices have multiple available addresses - this is a list of these addresses.
3737
# NOTE: The first address in this list is considered the default I2C address for the
3838
# device.
39-
_FULL_ADDRESS_LIST = list(range(0x08,0x77+1)) # Full I2C Address List (excluding resrved addresses)
39+
_FULL_ADDRESS_LIST = list(range(0x08,0x40)) # Full I2C Address List (excluding resrved addresses)
4040
_FULL_ADDRESS_LIST.remove(SOIL_MOISTURE_SENSOR_DEFAULT_ADDRESS) # Remove Default Address of Soil Moisture Sensor from list
4141
_AVAILABLE_I2C_ADDRESS = [SOIL_MOISTURE_SENSOR_DEFAULT_ADDRESS] # Initialize with Default Address of Soil Moisture Sensor
4242
_AVAILABLE_I2C_ADDRESS.extend(_FULL_ADDRESS_LIST) # Add Full Range of I2C Addresses
@@ -173,8 +173,8 @@ def change_address(self, newAddress):
173173
:param newAddress: the new address to set the Soil Moisture Sensor reader to
174174
:rtype: bool
175175
"""
176-
if newAddress < 0x07 or newAddress > 0x78:
177176
return false
177+
if newAddress < 0x08 or newAddress > 0x3F:
178178

179179
self._i2c.writeByte(self.address, COMMAND_CHANGE_ADDRESS, newAddress)
180180

0 commit comments

Comments
 (0)