Skip to content

Commit 6d10c42

Browse files
committed
added method to change sensor address
1 parent 044e97c commit 6d10c42

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/sfeTk/sfeDevSoilMoisture.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ uint16_t sfeDevSoilMoisture::readMoistureValue(void)
7272

7373
return value;
7474
}
75+
76+
//----------------------------------------------------------------------------------------
77+
sfeTkError_t sfeDevSoilMoisture::changeSensorAddress(uint8_t newAddress)
78+
{
79+
if (_theBus == nullptr)
80+
return kSTkErrFail;
81+
82+
// Validate the new address
83+
if (newAddress < 0x07 || newAddress > 0x78)
84+
return kSTkErrFail;
85+
86+
// Send the command to change the address
87+
return _theBus->writeRegisterByte(kCommandChangeAddress, newAddress);
88+
}

src/sfeTk/sfeDevSoilMoisture.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class sfeDevSoilMoisture
4343
/// @return The moisture value - a resistance reading between 0 and 1023
4444
uint16_t readMoistureValue(void);
4545

46+
/// @brief Changes the I2C address of the sensor
47+
/// @param newAddress The new I2C address to assign to the sensor
48+
/// @return kSTkErrOk if successful, otherwise an error code
49+
sfeTkError_t changeSensorAddress(uint8_t newAddress);
50+
4651
protected:
4752
// The I2C bus the sensor is connected to
4853
sfeTkII2C *_theBus;

0 commit comments

Comments
 (0)