ModularSensors > Classes > Sensor > RainCounterI2C
ModularSensors > Modules > Trinket Tipping Bucket > RainCounterI2C


RainCounterI2C class

The Sensor sub-class for the Arduino-based external tipping bucket counter.

Base classes

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

Constructors, destructors, conversion operators

RainCounterI2C(SoftwareWire* theI2C, uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2)
Construct a new Rain Counter I2C object using a software I2C instance.
RainCounterI2C(int8_t dataPin, int8_t clockPin, uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2)
Construct a new Rain Counter I2C object, also creating a SoftwareWire I2C instance for communication with that object.
RainCounterI2C(TwoWire* theI2C, uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2) explicit
Construct a new Rain Counter I2C object using a secondary hardware I2C instance.
RainCounterI2C(uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2) explicit
Construct a new Rain Counter I2C object using the primary hardware I2C instance.
~RainCounterI2C()
Destroy the Rain Counter I2C object. Also destroy the software I2C instance if one was created.

Public functions

bool setup(void ) override
Do any one-time preparations needed before the sensor will be able to take readings.
String getSensorLocation(void ) override
Get the pin or connection location between the mcu and the sensor.
bool addSingleMeasurementResult(void ) override
Get the results from a single measurement.

Function documentation

RainCounterI2C(SoftwareWire* theI2C, uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2)

Construct a new Rain Counter I2C object using a software I2C instance.

Parameters
theI2C A SoftwareWire instance for I2C communication.
i2cAddressHex The I2C address of the Trinket; can be any number between 0x40 and 0x4F. The default value is 0x08.
rainPerTip The depth of rain from a single tip; most likely either 0.01" or 0.2mm, depending on your tipping bucket calibration. The default value is 0.2.

RainCounterI2C(int8_t dataPin, int8_t clockPin, uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2)

Construct a new Rain Counter I2C object, also creating a SoftwareWire I2C instance for communication with that object.

Parameters
dataPin The pin on the mcu that will be used for I2C data (SDA). Must be a valid pin number.
clockPin The pin on the mcu that will be used for the I2C clock (SCL). Must be a valid pin number.
i2cAddressHex The I2C address of the Trinket; can be any number between 0x40 and 0x4F. The default value is 0x08.
rainPerTip The depth of rain from a single tip; most likely either 0.01" or 0.2mm, depending on your tipping bucket calibration. The default value is 0.2.

RainCounterI2C(TwoWire* theI2C, uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2) explicit

Construct a new Rain Counter I2C object using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
i2cAddressHex The I2C address of the Trinket; can be any number between 0x40 and 0x4F. The default value is 0x08.
rainPerTip The depth of rain from a single tip; most likely either 0.01" or 0.2mm, depending on your tipping bucket calibration. The default value is 0.2.

RainCounterI2C(uint8_t i2cAddressHex = 0x08, float rainPerTip = 0.2) explicit

Construct a new Rain Counter I2C object using the primary hardware I2C instance.

Parameters
i2cAddressHex The I2C address of the Trinket; can be any number between 0x40 and 0x4F. The default value is 0x08.
rainPerTip The depth of rain from a single tip; most likely either 0.01" or 0.2mm, depending on your tipping bucket calibration. The default value is 0.2.

boolsetup(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 begins the Wire library (sets pin levels and modes for I2C) and updates the _sensorStatus. No sensor power is required.


StringgetSensorLocation(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.

booladdSingleMeasurementResult(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.