SparkFun Capacitive Soil Moisture Sensor - CY8CMBR3 Arduino Library
Library for the SparkFun Capacitive Soil Moisture Sensor - CY8CMBR3
Loading...
Searching...
No Matches
sfDevCY8CMBR3 Class Reference

#include <sfDevCY8CMBR3.h>

Inheritance diagram for sfDevCY8CMBR3:

Public Member Functions

 sfDevCY8CMBR3 ()
 
bool begin (sfTkIBus *theBus=nullptr)
 This method is called to set the communication bus directly and initialize the sensor. More...
 
uint8_t getFamilyID (void)
 Requests the family ID from the sensor. More...
 
uint16_t getDeviceID (void)
 Requests the device ID from the sensor. More...
 
void setCommunicationBus (sfTkIBus *theBus)
 Sets the communication bus to the specified bus. More...
 
bool isCtrlCommandComplete (void)
 Checks if the last sent control command is complete. More...
 
bool sendCtrlCommand (sfe_cy8cmbr3_ctrl_cmd_t command, bool waitForCompletion=true)
 Sends a control command to the sensor. More...
 
bool saveConfig (void)
 Save the current configuration to non-volatile memory. More...
 
bool reset (bool waitForCompletion=true)
 Perform a software reset of the sensor. More...
 
bool readWithSyncCounter (uint8_t reg, uint8_t &data, uint8_t retries=10)
 Reads target register while waiting for the sync counter on either end of the target register to be equal indicating data is valid. More...
 
bool readWithSyncCounter (uint8_t reg, uint16_t &data, uint8_t retries=10)
 
bool setSensorId (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Set the sensor Id. More...
 
sfe_cy8cmbr3_sensor_id_t getDebugSensorId (void)
 Get the current debug sensor Id. More...
 
bool setSensitivity (sfe_cy8cmbr3_sensitivity_t sensitivity=CS_SENSITIVITY_500_COUNTS_PER_PF, sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Set sensitivity for the specified sensor Id. More...
 
sfe_cy8cmbr3_sensitivity_t getSensitivity (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Get sensitivity for the specified sensor Id. More...
 
bool setAutoThresholdEnable (bool enable=true)
 Enable or disable the auto-threshold feature. More...
 
bool setAutoResetEnable (bool enable=true, sfe_cy8cmbr3_auto_reset_timeout_t timeout=AUTO_RESET_TIMEOUT_5_SECONDS)
 Enable or disable the auto-reset feature. More...
 
bool setSystemDiagnosticsEnable (bool enable=true)
 Enable or disable system diagnostics. More...
 
bool setRefreshInterval (sfe_cy8cmbr3_refresh_interval_t interval=REFRESH_INTERVAL_100MS)
 Set the refresh interval for the sensor. More...
 
bool setSPO0Config (sfe_cy8cmbr3_spo_config_t config=SPO_GPO)
 Set the SPO0 configuration. More...
 
bool setProxEnable (bool enable=false, sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Enable or disable proximity sensing for the specified sensor Id. More...
 
bool setBaseThreshold (uint8_t threshold=128, sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Set the base threshold for the specified sensor Id. More...
 
uint8_t getBaseThreshold (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Get the base threshold for the specified sensor Id. More...
 
bool setHysteresisOverride (bool override=false)
 Set the hysteresis override. This allows manual control of the hysteresis value. More...
 
bool setHysteresis (uint8_t hysteresis=0)
 Set the hysteresis value. More...
 
uint8_t getHysteresis (void)
 Get the hysteresis value. More...
 
bool setLowBaselineResetOverride (bool override=false)
 Set the low baseline reset override. This allows manual control of the low baseline reset. More...
 
bool setLowBaselineReset (uint8_t baseline=0)
 Set the low baseline reset value. More...
 
uint8_t getLowBaselineReset (void)
 Get the low baseline reset value. More...
 
bool setNegativeNoiseThresholdOverride (bool override=false)
 Set the negative noise threshold override. This allows manual control of the negative noise threshold. More...
 
bool setNegativeNoiseThreshold (uint8_t threshold=0)
 Set the negative noise threshold value. More...
 
uint8_t getNegativeNoiseThreshold (void)
 Get the negative noise threshold value. More...
 
bool setNoiseThresholdOverride (bool override=false)
 Set the noise threshold override. This allows manual control of the noise threshold. More...
 
bool setNoiseThreshold (uint8_t threshold=0)
 Set the noise threshold value. More...
 
uint8_t getNoiseThreshold (void)
 Get the noise threshold value. More...
 
bool saveDefaultConfig (void)
 Load the default configuration and save it to non-volatile memory. More...
 
bool setGPOConfig (bool controlByHost=true, bool pwmOutput=false, bool strongDrive=true, bool activeHigh=false)
 Set the GPO configuration. More...
 
sfe_cy8cmbr3_reg_gpo_cfg_t getGPOConfig (void)
 Get the GPO configuration. More...
 
bool setGPOToggleEnable (bool enable=false, sfe_cy8cmbr3_gpo_t gpo=GPO_0)
 Enable or disable GPO toggle. More...
 
uint8_t getGPOOutputState (void)
 Get the current GPO output state. More...
 
uint8_t getGPOData (void)
 Get the current GPO data. More...
 
bool enable (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0, bool enable=true)
 Enable or disable sensor by sensor Id. More...
 
uint8_t readCapacitancePF (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Reads the capacitance value in pF from the sensor. More...
 
uint16_t readDebugDifferenceCount (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Reads the difference count value from the sensor. More...
 
uint16_t readDifferenceCount (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Reads the difference count value from the sensor. More...
 
uint16_t readBaselineCount (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Reads the baseline count value from the sensor. More...
 
uint16_t readRawCount (sfe_cy8cmbr3_sensor_id_t sensorId=SID_0)
 Reads the raw count value from the sensor. More...
 
bool ledOn (bool ledOn=true, sfe_cy8cmbr3_gpo_t gpo=GPO_0)
 Turn on or off the LED. More...
 
bool ledOff (sfe_cy8cmbr3_gpo_t gpo=GPO_0)
 Turn off the LED. More...
 
bool defaultMoistureSensorInit (void)
 Initialize the moisture sensor with default settings. More...
 

Protected Member Functions

bool _setI2CAddress (uint8_t i2cAddress)
 Set the I2C address of the sensor. More...
 
bool _readI2CAddress (uint8_t &i2cAddress)
 Read the I2C address of the sensor. More...
 

Constructor & Destructor Documentation

◆ sfDevCY8CMBR3()

sfDevCY8CMBR3::sfDevCY8CMBR3 ( )
inline

Member Function Documentation

◆ _readI2CAddress()

bool sfDevCY8CMBR3::_readI2CAddress ( uint8_t &  i2cAddress)
protected

Read the I2C address of the sensor.

This method reads the current I2C address from the sensor.

Parameters
i2cAddressReference to store the read I2C address (7-bit).
Returns
True if successful, false if it fails.

◆ _setI2CAddress()

bool sfDevCY8CMBR3::_setI2CAddress ( uint8_t  i2cAddress)
protected

Set the I2C address of the sensor.

This method is responsible for sending the command to change the I2C slave address of the sensor. It won't change the address of the communication bus, that is the caller's responsibility.

Parameters
i2cAddressThe I2C address to set (7-bit).
Returns
True if successful, false if it fails.

◆ begin()

bool sfDevCY8CMBR3::begin ( sfTkIBus *  theBus = nullptr)

This method is called to set the communication bus directly and initialize the sensor.

Parameters
theBusPointer to the bus object.
Returns
True if successful, false if it fails.

◆ defaultMoistureSensorInit()

bool sfDevCY8CMBR3::defaultMoistureSensorInit ( void  )

Initialize the moisture sensor with default settings.

This method initializes the moisture sensor with default settings

Returns
True if successful, false if it fails.

◆ enable()

bool sfDevCY8CMBR3::enable ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0,
bool  enable = true 
)

Enable or disable sensor by sensor Id.

This method enables the specified sensor by setting the appropriate bits in the SENSOR_EN register.

Parameters
sensorIdThe sensor Id to enable or disable.
enableTrue to enable the sensor, false to disable.
Returns
True if successful, false if it fails.

◆ getBaseThreshold()

uint8_t sfDevCY8CMBR3::getBaseThreshold ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Get the base threshold for the specified sensor Id.

This method gets the base threshold for the specified sensor by reading from the BASE_THRESHOLDx register.

Parameters
sensorIdThe sensor Id to get the base threshold for.
Returns
The base threshold value for the specified sensor (0-255).

◆ getDebugSensorId()

sfe_cy8cmbr3_sensor_id_t sfDevCY8CMBR3::getDebugSensorId ( void  )

Get the current debug sensor Id.

This method gets the current debug sensor Id by reading from the DEBUG_SENSOR_ID register.

Returns
The current debug sensor Id.

◆ getDeviceID()

uint16_t sfDevCY8CMBR3::getDeviceID ( void  )

Requests the device ID from the sensor.

Returns
The device ID of the sensor or 0 on error.

◆ getFamilyID()

uint8_t sfDevCY8CMBR3::getFamilyID ( void  )

Requests the family ID from the sensor.

Returns
The family ID of the sensor.

◆ getGPOConfig()

sfe_cy8cmbr3_reg_gpo_cfg_t sfDevCY8CMBR3::getGPOConfig ( void  )

Get the GPO configuration.

This method gets the GPO configuration by reading from the GPO_CFG register.

Parameters
None
Returns
The GPO configuration.

◆ getGPOData()

uint8_t sfDevCY8CMBR3::getGPOData ( void  )

Get the current GPO data.

This method gets the current GPO data by reading from the GPO_DATA register.

Parameters
None
Returns
The current GPO data.

◆ getGPOOutputState()

uint8_t sfDevCY8CMBR3::getGPOOutputState ( void  )

Get the current GPO output state.

This method gets the current GPO output state by reading from the GPO_OUTPUT_STATE register.

Parameters
None
Returns
The current GPO output state.

◆ getHysteresis()

uint8_t sfDevCY8CMBR3::getHysteresis ( void  )

Get the hysteresis value.

This method gets the hysteresis value by reading from the BUTTON_HYS register.

Returns
The current hysteresis value (0-31)

◆ getLowBaselineReset()

uint8_t sfDevCY8CMBR3::getLowBaselineReset ( void  )

Get the low baseline reset value.

This method gets the low baseline reset value by reading from the BUTTON_LBR register.

Returns
The current low baseline reset value (0-127).

◆ getNegativeNoiseThreshold()

uint8_t sfDevCY8CMBR3::getNegativeNoiseThreshold ( void  )

Get the negative noise threshold value.

This method gets the negative noise threshold value by reading from the BUTTON_NNT register.

Returns
The current negative noise threshold value (0-127).

◆ getNoiseThreshold()

uint8_t sfDevCY8CMBR3::getNoiseThreshold ( void  )

Get the noise threshold value.

This method gets the noise threshold value by reading from the BUTTON_NT register.

Returns
The current noise threshold value (0-127).

◆ getSensitivity()

sfe_cy8cmbr3_sensitivity_t sfDevCY8CMBR3::getSensitivity ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Get sensitivity for the specified sensor Id.

This method gets the sensitivity for the specified sensor by reading from the SENSITIVITY0 register.

Parameters
sensorIdThe sensor Id to get the sensitivity for.

◆ isCtrlCommandComplete()

bool sfDevCY8CMBR3::isCtrlCommandComplete ( void  )

Checks if the last sent control command is complete.

Returns
True if the command is complete, false if it is still in progress.

◆ ledOff()

bool sfDevCY8CMBR3::ledOff ( sfe_cy8cmbr3_gpo_t  gpo = GPO_0)

Turn off the LED.

This method turns off the LED by calling the ledOn method with false.

Returns
True if successful, false if it fails.

◆ ledOn()

bool sfDevCY8CMBR3::ledOn ( bool  ledOn = true,
sfe_cy8cmbr3_gpo_t  gpo = GPO_0 
)

Turn on or off the LED.

This method turns on or off the LED by setting or clearing the GPO output state.

Parameters
ledOnTrue to turn on the LED, false to turn off.
Returns
True if successful, false if it fails.

◆ readBaselineCount()

uint16_t sfDevCY8CMBR3::readBaselineCount ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Reads the baseline count value from the sensor.

This method reads the baseline count from the DEBUG_BASELINE_COUNT resister.

Parameters
sensorIdThe sensor Id to read the baseline count from.
Returns
The baseline count value (or 0 on error).

◆ readCapacitancePF()

uint8_t sfDevCY8CMBR3::readCapacitancePF ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Reads the capacitance value in pF from the sensor.

This method reads the capacitance in pF from the DEBUG_CP register.

Parameters
sensorIdThe sensor Id to read the capacitance from.
Returns
The capacitance value in pF (or 0 on error).

◆ readDebugDifferenceCount()

uint16_t sfDevCY8CMBR3::readDebugDifferenceCount ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Reads the difference count value from the sensor.

This method reads the difference count from the DEBUG_DIFFERENCE_COUNTx register.

Parameters
sensorIdThe sensor Id to read the difference count from.
Returns
The difference count value (or 0 on error).

◆ readDifferenceCount()

uint16_t sfDevCY8CMBR3::readDifferenceCount ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Reads the difference count value from the sensor.

This method reads the difference count from the DIFFERENCE_COUNTx register.

Parameters
sensorIdThe sensor Id to read the difference count from.
Returns
The difference count value (or 0 on error).

◆ readRawCount()

uint16_t sfDevCY8CMBR3::readRawCount ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Reads the raw count value from the sensor.

This method reads the raw count from the DEBUG_RAW_COUNT0 register.

Parameters
sensorIdThe sensor Id to read the raw count from.
Returns
The raw count value (or 0 on error).

◆ readWithSyncCounter() [1/2]

bool sfDevCY8CMBR3::readWithSyncCounter ( uint8_t  reg,
uint16_t &  data,
uint8_t  retries = 10 
)

◆ readWithSyncCounter() [2/2]

bool sfDevCY8CMBR3::readWithSyncCounter ( uint8_t  reg,
uint8_t &  data,
uint8_t  retries = 10 
)

Reads target register while waiting for the sync counter on either end of the target register to be equal indicating data is valid.

Parameters
registerThe data register we are reading from
dataReference to store the read data.
retriesThe number of times to retry checking the sync counters before giving up.
Returns
True if successful, false if it fails.

◆ reset()

bool sfDevCY8CMBR3::reset ( bool  waitForCompletion = true)

Perform a software reset of the sensor.

This method performs a software reset of the sensor by sending the SW_RESET command.

Parameters
waitForCompletionIf true, the function will wait until the reset is complete before returning.
Returns
True if successful, false if it fails.

◆ saveConfig()

bool sfDevCY8CMBR3::saveConfig ( void  )

Save the current configuration to non-volatile memory.

This method saves the current configuration to non-volatile memory by sending the SAVE_CONFIG command. the device will require a reset or power cycle to load the saved configuration and leave CONFIG state.

Returns
True if successful, false if it fails.

◆ saveDefaultConfig()

bool sfDevCY8CMBR3::saveDefaultConfig ( void  )

Load the default configuration and save it to non-volatile memory.

Returns
True if successful, false if it fails.

◆ sendCtrlCommand()

bool sfDevCY8CMBR3::sendCtrlCommand ( sfe_cy8cmbr3_ctrl_cmd_t  command,
bool  waitForCompletion = true 
)

Sends a control command to the sensor.

Parameters
commandThe control command to send.
waitForCompletionIf true, the function will wait until the command is complete before returning.
Returns
True if successful, false if it fails.

◆ setAutoResetEnable()

bool sfDevCY8CMBR3::setAutoResetEnable ( bool  enable = true,
sfe_cy8cmbr3_auto_reset_timeout_t  timeout = AUTO_RESET_TIMEOUT_5_SECONDS 
)

Enable or disable the auto-reset feature.

This method enables or disables the auto-reset feature by setting the BUTTON_SLD_ARST bits in the DEVICE_CFG2 register.

Parameters
enableTrue to enable auto-reset, false to disable.
Returns
True if successful, false if it fails.

◆ setAutoThresholdEnable()

bool sfDevCY8CMBR3::setAutoThresholdEnable ( bool  enable = true)

Enable or disable the auto-threshold feature.

This method enables or disables the auto-threshold feature by setting the ATH_EN bit in the DEVICE_CFG2 register.

Parameters
enableTrue to enable auto-threshold, false to disable.
Returns
True if successful, false if it fails.

◆ setBaseThreshold()

bool sfDevCY8CMBR3::setBaseThreshold ( uint8_t  threshold = 128,
sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0 
)

Set the base threshold for the specified sensor Id.

This method sets the base threshold for the specified sensor by writing to the BASE_THRESHOLDx register.

Parameters
thresholdThe base threshold value to set (0-255).
sensorIdThe sensor Id to set the base threshold for.
Returns
True if successful, false if it fails.

◆ setCommunicationBus()

void sfDevCY8CMBR3::setCommunicationBus ( sfTkIBus *  theBus)

Sets the communication bus to the specified bus.

Parameters
theBusBus to set as the communication device.

◆ setGPOConfig()

bool sfDevCY8CMBR3::setGPOConfig ( bool  controlByHost = true,
bool  pwmOutput = false,
bool  strongDrive = true,
bool  activeHigh = false 
)

Set the GPO configuration.

This method sets the GPO configuration by writing to the GPO_CFG register.

Parameters
controlByHostTrue to control GPO by host, false to control by sensor.
pwmOutputTrue to set GPO as PWM output, false for DC output
strongDriveTrue for strong drive mode, false for high-Z mode.
activeHighTrue for active high, false for active low. (note we use active low since our LED is tied to GPO0 on it's low side)

◆ setGPOToggleEnable()

bool sfDevCY8CMBR3::setGPOToggleEnable ( bool  enable = false,
sfe_cy8cmbr3_gpo_t  gpo = GPO_0 
)

Enable or disable GPO toggle.

Parameters
enableTrue to enable GPO toggle, false to disable.
gpoThe GPO to set the toggle enable for.
Returns
True if successful, false if it fails.

◆ setHysteresis()

bool sfDevCY8CMBR3::setHysteresis ( uint8_t  hysteresis = 0)

Set the hysteresis value.

This method sets the hysteresis value by writing to the BUTTON_HYS register.

Parameters
hysteresisThe hysteresis value to set (0-31).
Returns
True if successful, false if it fails.

◆ setHysteresisOverride()

bool sfDevCY8CMBR3::setHysteresisOverride ( bool  override = false)

Set the hysteresis override. This allows manual control of the hysteresis value.

Parameters
overrideTrue to enable hysteresis override, false to disable.
Returns
True if successful, false if it fails.

◆ setLowBaselineReset()

bool sfDevCY8CMBR3::setLowBaselineReset ( uint8_t  baseline = 0)

Set the low baseline reset value.

This method sets the low baseline reset value by writing to the BUTTON_LBR register.

Parameters
baselineThe low baseline reset value to set (0-127).
Returns
True if successful, false if it fails.

◆ setLowBaselineResetOverride()

bool sfDevCY8CMBR3::setLowBaselineResetOverride ( bool  override = false)

Set the low baseline reset override. This allows manual control of the low baseline reset.

Parameters
overrideTrue to enable low baseline reset override, false to disable.
Returns
True if successful, false if it fails.

◆ setNegativeNoiseThreshold()

bool sfDevCY8CMBR3::setNegativeNoiseThreshold ( uint8_t  threshold = 0)

Set the negative noise threshold value.

This method sets the negative noise threshold value by writing to the BUTTON_NNT register.

Parameters
thresholdThe negative noise threshold value to set (0-127).
Returns
True if successful, false if it fails.

◆ setNegativeNoiseThresholdOverride()

bool sfDevCY8CMBR3::setNegativeNoiseThresholdOverride ( bool  override = false)

Set the negative noise threshold override. This allows manual control of the negative noise threshold.

Parameters
overrideTrue to enable negative noise threshold override, false to disable.
Returns
True if successful, false if it fails.

◆ setNoiseThreshold()

bool sfDevCY8CMBR3::setNoiseThreshold ( uint8_t  threshold = 0)

Set the noise threshold value.

This method sets the noise threshold value by writing to the BUTTON_NT register.

Parameters
thresholdThe noise threshold value to set (0-127).
Returns
True if successful, false if it fails.

◆ setNoiseThresholdOverride()

bool sfDevCY8CMBR3::setNoiseThresholdOverride ( bool  override = false)

Set the noise threshold override. This allows manual control of the noise threshold.

Parameters
overrideTrue to enable noise threshold override, false to disable.
Returns
True if successful, false if it fails.

◆ setProxEnable()

bool sfDevCY8CMBR3::setProxEnable ( bool  enable = false,
sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0 
)

Enable or disable proximity sensing for the specified sensor Id.

Parameters
enableTrue to enable proximity sensing, false to disable.
sensorIdThe sensor Id to enable or disable proximity sensing for (Only SID_0 and SID_1 are valid).
Returns
True if successful, false if it fails.

◆ setRefreshInterval()

bool sfDevCY8CMBR3::setRefreshInterval ( sfe_cy8cmbr3_refresh_interval_t  interval = REFRESH_INTERVAL_100MS)

Set the refresh interval for the sensor.

This method sets the refresh interval by writing to the REFRESH_CTRL register.

Parameters
intervalThe refresh interval to set (default is 100ms).
Returns
True if successful, false if it fails.

◆ setSensitivity()

bool sfDevCY8CMBR3::setSensitivity ( sfe_cy8cmbr3_sensitivity_t  sensitivity = CS_SENSITIVITY_500_COUNTS_PER_PF,
sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0 
)

Set sensitivity for the specified sensor Id.

This method sets the sensitivity for the specified sensor by writing to the SENSITIVITY0 register.

Parameters
sensorIdThe sensor Id to set the sensitivity for.
sensitivityThe sensitivity value to set (0-3).
Returns
True if successful, false if it fails.

◆ setSensorId()

bool sfDevCY8CMBR3::setSensorId ( sfe_cy8cmbr3_sensor_id_t  sensorId = SID_0)

Set the sensor Id.

Parameters
sensorIdThe sensor Id to set.

This will set the sensor Id (and by extension the debug sensor Id) for debug operations.

Returns
True if successful, false if it fails.

◆ setSPO0Config()

bool sfDevCY8CMBR3::setSPO0Config ( sfe_cy8cmbr3_spo_config_t  config = SPO_GPO)

Set the SPO0 configuration.

This method sets the SPO0 configuration by writing to the SPO_CFG register.

Parameters
configThe configuration for SPO0 (default is GPO).

◆ setSystemDiagnosticsEnable()

bool sfDevCY8CMBR3::setSystemDiagnosticsEnable ( bool  enable = true)

Enable or disable system diagnostics.

This method enables or disables system diagnostics by setting the SYSD_EN bit in the DEVICE_CFG1 register.

Parameters
enableTrue to enable system diagnostics, false to disable.
Returns
True if successful, false if it fails.

The documentation for this class was generated from the following files: