SparkFun Soil Moisture Sensor  v00.09.00-32-g3ccbaeb
Library for the SparkFun Soil Moisture Sensor
Loading...
Searching...
No Matches
sfeDevSoilMoisture.h
Go to the documentation of this file.
1/*
2 *---------------------------------------------------------------------------------
3 *
4 * Copyright (c) 2025, SparkFun Electronics Inc.
5 *
6 * SPDX-License-Identifier: MIT
7 *
8 *---------------------------------------------------------------------------------
9 */
10// Actual implementation of the soil moisture sensor - this is a platform "independent" implementation
11
12#pragma once
13
14#include <cstdint>
15
16// include the sparkfun toolkit headers
17#include <sfeTk/sfeToolKit.h>
18
19// Default I2C address for the sensor
20#define SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS 0x28
21
22// Max value for the sensor value (10-bit ADC) 2^10 = 1024-1
23#define SFE_SOIL_MOISTURE_MAX_VALUE 1023
24
26{
27
28 public:
29 // ctor
31 {
32 }
33
37 sfeTkError_t begin(sfeTkIBus *theBus = nullptr);
38
41 sfeTkError_t LEDOff(void);
42
45 sfeTkError_t LEDOn(void);
46
49 uint16_t readMoistureValue(void);
50
53 float readMoistureRatio(void);
54
57 float readMoisturePercentage(void);
58
62 sfeTkError_t changeSensorAddress(uint8_t newAddress);
63
64 protected:
65 // The toolkit bus the sensor is connected to
66 sfeTkIBus *_theBus;
67
68}; // class sfeDevSoilMoisture
Definition: sfeDevSoilMoisture.h:26
sfeDevSoilMoisture()
Definition: sfeDevSoilMoisture.h:30
float readMoistureRatio(void)
Reads the sensor value and returns the moisture ratio from the sensor (0 - 1.0)
Definition: sfeDevSoilMoisture.cpp:75
sfeTkIBus * _theBus
Definition: sfeDevSoilMoisture.h:66
sfeTkError_t LEDOn(void)
Turns on the on-board LED.
Definition: sfeDevSoilMoisture.cpp:50
uint16_t readMoistureValue(void)
Reads the moisture value from the sensor.
Definition: sfeDevSoilMoisture.cpp:61
sfeTkError_t changeSensorAddress(uint8_t newAddress)
Changes the I2C address of the sensor.
Definition: sfeDevSoilMoisture.cpp:91
float readMoisturePercentage(void)
Reads the sensor value and returns the moisture percentage from the sensor (0 - 100%)
Definition: sfeDevSoilMoisture.cpp:85
sfeTkError_t begin(sfeTkIBus *theBus=nullptr)
Start the driver/begin connecting/comms to the device.
Definition: sfeDevSoilMoisture.cpp:26
sfeTkError_t LEDOff(void)
Turns off the on-board LED.
Definition: sfeDevSoilMoisture.cpp:40