![]() |
SparkFun Soil Moisture Sensor
v1.0.1-2-g96f40cb
Library for the SparkFun Soil Moisture Sensor
|
Class representing the soil moisture sensor. More...
#include <sfDevSoilMoisture.h>
Public Member Functions | |
sfDevSoilMoisture () | |
sfTkError_t | begin (sfTkIBus *theBus=nullptr) |
Initializes communication with the soil moisture sensor. More... | |
sfTkError_t | LEDOff (void) |
Turns off the on-board LED. More... | |
sfTkError_t | LEDOn (void) |
Turns on the on-board LED. More... | |
uint16_t | readMoistureValue (void) |
Reads the moisture value from the sensor. More... | |
float | readMoistureRatio (void) |
Reads the sensor value and returns the moisture ratio from the sensor. More... | |
float | readMoisturePercentage (void) |
Reads the sensor value and returns the moisture percentage from the sensor. More... | |
sfTkError_t | setI2CAddress (uint8_t newAddress) |
Changes the I2C address of the sensor. More... | |
uint8_t | address (void) |
Returns the current address of the sensor. More... | |
Protected Attributes | |
sfTkIBus * | _theBus |
The toolkit bus the sensor is connected to. More... | |
Class representing the soil moisture sensor.
This class provides an interface to the soil moisture sensor, allowing for initialization, reading moisture values and controlling the on-board LED.
|
inline |
uint8_t sfDevSoilMoisture::address | ( | void | ) |
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.
sfTkError_t sfDevSoilMoisture::begin | ( | sfTkIBus * | theBus = nullptr | ) |
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.
theBus | Pointer to an I2C toolkit object. If nullptr, uses previously set bus |
sfTkError_t sfDevSoilMoisture::LEDOff | ( | void | ) |
Turns off the on-board LED.
Disables the sensor's built-in LED
sfTkError_t sfDevSoilMoisture::LEDOn | ( | void | ) |
Turns on the on-board LED.
Enables the sensor's built-in LED by sending the appropriate command
float sfDevSoilMoisture::readMoisturePercentage | ( | void | ) |
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%.
float sfDevSoilMoisture::readMoistureRatio | ( | void | ) |
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.
uint16_t sfDevSoilMoisture::readMoistureValue | ( | void | ) |
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.
sfTkError_t sfDevSoilMoisture::setI2CAddress | ( | uint8_t | newAddress | ) |
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
newAddress | The new I2C address to assign to the sensor |
|
protected |
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.