SapFlow Probe
A low-cost HRM probe for measuring a tree's water consumption
sapflow_protothread.ino File Reference
#include "pinout.h"
#include "schedule.h"
#include "measure.h"

Go to the source code of this file.

Functions

void setup ()
 One-time initialization. More...
 
void loop ()
 Implicit loop. More...
 

Function Documentation

◆ loop()

void loop ( )

Implicit loop.

This function is called inside a hidden loop in the Arduino framework. We're using it for protothread scheduling. All the real work happens inside the protothreads.

Definition at line 47 of file sapflow_protothread.ino.

47  {
48  measure(); //< Actually performs measurement. Gated by the sample_timer.
49  schedule(); //< Controls the sequence of actions in our measurement cycle
50  sample_timer(); //< Sets the sample rate at 1Hz
51 }

◆ setup()

void setup ( )

One-time initialization.

This function is called when the microcontroller first starts up or is reset. It's good for things that should only happen once. You do not need to call it yourself. It initializes some hardware, puts the protothreads in a known state, and begins the measurement cycle (which starts with sleep)

Definition at line 12 of file sapflow_protothread.ino.

12  {
13  pinMode(HEATER, OUTPUT);
14  digitalWrite(HEATER, LOW);
15  Serial.begin(115200);
16  Serial.println("Serial connected");
17  halt_location.init(2000);
18  //Initialize the Threads
19  PT_INIT(&sched_thd);
20  PT_INIT(&measure_thd);
21  PT_INIT(&sample_timer_thd);
22  PT_INIT(&baseline_thd);
23  PT_INIT(&delta_thd);
24  sleep = false;
25 
26 // Initialize the hardware
27  pinMode(EN_3v3, OUTPUT);
28  pinMode(EN_5v, OUTPUT);
29  pinMode(I2C_SCL, INPUT_PULLUP);
30  pinMode(I2C_SDA, INPUT_PULLUP);
31  pinMode(RFM95_CS, OUTPUT);
32  digitalWrite(RFM95_CS, HIGH); //< disable LoRa until we're ready to use
33  digitalWrite(STATUS_LED, HIGH);
34  digitalWrite(EN_3v3, LOW);
35  digitalWrite(EN_5v, HIGH);
36  pinMode(SPI_SCK, OUTPUT);
37  pinMode(SPI_MOSI, OUTPUT);
38  pinMode(SD_CS, OUTPUT);
39  sd.begin(SD_CS, SD_SCK_MHZ(1));
40 }
measure_thd
static struct pt measure_thd
Protothread control structure for measure()
Definition: measure.h:29
I2C_SCL
@ I2C_SCL
I2C clock pin. Pull-up.
Definition: pinout.h:19
baseline_thd
static struct pt baseline_thd
Protothread control structure for baseline()
Definition: measure.h:31
EN_5v
@ EN_5v
Control pin for 5v Power rail. Output, Active-high.
Definition: pinout.h:13
STATUS_LED
@ STATUS_LED
Built-in LED on feather. Active-high.
Definition: pinout.h:17
EN_3v3
@ EN_3v3
Control pin for 3.3V power rail. Output, Active-low.
Definition: pinout.h:12
sched_thd
static struct pt sched_thd
Protothread control structure for measure()
Definition: schedule.h:9
sample_timer
int sample_timer(struct pt *pt)
Controls timing of the measurements.
Definition: measure.cpp:8
SPI_MOSI
@ SPI_MOSI
SPI data pin. Output.
Definition: pinout.h:21
FunctionMarker::init
void init(int period)
Initialize the watchdog at the period given.
Definition: debug.cpp:26
measure
int measure(struct pt *pt)
Captures a measurement from the three probes.
Definition: measure.cpp:22
sd
static SdFat sd
File system object.
Definition: sd_log.h:14
HEATER
@ HEATER
Control pin for heater switch. Output, Active-high.
Definition: pinout.h:15
RFM95_CS
@ RFM95_CS
SPI chip select used for LoRa. Output, Active-low.
Definition: pinout.h:28
halt_location
static class FunctionMarker halt_location
Singleton of our debug class.
Definition: debug.h:64
delta_thd
static struct pt delta_thd
Protothread control structure for delta()
Definition: measure.h:32
sample_timer_thd
static struct pt sample_timer_thd
Protothread control structure for sample_timer()
Definition: measure.h:30
schedule
int schedule(struct pt *pt)
Controls general measurement schedule.
Definition: schedule.cpp:81
sleep
static bool sleep
Global flag to prep for sleep.
Definition: schedule.h:13
I2C_SDA
@ I2C_SDA
I2C data pin. Pull-up.
Definition: pinout.h:18
SPI_SCK
@ SPI_SCK
SPI clock pin. Output.
Definition: pinout.h:20
SD_CS
@ SD_CS
SPI chip select for SD card. Output, Active-low.
Definition: pinout.h:14