Skip to content

Pull develop/v1.0.0 to main in prep for publish #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-compile-sketch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
run: |
arduino-cli config set library.enable_unsafe_install true
arduino-cli version
arduino-cli lib install --git-url https://github.com/sparkfun/SparkFun_Toolkit.git#dc0f0ca
arduino-cli lib install "SparkFun Toolkit"@1.0.0

- name: Compile Sketch
run: arduino-cli compile --fqbn ${{ matrix.board.fqbn }} examples/Example_01_BasicReadings --library .
Expand Down
2 changes: 1 addition & 1 deletion docs/doxygen/doxygen-config
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ALWAYS_DETAILED_SEC = YES
# operators of the base classes will not be shown.
# The default value is: NO.

INLINE_INHERITED_MEMB = NO
INLINE_INHERITED_MEMB = YES

# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
# before files name in the file list and in the header files. If set to NO the
Expand Down
10 changes: 5 additions & 5 deletions docs/doxygen/doxygen-custom/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!-- BEGIN opengraph metadata -->
<meta property="og:title" content="SparkFun Toolkit" />
<meta property="og:description" content="Common Functionality for Arduino Libraries" />
<meta property="og:url" content="https://docs.sparkfun.com/SparkFun_Toolkit/" />
<meta property="og:title" content="SparkFun Soil Moisture Arduino Library" />
<meta property="og:description" content="An Arduino Library implementation for the SparkFun Soil Moisture qwiic sensor" />
<meta property="og:url" content="https://docs.sparkfun.com/SparkFun_Soil_Moisture_Arduino_Library/" />
<!-- END opengraph metadata -->

<!-- BEGIN twitter metadata -->
<meta name="twitter:title" content="SparkFun Toolkit" />
<meta name="twitter:description" content="Common Functionality for Arduino Libraries." />
<meta name="twitter:title" content="SparkFun Soil Moisture Arduino Library" />
<meta name="twitter:description" content="An Arduino Library implementation for the SparkFun Soil Moisture qwiic sensor" />
<!-- END twitter metadata -->

<!--BEGIN PROJECT_NAME-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture_Sensor
#include <Wire.h>

SparkFunSoilMoistureSensorI2C mySoilSensor; // Create an instance of the sensor class
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class

// Some Dev boards have their QWIIC connector on Wire or Wire1
// This #ifdef will help this sketch work across more products
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture_Sensor
#include <Wire.h>

SparkFunSoilMoistureSensorI2C mySoilSensor; // Create an instance of the sensor class
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class

// Some Dev boards have their QWIIC connector on Wire or Wire1
// This #ifdef will help this sketch work across more products
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture_Sensor
#include <Wire.h>

SparkFunSoilMoistureSensorI2C mySoilSensor; // Create an instance of the sensor class
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class

// The plan:
// The value of the sensor has the following range:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "SparkFun_Soil_Moisture_Sensor.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_Soil_Moisture_Sensor
#include <Wire.h>

SparkFunSoilMoistureSensorI2C mySoilSensor; // Create an instance of the sensor class
SparkFunSoilMoistureSensor mySoilSensor; // Create an instance of the sensor class

// Define our alternate I2C address - the default address + 1
#define ALTERNATE_I2C_ADDRESS SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS + 1
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ category=Sensors
url=https://github.com/sparkfun/SparkFun_Soil_Moisture_Arduino_Library
architectures=*
includes=SparkFun_Soil_Moisture_Sensor.h
depends=SparkFun Toolkit
depends=SparkFun Toolkit >=1.0.0

27 changes: 14 additions & 13 deletions src/SparkFun_Soil_Moisture_Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author SparkFun Electronics
* @date 2025
* @copyright Copyright (c) 2025, SparkFun Electronics Inc. This project is released under the MIT License.
*
*
* SPDX-License-Identifier: MIT
*/

Expand All @@ -20,19 +20,20 @@
#pragma once

// To make the Arduino machine happy, include the toolkit header before the core implementation for this device
// clang-format off
#include <SparkFun_Toolkit.h>
#include "sfeTk/sfeDevSoilMoisture.h"

#include "sfTk/sfDevSoilMoisture.h"
// clang-format on

// Note:
// The core of the implementation for this device library is in the SparkFun Toolkit object sfeDevSoilMoisture,
// contained in the directory sfeTk. This object implements all functionality independent of the bus type, I2C or SPI.
// The core of the implementation for this device library is in the SparkFun Toolkit object sfDevSoilMoisture,
// contained in the directory sfTk. This object implements all functionality independent of the bus type, I2C or SPI.
// The SparkFunSoilMoistureSensorI2C and SparkFunSoilMoistureSensorSPI classes below are the Arduino-specific,
// bus-specific implementations that inherit from the core toolkit class.
//
//-----------------------------------------------------------------------------------------------
// Define our Arduino Object - I2C version
class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
class SparkFunSoilMoistureSensor : public sfDevSoilMoisture
{
public:
/**
Expand All @@ -45,13 +46,13 @@ class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
* @param wirePort Wire port to use for I2C communication (default is Wire)
* @return true if successful, false otherwise
*/
bool begin(const uint8_t address = SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
bool begin(const uint8_t address = SF_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
{
// Setup Arduino I2C bus
_theI2CBus.init(wirePort, address);

// Begin the sensor and make sure it's connected.
return sfeDevSoilMoisture::begin(&_theI2CBus) == kSTkErrOk ? isConnected() : false;
return sfDevSoilMoisture::begin(&_theI2CBus) == ksfTkErrOk ? isConnected() : false;
}

/**
Expand All @@ -64,16 +65,16 @@ class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
*/
bool isConnected()
{
return _theI2CBus.ping() == kSTkErrOk;
return _theI2CBus.ping() == ksfTkErrOk;
}

private:
sfeTkArdI2C _theI2CBus;
sfTkArdI2C _theI2CBus;
};

//-----------------------------------------------------------------------------------------------
// Define our Arduino Object - SPI version
class SparkFunSoilMoistureSensorSPI : public sfeDevSoilMoisture
class SparkFunSoilMoistureSensorSPI : public sfDevSoilMoisture
{
public:
/**
Expand All @@ -96,9 +97,9 @@ class SparkFunSoilMoistureSensorSPI : public sfeDevSoilMoisture
_theSPIBus.init(spiPort, spiSettings, csPin, true);

// Begin the sensor with the SPI bus connection
return (sfeDevSoilMoisture::begin(&_theSPIBus) == kSTkErrOk);
return (sfDevSoilMoisture::begin(&_theSPIBus) == ksfTkErrOk);
}

private:
sfeTkArdSPI _theSPIBus;
sfTkArdSPI _theSPIBus;
};
69 changes: 34 additions & 35 deletions src/sfeTk/sfeDevSoilMoisture.cpp → src/sfTk/sfDevSoilMoisture.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file sfeDevSoilMoisture.cpp
* @file sfDevSoilMoisture.cpp
* @brief Implementation file for the soil moisture sensor class
*
* This file contains the implementation of the soil moisture sensor class, including
Expand All @@ -9,141 +9,140 @@
* @author SparkFun Electronics
* @date 2025
* @copyright Copyright (c) 2025, SparkFun Electronics Inc. This project is released under the MIT License.
*
*
* SPDX-License-Identifier: MIT
*/


#include "sfeDevSoilMoisture.h"
#include "sfDevSoilMoisture.h"

// Impl for the core driver

// Define the communication commands for the soil moisture sensor (from the original zio firmware)
/**
* @brief Command to turn off the on-board LED
*/
#define kCommandLEDOff 0x00
const uint8_t kCommandLEDOff = 0x00;

/**
* @brief Command to turn on the on-board LED
*/
#define kCommandLEDOn 0x01
const uint8_t kCommandLEDOn = 0x01;

/**
* @brief Command to change the I2C address of the sensor
*/
#define kCommandChangeAddress 0x03
const uint8_t kCommandChangeAddress = 0x03;

/**
* @brief Command to get the moisture value from the sensor
*/
#define kCommandGetValue 0x05
const uint8_t kCommandGetValue = 0x05;

/**
* @brief Command indicating no new data is available
*/
#define kCommandNothingNew 0x99
const uint8_t kCommandNothingNew = 0x99;

//---------------------------------------------------------------------
// Core object implementation
//---------------------------------------------------------------------
// start up the sensor
sfeTkError_t sfeDevSoilMoisture::begin(sfeTkIBus *theBus)
sfTkError_t sfDevSoilMoisture::begin(sfTkIBus *theBus)
{
// Nullptr check
if (theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Set bus pointer
_theBus = theBus;

return kSTkErrOk;
return ksfTkErrOk;
}

//----------------------------------------------------------------------------------------
// LED off command
sfeTkError_t sfeDevSoilMoisture::LEDOff(void)
sfTkError_t sfDevSoilMoisture::LEDOff(void)
{
if (_theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Send the command to turn the LED off
return _theBus->writeByte(kCommandLEDOff);
return _theBus->writeData(kCommandLEDOff);
}
//----------------------------------------------------------------------------------------
// LED on command
sfeTkError_t sfeDevSoilMoisture::LEDOn(void)
sfTkError_t sfDevSoilMoisture::LEDOn(void)
{
if (_theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Send the command to turn the LED on
return _theBus->writeByte(kCommandLEDOn);
return _theBus->writeData(kCommandLEDOn);
}

//----------------------------------------------------------------------------------------
// Read the moisture value from the sensor - returns a resistance reading between 0 and 1023
uint16_t sfeDevSoilMoisture::readMoistureValue(void)
uint16_t sfDevSoilMoisture::readMoistureValue(void)
{
if (_theBus == nullptr)
return 0;

uint16_t value = 0;
if (_theBus->readRegisterWord(kCommandGetValue, value) != kSTkErrOk)
if (_theBus->readRegister(kCommandGetValue, value) != ksfTkErrOk)
return 0;

return value;
}

//----------------------------------------------------------------------------------------
// Returns the moisture ratio from the sensor (0 - 1.0)
float sfeDevSoilMoisture::readMoistureRatio(void)
float sfDevSoilMoisture::readMoistureRatio(void)
{
if (_theBus == nullptr)
return 0.0;

return (((float)SFE_SOIL_MOISTURE_MAX_VALUE - (float)readMoistureValue()) / (float)SFE_SOIL_MOISTURE_MAX_VALUE);
return (((float)SF_SOIL_MOISTURE_MAX_VALUE - (float)readMoistureValue()) / (float)SF_SOIL_MOISTURE_MAX_VALUE);
}

//----------------------------------------------------------------------------------------
// Returns the moisture percentage from the sensor (0 - 100%)
float sfeDevSoilMoisture::readMoisturePercentage(void)
float sfDevSoilMoisture::readMoisturePercentage(void)
{
return readMoistureRatio() * 100.0;
}
//----------------------------------------------------------------------------------------
// Change the I2C address of the sensor
sfeTkError_t sfeDevSoilMoisture::setI2CAddress(uint8_t newAddress)
sfTkError_t sfDevSoilMoisture::setI2CAddress(uint8_t newAddress)
{
if (_theBus == nullptr)
return kSTkErrBusNotInit;
return ksfTkErrBusNotInit;

// Validate the new address
if (newAddress < 0x07 || newAddress > 0x78)
return kSTkErrFail;
return ksfTkErrFail;

// If in I2C mode, is the address the same as the current address?
if (_theBus->type() == kBusTypeI2C && ((sfeTkII2C *)_theBus)->address() == newAddress)
return kSTkErrOk;
if (_theBus->type() == ksfTkBusTypeI2C && ((sfTkII2C *)_theBus)->address() == newAddress)
return ksfTkErrOk;

// Send the command to change the address. NOTE: Because of how the sensor works,
// the following will return an error (since the sensor side resets the bus)
(void)_theBus->writeRegisterByte(kCommandChangeAddress, newAddress);
(void)_theBus->writeRegister(kCommandChangeAddress, newAddress);

return kSTkErrOk;
return ksfTkErrOk;
}
//----------------------------------------------------------------------------------------
// Return the address of the sensor bus. For I2C this is the address of the sensor, for
// SPI this is the CS pin
uint8_t sfeDevSoilMoisture::address(void)
uint8_t sfDevSoilMoisture::address(void)
{
if (_theBus == nullptr)
return 0;

if (_theBus->type() == kBusTypeSPI)
return ((sfeTkISPI *)_theBus)->cs();
else if (_theBus->type() == kBusTypeI2C)
return ((sfeTkII2C *)_theBus)->address();
if (_theBus->type() == ksfTkBusTypeSPI)
return ((sfTkISPI *)_theBus)->cs();
else if (_theBus->type() == ksfTkBusTypeI2C)
return ((sfTkII2C *)_theBus)->address();

return 0;
}
Loading