Trinket Tipping Bucket topic

Classes for the Trinket-based I2C tipping bucket rain counter

Introduction

This module is for use with a simple external I2C tipping bucket counter based on an Adafriut Trinket. This is NOT for direct counting of tips using an interrupt on the main processor. The construction and programming of the tipping bucket counter is documented on GitHub. It is assumed that the processor of the tip counter takes care of its own power management.

Sensor Datasheet

Build flags

  • -D MS_RAIN_SOFTWAREWIRE
    • switches from using hardware I2C to software I2C

Sensor Constructors

RainCounterI2C::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.

RainCounterI2C::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::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::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.


Example Code

The Arduino-based I2C tipping bucket rain counter is used in the menu a la carte example.

1#include <sensors/RainCounterI2C.h>
2
3const uint8_t RainCounterI2CAddress = 0x08;
4// I2C Address for EnviroDIY external tip counter; 0x08 by default
5const float depthPerTipEvent = 0.2; // rain depth in mm per tip event
6
7// Create a Rain Counter sensor object
8#ifdef MS_RAIN_SOFTWAREWIRE
9RainCounterI2C tbi2c(&softI2C, RainCounterI2CAddress, depthPerTipEvent);
10// RainCounterI2C tbi2c(softwareSDA, softwareSCL, RainCounterI2CAddress,
11// depthPerTipEvent);
12#else
13RainCounterI2C tbi2c(RainCounterI2CAddress, depthPerTipEvent);
14#endif
15
16// Create number of tips and rain depth variable pointers for the tipping bucket
17Variable* tbi2cTips =
18 new RainCounterI2C_Tips(&tbi2c, "12345678-abcd-1234-ef00-1234567890ab");
19Variable* tbi2cDepth =
20 new RainCounterI2C_Depth(&tbi2c, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class RainCounterI2C
The Sensor sub-class for the Arduino-based external tipping bucket counter.
class RainCounterI2C_Tips
The Variable sub-class used for the total tip count output from an Adafruit Trinket based I2C tipping bucket counter.
class RainCounterI2C_Depth
The Variable sub-class used for the depth of rain output from an Adafruit Trinket based I2C tipping bucket counter.

Sensor Variable Counts

The number of variables that can be returned by the tipping bucket counter

#define BUCKET_NUM_VARIABLES = 2
Sensor::_numReturnedValues; the tipping bucket counter can report 2 values.
#define BUCKET_INC_CALC_VARIABLES = 1
Sensor::_incCalcValues; we calculate rain depth from the number of tips, assuming either English or metric calibration.

Sensor Timing

The sensor timing for a Trinket-based tipping bucket counter

  • Readings transferred from the tipping bucket to the logger are from past tips, so there is no need to wait for stability or measuring.
#define BUCKET_WARM_UP_TIME_MS = 0
Sensor::_warmUpTime_ms; the tipping bucket counter warms up in 0ms.
#define BUCKET_STABILIZATION_TIME_MS = 0
Sensor::_stabilizationTime_ms; the tipping bucket counter is stable after 0ms.
#define BUCKET_MEASUREMENT_TIME_MS = 0
Sensor::_measurementTime_ms; the tipping bucket counter takes 0ms to complete a measurement.

Rain Depth

The rain depth variable from a Trinket-based tipping bucket counter

  • Range and accuracy depend on the tipping bucket used

RainCounterI2C_Depth::RainCounterI2C_Depth(RainCounterI2C* parentSense, const char* uuid = "", const char* varCode = "RainCounterI2CVol") explicit

Construct a new RainCounterI2C_Depth object.

Parameters
parentSense The parent RainCounterI2C providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "RainCounterI2CVol".

#define BUCKET_RAIN_RESOLUTION = 2
Decimals places in string representation; rain depth should have 2.
#define BUCKET_RAIN_VAR_NUM = 0
Sensor variable number; rain depth is stored in sensorValues[0].
#define BUCKET_RAIN_VAR_NAME = "precipitation"
Variable name in ODM2 controlled vocabulary; "precipitation".
#define BUCKET_RAIN_UNIT_NAME = "millimeter"
Variable unit name in ODM2 controlled vocabulary; "millimeter".
#define BUCKET_RAIN_DEFAULT_CODE = "RainCounterI2CVol"
Default variable short code; "RainCounterI2CVol".

Tip Count

Defines for tip count variable from a Trinket-based tipping bucket counter

  • Range and accuracy depend on the tipping bucket used.

RainCounterI2C_Tips::RainCounterI2C_Tips(RainCounterI2C* parentSense, const char* uuid = "", const char* varCode = "RainCounterI2CTips") explicit

Construct a new RainCounterI2C_Tips object.

Parameters
parentSense The parent RainCounterI2C providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "RainCounterI2CTips".

#define BUCKET_TIPS_RESOLUTION = 0
Decimals places in string representation; the number of tips should have 0 - resolution is 1 tip.
#define BUCKET_TIPS_VAR_NUM = 1
Sensor variable number; the number of tips is stored in sensorValues[1].
#define BUCKET_TIPS_VAR_NAME = "precipitation"
Variable name in ODM2 controlled vocabulary; "precipitation".
#define BUCKET_TIPS_UNIT_NAME = "event"
Variable unit name in ODM2 controlled vocabulary; "event".
#define BUCKET_TIPS_DEFAULT_CODE = "RainCounterI2CTips"
Default variable short code; "RainCounterI2CTips".

Define documentation

#define BUCKET_NUM_VARIABLES = 2

Sensor::_numReturnedValues; the tipping bucket counter can report 2 values.


#define BUCKET_INC_CALC_VARIABLES = 1

Sensor::_incCalcValues; we calculate rain depth from the number of tips, assuming either English or metric calibration.


#define BUCKET_WARM_UP_TIME_MS = 0

Sensor::_warmUpTime_ms; the tipping bucket counter warms up in 0ms.


#define BUCKET_STABILIZATION_TIME_MS = 0

Sensor::_stabilizationTime_ms; the tipping bucket counter is stable after 0ms.


#define BUCKET_MEASUREMENT_TIME_MS = 0

Sensor::_measurementTime_ms; the tipping bucket counter takes 0ms to complete a measurement.


#define BUCKET_RAIN_RESOLUTION = 2

Decimals places in string representation; rain depth should have 2.

Resolution is typically either 0.01" or 0.2mm of rainfall, depending on if bucket is calibrated to English or metric units.


#define BUCKET_RAIN_VAR_NUM = 0

Sensor variable number; rain depth is stored in sensorValues[0].


#define BUCKET_RAIN_VAR_NAME = "precipitation"

Variable name in ODM2 controlled vocabulary; "precipitation".


#define BUCKET_RAIN_UNIT_NAME = "millimeter"

Variable unit name in ODM2 controlled vocabulary; "millimeter".


#define BUCKET_RAIN_DEFAULT_CODE = "RainCounterI2CVol"

Default variable short code; "RainCounterI2CVol".


#define BUCKET_TIPS_RESOLUTION = 0

Decimals places in string representation; the number of tips should have 0 - resolution is 1 tip.


#define BUCKET_TIPS_VAR_NUM = 1

Sensor variable number; the number of tips is stored in sensorValues[1].


#define BUCKET_TIPS_VAR_NAME = "precipitation"

Variable name in ODM2 controlled vocabulary; "precipitation".


#define BUCKET_TIPS_DEFAULT_CODE = "RainCounterI2CTips"

Default variable short code; "RainCounterI2CTips".