ANBpH class

The Sensor sub-class for the ANB pH sensors.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

ANBpH(byte modbusAddress, Stream* stream, int8_t powerPin, int8_t powerPin2, int8_t enablePin = -1, uint8_t measurementsToAverage = 1)
Construct a new ANB pH object.
ANBpH(byte modbusAddress, Stream& stream, int8_t powerPin, int8_t powerPin2, int8_t enablePin = -1, uint8_t measurementsToAverage = 1)
Construct a new ANB pH object.
~ANBpH() virtual
Destroy the ANB pH object - no action taken.

Public functions

String getSensorLocation(void) -> String override
Get the pin or connection location between the mcu and the sensor.
bool setup(void) -> bool override
Do any one-time preparations needed before the sensor will be able to take readings.
bool wake(void) -> bool override
Wake the sensor up, if necessary. Do whatever it takes to get a sensor in the proper state to begin a measurement.
bool sleep(void) -> bool override
Puts the sensor to sleep, if necessary.
bool startSingleMeasurement(void) -> bool override
Tell the sensor to start a single measurement, if needed.
bool addSingleMeasurementResult(void) -> bool override
Get the results from a single measurement.
void powerUp(void) override
Turn on the sensor power, if applicable.
void powerDown(void) override
Turn off the sensor power, if applicable.
bool isWarmedUp(bool debug = false) -> bool override
Check whether or not enough time has passed between the sensor receiving power and being ready to respond to logger commands.
bool isStable(bool debug = false) -> bool override
Check whether or not enough time has passed between the sensor responding to any modbus command to giving a valid status code - which indicates that it's ready to take a measurement.
bool isMeasurementComplete(bool debug = false) -> bool override
Check whether or not the pH sensor has completed a measurement.
bool setSalinityMode(ANBSalinityMode newSalinityMode) -> bool
Set the sensor salinity mode.
bool enableImmersionSensor(bool enable = true) -> bool
Enable or disable the immersion sensor.

Function documentation

ANBpH::ANBpH(byte modbusAddress, Stream* stream, int8_t powerPin, int8_t powerPin2, int8_t enablePin = -1, uint8_t measurementsToAverage = 1)

Construct a new ANB pH object.

Parameters
modbusAddress The modbus address of the sensor.
stream An Arduino data stream for modbus communication. See notes for more information on what streams can be used.
powerPin The pin on the mcu controlling power to the ANB pH sensor. Use -1 if it is continuously powered.
powerPin2 The pin on the mcu controlling power to the RS485 adapter, if it is different from that used to power the sensor. Use -1 or omit if not applicable.
enablePin The pin on the mcu controlling the direction enable on the RS485 adapter, if necessary; use -1 or omit if not applicable.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

ANBpH::ANBpH(byte modbusAddress, Stream& stream, int8_t powerPin, int8_t powerPin2, int8_t enablePin = -1, uint8_t measurementsToAverage = 1)

Construct a new ANB pH object.

Parameters
modbusAddress The modbus address of the sensor.
stream An Arduino data stream for modbus communication. See notes for more information on what streams can be used.
powerPin The pin on the mcu controlling power to the ANB pH sensor. Use -1 if it is continuously powered.
powerPin2 The pin on the mcu controlling power to the RS485 adapter, if it is different from that used to power the sensor. Use -1 or omit if not applicable.
enablePin The pin on the mcu controlling the direction enable on the RS485 adapter, if necessary; use -1 or omit if not applicable.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

String ANBpH::getSensorLocation(void) override

Get the pin or connection location between the mcu and the sensor.

Returns String Text describing how the sensor is attached to the mcu.

bool ANBpH::setup(void) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets pin modes on the _powerPin, adapter power, and adapter enable pins. It also sets the expected stream timeout for modbus and updates the _sensorStatus. No sensor power is required. This will always return true.


bool ANBpH::wake(void) override

Wake the sensor up, if necessary. Do whatever it takes to get a sensor in the proper state to begin a measurement.

Returns bool True if the wake function completed successfully.

Verifies that the power is on and updates the _sensorStatus. This also sets the _millisSensorActivated timestamp.


bool ANBpH::sleep(void) override

Puts the sensor to sleep, if necessary.

Returns bool True if the sleep function completed successfully.

Does not take any action if not necessary.


bool ANBpH::startSingleMeasurement(void) override

Tell the sensor to start a single measurement, if needed.

Returns bool True if the start measurement function completed successfully.

This also sets the _millisMeasurementRequested timestamp and updates the _sensorStatus.


bool ANBpH::addSingleMeasurementResult(void) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.


void ANBpH::powerUp(void) override

Turn on the sensor power, if applicable.

Generally this is done by setting the _powerPin HIGH. Also sets the _millisPowerOn timestamp and updates the _sensorStatus.


void ANBpH::powerDown(void) override

Turn off the sensor power, if applicable.

Generally this is done by setting the _powerPin LOW. Also un-sets the _millisPowerOn timestamp (sets _millisPowerOn to 0) and updates the _sensorStatus.


bool ANBpH::isWarmedUp(bool debug = false) override

Check whether or not enough time has passed between the sensor receiving power and being ready to respond to logger commands.

Parameters
debug True to output the result to the debugging Serial
Returns bool True indicates that enough time has passed that the sensor should be ready to respond to commands.

For the ANB pH sensor, this waits for both the power-on warm up and for a valid response from the sensor to a Modbus command.


bool ANBpH::isStable(bool debug = false) override

Check whether or not enough time has passed between the sensor responding to any modbus command to giving a valid status code - which indicates that it's ready to take a measurement.

Parameters
debug True to output the result to the debugging Serial
Returns bool True indicates that enough time has passed that the sensor is ready to take a measurement.

bool ANBpH::isMeasurementComplete(bool debug = false) override

Check whether or not the pH sensor has completed a measurement.

Parameters
debug True to output the result to the debugging Serial
Returns bool True indicates that the pH sensor has completed a measurement.

bool ANBpH::setSalinityMode(ANBSalinityMode newSalinityMode)

Set the sensor salinity mode.

Parameters
newSalinityMode The new salinity mode to use
Returns bool True if the salinity mode was successfully set, false if not.

Change this value to any of the following valid values: ANBSalinityMode::LOW_SALINITY, ANBSalinityMode::HIGH_SALINITY


bool ANBpH::enableImmersionSensor(bool enable = true)

Enable or disable the immersion sensor.

Parameters
enable True to enable the immersion sensor, false to disable
Returns bool True if the immersion sensor status was successfully set, false if not.