![]() |
SparkFun Capacitive Soil Moisture Sensor - CY8CMBR3 Arduino Library
Library for the SparkFun Capacitive Soil Moisture Sensor - CY8CMBR3
|
#include <sfDevCY8CMBR3.h>
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... | |
|
inline |
|
protected |
Read the I2C address of the sensor.
This method reads the current I2C address from the sensor.
| i2cAddress | Reference to store the read I2C address (7-bit). |
|
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.
| i2cAddress | The I2C address to set (7-bit). |
| bool sfDevCY8CMBR3::begin | ( | sfTkIBus * | theBus = nullptr | ) |
This method is called to set the communication bus directly and initialize the sensor.
| theBus | Pointer to the bus object. |
| bool sfDevCY8CMBR3::defaultMoistureSensorInit | ( | void | ) |
Initialize the moisture sensor with default settings.
This method initializes the moisture sensor with default settings
| 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.
| sensorId | The sensor Id to enable or disable. |
| enable | True to enable the sensor, false to disable. |
| 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.
| sensorId | The sensor Id to get the base threshold for. |
| 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.
| uint16_t sfDevCY8CMBR3::getDeviceID | ( | void | ) |
Requests the device ID from the sensor.
| uint8_t sfDevCY8CMBR3::getFamilyID | ( | void | ) |
Requests the family ID from the sensor.
| 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.
| None |
| uint8_t sfDevCY8CMBR3::getGPOData | ( | void | ) |
Get the current GPO data.
This method gets the current GPO data by reading from the GPO_DATA register.
| None |
| 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.
| None |
| uint8_t sfDevCY8CMBR3::getHysteresis | ( | void | ) |
Get the hysteresis value.
This method gets the hysteresis value by reading from the BUTTON_HYS register.
| 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.
| 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.
| uint8_t sfDevCY8CMBR3::getNoiseThreshold | ( | void | ) |
Get the noise threshold value.
This method gets the noise threshold value by reading from the BUTTON_NT register.
| 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.
| sensorId | The sensor Id to get the sensitivity for. |
| bool sfDevCY8CMBR3::isCtrlCommandComplete | ( | void | ) |
Checks if the last sent control command is complete.
| 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.
| 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.
| ledOn | True to turn on the LED, false to turn off. |
| 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.
| sensorId | The sensor Id to read the baseline count from. |
| 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.
| sensorId | The sensor Id to read the capacitance from. |
| 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.
| sensorId | The sensor Id to read the difference count from. |
| 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.
| sensorId | The sensor Id to read the difference count from. |
| 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.
| sensorId | The sensor Id to read the raw count from. |
| bool sfDevCY8CMBR3::readWithSyncCounter | ( | uint8_t | reg, |
| uint16_t & | data, | ||
| uint8_t | retries = 10 |
||
| ) |
| 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.
| register | The data register we are reading from |
| data | Reference to store the read data. |
| retries | The number of times to retry checking the sync counters before giving up. |
| 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.
| waitForCompletion | If true, the function will wait until the reset is complete before returning. |
| 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.
| bool sfDevCY8CMBR3::saveDefaultConfig | ( | void | ) |
Load the default configuration and save it to non-volatile memory.
| bool sfDevCY8CMBR3::sendCtrlCommand | ( | sfe_cy8cmbr3_ctrl_cmd_t | command, |
| bool | waitForCompletion = true |
||
| ) |
Sends a control command to the sensor.
| command | The control command to send. |
| waitForCompletion | If true, the function will wait until the command is complete before returning. |
| 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.
| enable | True to enable auto-reset, false to disable. |
| 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.
| enable | True to enable auto-threshold, false to disable. |
| 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.
| threshold | The base threshold value to set (0-255). |
| sensorId | The sensor Id to set the base threshold for. |
| void sfDevCY8CMBR3::setCommunicationBus | ( | sfTkIBus * | theBus | ) |
Sets the communication bus to the specified bus.
| theBus | Bus to set as the communication device. |
| 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.
| controlByHost | True to control GPO by host, false to control by sensor. |
| pwmOutput | True to set GPO as PWM output, false for DC output |
| strongDrive | True for strong drive mode, false for high-Z mode. |
| activeHigh | True for active high, false for active low. (note we use active low since our LED is tied to GPO0 on it's low side) |
| bool sfDevCY8CMBR3::setGPOToggleEnable | ( | bool | enable = false, |
| sfe_cy8cmbr3_gpo_t | gpo = GPO_0 |
||
| ) |
Enable or disable GPO toggle.
| enable | True to enable GPO toggle, false to disable. |
| gpo | The GPO to set the toggle enable for. |
| bool sfDevCY8CMBR3::setHysteresis | ( | uint8_t | hysteresis = 0 | ) |
Set the hysteresis value.
This method sets the hysteresis value by writing to the BUTTON_HYS register.
| hysteresis | The hysteresis value to set (0-31). |
| bool sfDevCY8CMBR3::setHysteresisOverride | ( | bool | override = false | ) |
Set the hysteresis override. This allows manual control of the hysteresis value.
| override | True to enable hysteresis override, false to disable. |
| 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.
| baseline | The low baseline reset value to set (0-127). |
| bool sfDevCY8CMBR3::setLowBaselineResetOverride | ( | bool | override = false | ) |
Set the low baseline reset override. This allows manual control of the low baseline reset.
| override | True to enable low baseline reset override, false to disable. |
| 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.
| threshold | The negative noise threshold value to set (0-127). |
| bool sfDevCY8CMBR3::setNegativeNoiseThresholdOverride | ( | bool | override = false | ) |
Set the negative noise threshold override. This allows manual control of the negative noise threshold.
| override | True to enable negative noise threshold override, false to disable. |
| 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.
| threshold | The noise threshold value to set (0-127). |
| bool sfDevCY8CMBR3::setNoiseThresholdOverride | ( | bool | override = false | ) |
Set the noise threshold override. This allows manual control of the noise threshold.
| override | True to enable noise threshold override, false to disable. |
| bool sfDevCY8CMBR3::setProxEnable | ( | bool | enable = false, |
| sfe_cy8cmbr3_sensor_id_t | sensorId = SID_0 |
||
| ) |
Enable or disable proximity sensing for the specified sensor Id.
| enable | True to enable proximity sensing, false to disable. |
| sensorId | The sensor Id to enable or disable proximity sensing for (Only SID_0 and SID_1 are valid). |
| 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.
| interval | The refresh interval to set (default is 100ms). |
| 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.
| sensorId | The sensor Id to set the sensitivity for. |
| sensitivity | The sensitivity value to set (0-3). |
| bool sfDevCY8CMBR3::setSensorId | ( | sfe_cy8cmbr3_sensor_id_t | sensorId = SID_0 | ) |
Set the sensor Id.
| sensorId | The sensor Id to set. |
This will set the sensor Id (and by extension the debug sensor Id) for debug operations.
| 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.
| config | The configuration for SPO0 (default is GPO). |
| 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.
| enable | True to enable system diagnostics, false to disable. |