SapFlow Probe
A low-cost HRM probe for measuring a tree's water consumption
measure.h File Reference
#include "pinout.h"
#include "sleep.h"
#include "sd_log.h"
#include "lora.h"
#include <Wire.h>

Data Structures

struct  temperature
 Stores a tuple of temperature values. More...
 
struct  measure_stack
 Holds the persistent variables for a particular tree. More...
 

Functions

int measure (struct pt *pt, struct measure_stack &m)
 Captures a measurement from the three probes. More...
 
int baseline (struct pt *pt, struct measure_stack &m, char &rdv)
 Calculates baseline temperature. More...
 
int delta (struct pt *pt, struct measure_stack &m, char &rdv)
 Calculates temperature delta and sapflow. More...
 
double rtd_calc (int32_t raw)
 Converts raw measurement into degrees Celcius. More...
 
int mcp3424_measure (struct pt *pt, uint8_t addr, uint8_t channel, int32_t &result)
 Measures the value of a single ADC channel. More...
 

Function Documentation

◆ baseline()

int baseline ( struct pt *  pt,
struct measure_stack m,
char &  rdv 
)

Calculates baseline temperature.

This is a protothread that averages 10 samples of data to determine the "initial" or "baseline" temperature of the tree. It should be used before the heater is turned on.

Parameters
ptA pointer to the protothread control structure. Don't forget to initialize the control structure in setup().
mPersistent storage for this thread, like a private stack.
rdvRendezvous to ensure all baseline() instances stop at the same point
Returns
the status of the protothread (Waiting, yeilded, exited, or ended)

References cout(), measure_stack::i, measure_stack::latest, temperature::lower, measure_stack::maxtemp, measure_stack::reference, measure_stack::sem, measure_stack::treeID, and temperature::upper.

Referenced by schedule().

◆ delta()

int delta ( struct pt *  pt,
struct measure_stack m,
char &  rdv 
)

Calculates temperature delta and sapflow.

This is a protothread that calculates the sap flow by averaging measurements over 40 seconds. It also calls other functions to get the weight, package the data, log to an SD card, and send the information over LoRa.

Parameters
ptA pointer to the protothread control structure.
mPersistent storage for this thread, like a private stack.
rdvRendezvous to ensure all delta() instances stop at the same point
Returns
the status of the protothread (Waiting, yeilded, exited, or ended)

We compute sapflow using the following formula:: sapflow = k / x * log(v1 / v2) / 3600

  • k is an empirical constant
  • x is the distance between the probes
  • v1 is temperature increase of the upper probe from its baseline temperature
  • v2 is the temperature increase of the lower probe from its baseline temperature
  • 3600 is the number of seconds in an hour

In order to get a smoother result, we are takng the average of this calculation over a period of 40 seconds. Burges et. al. (2001) suggests that this value should converge.

References cout(), measure_stack::flow, measure_stack::i, int2str(), measure_stack::latest, temperature::lower, measure_stack::reference, rtc_ds, measure_stack::sem, measure_stack::treeID, and temperature::upper.

Referenced by schedule().

◆ mcp3424_measure()

int mcp3424_measure ( struct pt *  pt,
uint8_t  addr,
uint8_t  channel,
int32_t &  result 
)

Measures the value of a single ADC channel.

Parameters
ptA pointer to the protothread control structure
addrThe 7-bit I2C address of the ADC. If you choose, you can enter only the last three bits (0-7).
channelThe measurement channel. Valid inputs are 1-4.
resultThe raw 18-bit signed ADC value. Result is bit-extended to 32 bits.
Returns
the status of the protothread (Waiting, yeilded, exited, or ended)

References CHAN, DEPTH, PGA, and RDY.

Referenced by measure().

◆ measure()

int measure ( struct pt *  pt,
struct measure_stack m 
)

Captures a measurement from the three probes.

This is a protothread that reads the temperature from three RTD amplifiers connected to the probes in the tree. It stores the result in the struct paramter "latest" and logs to the SD card.

Parameters
ptA pointer to the protothread control structure. The default parameter is correct. Don't forget to initialize the control structure in setup().
mPersistent storage for this thread, like a private stack.
Returns
the status of the protothread (Waiting, yeilded, exited, or ended)

References measure_stack::addr, measure_stack::child, cout(), temperature::heater, int2str(), measure_stack::latest, temperature::lower, measure_stack::maxtemp, mcp3424_measure(), measure_stack::raw, rtc_ds, rtd_calc(), measure_stack::sem, measure_stack::treeID, and temperature::upper.

Referenced by loop().

◆ rtd_calc()

double rtd_calc ( int32_t  raw)

Converts raw measurement into degrees Celcius.

Parameters
rawThe value measured by the ADC
Returns
temperature in Celcius

Referenced by measure().