SparkFun Soil Moisture Sensor  v1.0.1-2-g96f40cb
Library for the SparkFun Soil Moisture Sensor
Loading...
Searching...
No Matches
SparkFun_Soil_Moisture_Sensor.h
Go to the documentation of this file.
1
17// A simple wrapper around the SparkFun Soil Moisture Sensor - based on the original example driver /example from Zio
18// from here https://github.com/sparkfun/Zio-Qwiic-Soil-Moisture-Sensor
19
20#pragma once
21
22// To make the Arduino machine happy, include the toolkit header before the core implementation for this device
23// clang-format off
24#include <SparkFun_Toolkit.h>
26// clang-format on
27
28// Note:
29// The core of the implementation for this device library is in the SparkFun Toolkit object sfDevSoilMoisture,
30// contained in the directory sfTk. This object implements all functionality independent of the bus type, I2C or SPI.
31// The SparkFunSoilMoistureSensorI2C and SparkFunSoilMoistureSensorSPI classes below are the Arduino-specific,
32// bus-specific implementations that inherit from the core toolkit class.
33//
34//-----------------------------------------------------------------------------------------------
35// Define our Arduino Object - I2C version
37{
38 public:
49 bool begin(const uint8_t address = SF_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
50 {
51 // Setup Arduino I2C bus
52 _theI2CBus.init(wirePort, address);
53
54 // Begin the sensor and make sure it's connected.
55 return sfDevSoilMoisture::begin(&_theI2CBus) == ksfTkErrOk ? isConnected() : false;
56 }
57
67 {
68 return _theI2CBus.ping() == ksfTkErrOk;
69 }
70
71 private:
72 sfTkArdI2C _theI2CBus;
73};
74
75//-----------------------------------------------------------------------------------------------
76// Define our Arduino Object - SPI version
78{
79 public:
92 bool begin(const uint8_t csPin, SPIClass &spiPort = SPI,
93 SPISettings spiSettings = SPISettings(100000, MSBFIRST, SPI_MODE0))
94 {
95
96 // Setup Arduino SPI bus
97 _theSPIBus.init(spiPort, spiSettings, csPin, true);
98
99 // Begin the sensor with the SPI bus connection
100 return (sfDevSoilMoisture::begin(&_theSPIBus) == ksfTkErrOk);
101 }
102
103 private:
104 sfTkArdSPI _theSPIBus;
105};
Definition: SparkFun_Soil_Moisture_Sensor.h:37
bool isConnected()
Checks if the device is connected and responding.
Definition: SparkFun_Soil_Moisture_Sensor.h:66
bool begin(const uint8_t address=SF_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort=Wire)
Begins the Device.
Definition: SparkFun_Soil_Moisture_Sensor.h:49
Definition: SparkFun_Soil_Moisture_Sensor.h:78
bool begin(const uint8_t csPin, SPIClass &spiPort=SPI, SPISettings spiSettings=SPISettings(100000, MSBFIRST, SPI_MODE0))
Begins the Device with SPI as the communication bus.
Definition: SparkFun_Soil_Moisture_Sensor.h:92
Class representing the soil moisture sensor.
Definition: sfDevSoilMoisture.h:51
sfTkError_t begin(sfTkIBus *theBus=nullptr)
Initializes communication with the soil moisture sensor.
Definition: sfDevSoilMoisture.cpp:50
uint8_t address(void)
Returns the current address of the sensor.
Definition: sfDevSoilMoisture.cpp:137
Header file for the soil moisture sensor class.
#define SF_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS
Default I2C address for the soil moisture sensor.
Definition: sfDevSoilMoisture.h:34