/* Soil Sensor Firmware * Soil Moisture and Vcc Measurement * Sensiplicity Systems * * Copyright 2015 * * Department of Botany and Plant Pathology * Center for Genome Research and Biocomputing * Oregon State University * Corvallis, OR 97331 * * This program is not free software; you can not redistribute it and/or * modify it at all. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include /* This modules measure soil moisture using a capacitive voltage divider. * The 2Mhz clock signal is sent to a voltage divider with a 100k resistor * at the top and the variable capacitor pad at the bottom. The resulting * signal goes to a peak detector connected to the ADC. The peak detector * must be discharged manually, as it has no pull-down resistor. */ #define ADC_OVERSAMPLING_BITS 3 /* Number of bits to add (to the 10 bits of the ADC) * through oversampling. Each bit results in * 4^OVERSAMPLING_BITS conversions per zone per measurement, * with each conversion taking 104us */ #define ADC_AVERAGES 16 /* The number of oversampled values to average together for the final result. */ /* Initialize the ADC. */ void init_adc(void); /* Get the number of zones on this device. */ uint8_t num_zones(void); /* Measure the moisture level of a given zone. * Returns a value between 0 and 2^(10 + OVERSAMPLING_BITS). * Lower values indicate more moisture. */ uint16_t get_moisture(uint8_t zone); /* Measure Vcc. * Returns Vcc in 1/32V increments. */ uint16_t get_vcc(void);