|
44 | 44 | import time |
45 | 45 | import sys |
46 | 46 |
|
| 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 | + |
47 | 50 | def runExample(): |
48 | 51 |
|
49 | 52 | 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) |
51 | 54 |
|
52 | | - status = mySoilSensor.begin() |
53 | | - if status == False: |
54 | | - print ("\nStatus: ", status) |
| 55 | + if mySoilSensor.is_connected() == False: |
| 56 | + print("The Qwiic Soil Moisture Sensor device isn't connected to the system. Please check your connection", \ |
| 57 | + file=sys.stderr) |
| 58 | + return |
| 59 | + |
| 60 | + mySoilSensor.begin() |
55 | 61 |
|
56 | | - print("\nReady!") |
57 | | - print("\nEnter a new I2C address for the Qwiic Soil Moisture Sensor to use.") |
58 | | - print("\nDon't use the 0x prefix. For instance if you wanted to") |
59 | | - print("\nchange the address to 0x5B, you would type 5B and hit enter.") |
60 | | - |
| 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.") |
61 | 67 |
|
62 | 68 | newAddress = input("\nNew Address: ") |
63 | 69 | newAddress = int(newAddress, 16) |
64 | 70 |
|
65 | 71 | # Check if the user entered a valid address |
66 | | - if newAddress > 0x08 and newAddress < 0x77: |
| 72 | + if newAddress >= 0x08 and newAddress <= 0x3F: |
67 | 73 | print("\nCharacters received and new address valid!") |
68 | 74 | print("\nAttempting to set Soil Moisture Sensor address...") |
69 | 75 |
|
|
0 commit comments