SparkFun Soil Moisture Sensor  v00.09.00-32-g3ccbaeb
Library for the SparkFun Soil Moisture Sensor
Loading...
Searching...
No Matches
SparkFun_Soil_Moisture_Sensor.h
Go to the documentation of this file.
1
2/*
3 *---------------------------------------------------------------------------------
4 *
5 * Copyright (c) 2025, SparkFun Electronics Inc.
6 *
7 * SPDX-License-Identifier: MIT
8 *
9 *---------------------------------------------------------------------------------
10 */
11
12 // A simple wrapper around the SparkFun Soil Moisture Sensor - based on the original example driver /example from Zio
13 // from here https://github.com/sparkfun/Zio-Qwiic-Soil-Moisture-Sensor
14
15#pragma once
16
17// To make the Arduino machine happy, include the toolkit header before the core implementation for this device
18#include <SparkFun_Toolkit.h>
20
21// Note:
22// The core of the implementation for this device library is in the SparkFun Toolkit object sfeDevSoilMoisture,
23// contained in the directory sfeTk. This object implements all functionality independent of the bus type, I2C or SPI.
24// The SparkFunSoilMoistureSensorI2C and SparkFunSoilMoistureSensorSPI classes below are the Arduino-specific, bus-specific
25// implementations that inherit from the core toolkit class.
26//
27//-----------------------------------------------------------------------------------------------
28// Define our Arduino Object - I2C version
30{
31 public:
36 bool begin(const uint8_t address = SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
37 {
38 // Setup Arduino I2C bus
39 _theI2CBus.init(wirePort, address);
40
41 // Begin the sensor and make sure it's connected.
42 return sfeDevSoilMoisture::begin(&_theI2CBus) == kSTkErrOk ? isConnected() : false;
43 }
44
48 {
49 return _theI2CBus.ping() == kSTkErrOk;
50 }
51
52 private:
53 sfeTkArdI2C _theI2CBus;
54};
55
56//-----------------------------------------------------------------------------------------------
57// Define our Arduino Object - SPI version
59{
60 public:
66 bool begin(const uint8_t csPin, SPIClass &spiPort = SPI, SPISettings spiSettings = SPISettings(100000, MSBFIRST, SPI_MODE0))
67 {
68
69 // Setup Arduino SPI bus
70 _theSPIBus.init(spiPort, spiSettings, csPin, true);
71
72 // Begin the sensor with the SPI bus connection
73 return (sfeDevSoilMoisture::begin(&_theSPIBus) == kSTkErrOk );
74 }
75
76 private:
77 sfeTkArdSPI _theSPIBus;
78};
Definition: SparkFun_Soil_Moisture_Sensor.h:30
bool begin(const uint8_t address=SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort=Wire)
Begins the Device.
Definition: SparkFun_Soil_Moisture_Sensor.h:36
bool isConnected()
Checks if the Device is connected.
Definition: SparkFun_Soil_Moisture_Sensor.h:47
Definition: SparkFun_Soil_Moisture_Sensor.h:59
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:66
Definition: sfeDevSoilMoisture.h:26
sfeTkError_t begin(sfeTkIBus *theBus=nullptr)
Start the driver/begin connecting/comms to the device.
Definition: sfeDevSoilMoisture.cpp:26
#define SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS
Definition: sfeDevSoilMoisture.h:20