Skip to content

Commit 2f64ef1

Browse files
committed
Update I2C addresses and tidying up
1 parent e410140 commit 2f64ef1

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

examples/Example1-GetReadings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@
4646

4747
def runExample():
4848

49-
print("\nSparkFun qwiic soil moisture sensor Example 1\n")
49+
print("\nSparkFun Qwiic Soil Moisture Sensor Example 1\n")
5050
mySoilSensor = qwiic_soil_moisture_sensor.QwiicSoilMoistureSensor()
5151

52-
if mySoilSensor.connected == False:
52+
if mySoilSensor.is_connected == False:
5353
print("The Qwiic Soil Moisture Sensor device isn't connected to the system. Please check your connection", \
5454
file=sys.stderr)
5555
return

qwiic_soil_moisture_sensor.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,34 @@
1414

1515
import qwiic_i2c
1616

17-
1817
#======================================================================
19-
# Define the device name and I2C addresses. These are set in the class defintion
20-
# as class variables, making them avilable without having to create a class instance.
18+
# Basic setup of I2C commands and available I2C Addresses
2119
#
2220
#
2321
# The name of this device - note this is private
2422
_DEFAULT_NAME = "Qwiic Soil Moisture Sensor"
2523

26-
# Some devices have multiple available addresses - this is a list of these addresses.
27-
# NOTE: The first address in this list is considered the default I2C address for the
28-
# device.
29-
_AVAILABLE_I2C_ADDRESS = [0x28, 0x29] ###LAC FIX ADDRESSES
3024

31-
# Register addresses
25+
# Command addresses
3226
COMMAND_LED_OFF = 0x00
3327
COMMAND_LED_ON = 0x01
3428
COMMAND_CHANGE_ADDRESS = 0x03
3529
COMMAND_GET_VALUE = 0x05
3630
COMMAND_NOTHING_NEW = 0x99
3731
SENSOR_STATUS = 0x3F
32+
SOIL_MOISTURE_SENSOR_DEFAULT_ADDRESS = 0x28
33+
34+
###############################################################################
35+
###############################################################################
36+
# Some devices have multiple available addresses - this is a list of these addresses.
37+
# NOTE: The first address in this list is considered the default I2C address for the
38+
# device.
39+
_FULL_ADDRESS_LIST = list(range(0x08,0x77+1)) # Full I2C Address List (excluding resrved addresses)
40+
_FULL_ADDRESS_LIST.remove(SOIL_MOISTURE_SENSOR_DEFAULT_ADDRESS >> 1) # Remove Default Address of Soil Moisture Sensor from list
41+
_AVAILABLE_I2C_ADDRESS = [SOIL_MOISTURE_SENSOR_DEFAULT_ADDRESS >> 1] # Initialize with Default Address of Soil Moisture Sensor
42+
_AVAILABLE_I2C_ADDRESS.extend(_FULL_ADDRESS_LIST) # Add Full Range of I2C Addresses
43+
44+
3845

3946
class QwiicSoilMoistureSensor(object):
4047
"""

0 commit comments

Comments
 (0)