MH Embedded Systems Engineer

Sap Flow Meter

Summary

A lot of work has gone into determining best-practices for keeping a healthy orchard. Extension services provide advice on everything from soil amendments and fertilization to which pesticides to use and when to spray. However, less is known about water usage. How much water do trees use? Is the orchard getting irrigated evenly? Does it have adequate drainage? Measuring the sap flow gives you access to that information, since sap is primarily water. If you measure the sap flow on every tree, you can correlate water usage with fruit size and quality to determine the optimal watering practices, and potentially predict which trees are healthier and which may be diseased.

The sap flow project was a continuation of a multi-year project run by the OPEnS Lab and College of Agriculture at OSU, sponsored by the Washington State Tree Fruit Association. Previous years had left the project in an unknown state. Critical pieces of the project were missing and undocumented. I was part of a small team tasked with creating an accurate, affordable sap flow meter within the year.

Towards that goal we made significant developments. We increased the measurement resolution of the RTD amplifiers by 30x, resulting in very precise temperature measurements with minimal quantization error. We adapted the firmware to use protothreads, which both enforced the desired sample rate and allowed up to five probes to connect to one datalogger. We developed an Arduino-compatible low-memory DSP library that supports arbitrary order FIR and IIR filters. We developed state-of-the-art Arduino debugging tools, using a watchdog timer to record where the program was executing slowly. We used a Raspberry Pi as a low-cost LoRa hub, while leveraging a LAMP stack on the Pi to provide data visualization for the farmer without internet. We made a compact and feature-rich PCB that stacks with Adafruit Featherwings for extensible projects.

How it works

The probe works by creating a heat pulse in the sapwood, and sensing which direction the pulse travels. It uses three small probes inserted into the trunk, following the direction of the grain. The middle probe has a heater which is turned on for several seconds. The upper and lower probes measure the temperature of the sapwood during and after the heat pulse. The relative amplitudes of the observed pulses indicates the direction and velocity of sap flow. You can find more about the Heat Ratio Method in An improved heat pulse method to measure low and reverse rates of sap flow in woody plants by Burgess et al (2001).

Firmware

Our client required that we use the Arduino framework because they wanted to maintain the project in-house and Arduino is what they had been developing for. However, with the increasing complexity of the firmware I realized that a single-threaded program was much harder to maintain and I included Adam Dunkel's Protothread library, a lightweight solution for concurrency and non-blocking delays. This allowed me to spawn a thread for each probe and put the steps in sequence, rather than nesting for loops inside of a state machine. See the documentation for more details. Source code is at https://github.com/kamocat/SapFlowMeter