#include <SparkFun_Soil_Moisture_Sensor.h>
|
sfTkIBus * | _theBus |
| The toolkit bus the sensor is connected to. More...
|
|
◆ address()
uint8_t sfDevSoilMoisture::address |
( |
void |
| ) |
|
|
inherited |
Returns the current address of the sensor.
This function returns the current I2C address of the sensor if using I2C, or the Chip Select (CS) pin if using SPI.
- Returns
- The current I2C address of the sensor, or the CS pin for SPI
◆ begin() [1/2]
Begins the Device.
Initializes the soil moisture sensor for I2C communication using the specified I2C address and wire port.
- Parameters
-
address | I2C device address to use for the sensor (default is SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS) |
wirePort | Wire port to use for I2C communication (default is Wire) |
- Returns
- true if successful, false otherwise
◆ begin() [2/2]
sfTkError_t sfDevSoilMoisture::begin |
( |
sfTkIBus * |
theBus = nullptr | ) |
|
|
inherited |
Initializes communication with the soil moisture sensor.
This function must be called before any other methods. It establishes communication with the sensor using the provided I2C bus interface.
- Parameters
-
theBus | Pointer to an I2C toolkit object. If nullptr, uses previously set bus |
- Returns
- ksfTkErrOk if initialization succeeds
-
ksfTkErrBusNotInit if no valid bus interface is provided
◆ isConnected()
bool SparkFunSoilMoistureSensor::isConnected |
( |
| ) |
|
|
inline |
Checks if the device is connected and responding.
Tests communication with the sensor by attempting to ping it over I2C. A successful ping indicates the sensor is properly connected and responding.
- Returns
- true if the sensor responds to communication attempts, false otherwise
◆ LEDOff()
sfTkError_t sfDevSoilMoisture::LEDOff |
( |
void |
| ) |
|
|
inherited |
Turns off the on-board LED.
Disables the sensor's built-in LED
- Returns
- ksfTkErrOk if LED was successfully turned off
-
ksfTkErrBusNotInit if no bus interface is configured
-
ksfTkErrFail if sensor doesn't respond or a communication error occurs
- See also
- LEDOn()
◆ LEDOn()
sfTkError_t sfDevSoilMoisture::LEDOn |
( |
void |
| ) |
|
|
inherited |
Turns on the on-board LED.
Enables the sensor's built-in LED by sending the appropriate command
- Returns
- ksfTkErrOk if LED was successfully turned on
-
ksfTkErrBusNotInit if no bus interface is configured
-
ksfTkErrFail if sensor doesn't respond or a communication error occurs
- See also
- LEDOff()
◆ readMoisturePercentage()
float sfDevSoilMoisture::readMoisturePercentage |
( |
void |
| ) |
|
|
inherited |
Reads the sensor value and returns the moisture percentage from the sensor.
This function reads the raw moisture value from the sensor and converts it to a percentage between 0 and 100%.
- Returns
- The moisture percentage, where 0% indicates a dry sensor and 100% indicates a wet sensor
◆ readMoistureRatio()
float sfDevSoilMoisture::readMoistureRatio |
( |
void |
| ) |
|
|
inherited |
Reads the sensor value and returns the moisture ratio from the sensor.
This function reads the raw moisture value from the sensor and converts it to a ratio between 0 and 1.0.
- Returns
- The moisture ratio, where 0 indicates a dry sensor and 1.0 indicates a wet sensor
- Note
- On error, this method returns 0
◆ readMoistureValue()
uint16_t sfDevSoilMoisture::readMoistureValue |
( |
void |
| ) |
|
|
inherited |
Reads the moisture value from the sensor.
This function reads the raw moisture value from the sensor, which is a resistance reading between 0 and 1023.
- Returns
- The moisture value - a resistance reading between 0 and 1023
- Note
- A value of 0 indicates a wet sensor, while 1023 indicates a dry sensor
-
On error, this method returns 0
◆ setI2CAddress()
sfTkError_t sfDevSoilMoisture::setI2CAddress |
( |
uint8_t |
newAddress | ) |
|
|
inherited |
Changes the I2C address of the sensor.
This function sets a new I2C address for the sensor. The new address will be used for all future I2C communication with the sensor. This value is persistent
- Parameters
-
newAddress | The new I2C address to assign to the sensor |
- Returns
- ksfTkErrOk if successful, otherwise an error code
- Note
- If communicating via I2C, the provided address is used for future I2C communication
◆ _theBus
sfTkIBus* sfDevSoilMoisture::_theBus |
|
protectedinherited |
The toolkit bus the sensor is connected to.
This member variable holds a pointer to the bus interface (I2C or SPI) used for communication with the soil moisture sensor.
The documentation for this class was generated from the following file: