Crate anyleaf[][src]

Expand description

Driver for the AnyLeaf ph module. Allows you to measure pH using high-level code. See the Github repository for complete examples on the Rasperry Pi and stm32f3.

Example for Rasperry Pi, and other ph_linux systems: Cargo.toml:

[package]
name = "anyleaf_linux_example"
version = "0.1.0"
authors = ["Anyleaf <anyleaf@anyleaf.org>"]
edition = "2018"

[dependencies]
embedded-hal = "^0.2.3"
ph_linux-embedded-hal = "^0.3.0"
anyleaf = "^0.1.6"

main.rs:

use embedded_hal::blocking::delay::DelayMs;
use linux_embedded_hal::{Delay, I2cdev};
use anyleaf::{PhSensor, CalPt, CalSlot, TempSource};

fn main() {
   let i2c = I2cdev::new("/dev/i2c-1").unwrap();
   let mut ph_sensor = PhSensor::new(i2c);

   // 2 or 3 pt calibration both give acceptable results.
   // Calibrate with known values. (voltage, pH, temp in °C).
   // You can find voltage and temperature with `ph_sensor.read_voltage()` and
   // `ph_sensor.read_temp()` respectively.
   // For 3 pt calibration, pass a third argument to `calibrate_all`.
   ph_sensor.calibrate_all(
       CalPt::new(0., 7., 25.), CalPt::new(0.17, 4., 25.), None,
   );

   // Or, call these with the sensor in the appropriate buffer solution.
   // This will automatically use voltage and temperature.
   // Voltage and Temp are returned, but calibration occurs
   // without using the return values.
   // (V, T) = ph_sensor.calibrate(CalSlot::One, 7.);
   // ph_sensor.calibrate(CalSlot::Two, 4.);

   // Store the calibration parameters somewhere, so they persist
   // between program runs.

   let mut delay = Delay {};

   loop {
       let pH = ph_sensor.read(TempSource::OnBoard).unwrap();
       println!("pH: {}", pH);

       delay.delay_ms(1000);
   }
}

Re-exports

pub use rtd::Rtd;
pub use rtd::RtdType;
pub use rtd::Wires;

Modules

Supports the Max31865. Based on rudihorn’s max31865 lib, with modifications like support for Pt1000, and borrowing SPI instead of owning the bus.

Structs

Data for a single pH (or other ion measurement) calibration point.

Data for a single ORP (or other ion measurement) calibration point.

Data for a single ORP (or other ion measurement) calibration point.

Data for a single temperature calibration point.

Enums

Keeps our calibration organized, so we track when to overwrite.

We use SensorError on results from the WaterMonitor struct.

Specify onboard or offboard temperature source.

Functions

Map voltage to temperature for the TI LM61, in °C Datasheet: https://datasheet.lcsc.com/szlcsc/Texas- Instruments-TI-LM61BIM3-NOPB_C132073.pdf

Convert a 16-bit digital value to voltage. Input ranges from +- 2.048V; this is configurable. Output ranges from -32_768 to +32_767.