ALog
v0.3.2
Open-source Arduino-based data logger library, designed for field science
|
Public Member Functions | |
ALog () | |
ALog library for the Arduino-based data loggers. More... | |
void | initialize (char *_logger_name, char *_datafilename, int _hourInterval, int _minInterval, int _secInterval, bool _ext_int=false, bool _LOG_ALL_SENSORS_ON_BUCKET_TIP=false) |
void | setupLogger () |
void | sleep () |
void | goToSleep_if_needed () |
void | startLogging () |
void | endLogging () |
void | startAnalog () |
void | endAnalog () |
void | sensorPowerOn () |
void | sensorPowerOff () |
bool | get_use_sleep_mode () |
void | set_LEDpin (int8_t _pin) |
void | set_SDpowerPin (int8_t _pin) |
void | set_RTCpowerPin (int8_t _pin) |
void | set_SensorPowerPin (int8_t _pin) |
uint16_t | get_serial_number () |
float | get_3V3_measured_voltage () |
float | get_5V_measured_voltage () |
float | readPin (uint8_t pin) |
float | readPinOversample (uint8_t pin, uint8_t adc_bits) |
float | analogReadOversample (uint8_t pin, uint8_t adc_bits=10, uint8_t nsamples=1, bool debug=false) |
float | thermistorB (float R0, float B, float Rref, float T0degC, uint8_t thermPin, uint8_t ADC_resolution_nbits=14, bool Rref_on_GND_side=true, bool oversample_debug=false, bool record_results=true) |
void | ultrasonicMB_analog_1cm (uint8_t nping, uint8_t EX, uint8_t sonicPin, bool writeAll) |
float | maxbotixHRXL_WR_Serial (uint8_t Ex, uint8_t npings, bool writeAll, int maxRange, bool RS232=false) |
void | maxbotixHRXL_WR_analog (uint8_t nping=10, uint8_t sonicPin=A0, uint8_t EX=99, bool writeAll=true, uint8_t ADC_resolution_nbits=10) |
void | Decagon5TE (uint8_t excitPin, uint8_t dataPin) |
void | DecagonGS1 (uint8_t pin, float Vref, uint8_t ADC_resolution_nbits=14) |
void | vdivR (uint8_t pin, float Rref, uint8_t ADC_resolution_nbits=10, bool Rref_on_GND_side=true) |
void | linearPotentiometer (uint8_t linpotPin, float Rref, float slope, char *_distance_units, float intercept=0, uint8_t ADC_resolution_nbits=14, bool Rref_on_GND_side=true) |
void | HTM2500LF_humidity_temperature (uint8_t humidPin, uint8_t thermPin, float Rref_therm, uint8_t ADC_resolution_nbits=14) |
void | HM1500LF_humidity_with_external_temperature (uint8_t humidPin, float R0_therm, float B_therm, float Rref_therm, float T0degC_therm, uint8_t thermPin_therm, uint8_t ADC_resolution_nbits=14) |
void | Inclinometer_SCA100T_D02_analog_Tcorr (uint8_t xPin, uint8_t yPin, float Vref, float Vsupply, float R0_therm, float B_therm, float Rref_therm, float T0degC_therm, uint8_t thermPin_therm, uint8_t ADC_resolution_nbits=14) |
void | Anemometer_reed_switch (uint8_t interrupt_pin_number, unsigned long reading_duration_milliseconds, float meters_per_second_per_rotation) |
void | Wind_Vane_Inspeed (uint8_t vanePin) |
void | Pyranometer (uint8_t analogPin, float raw_mV_per_W_per_m2, float gain, float V_ref, uint8_t ADC_resolution_nbits=14) |
void | Barometer_BMP180 () |
void | _sensor_function_template (uint8_t pin, float param1, float param2, uint8_t ADC_bits=14, bool flag=false) |
void | HackHD (int control_pin, bool want_camera_on) |
float | Honeywell_HSC_analog (int pin, float Vsupply, float Vref, float Pmin, float Pmax, int TransferFunction_number, int units, uint8_t ADC_resolution_nbits=14) |
ALog::ALog | ( | ) |
ALog library for the Arduino-based data loggers.
ALog data logger library: methods to:
All help documentation here assumes you have created an instance of the "ALog" class.
void ALog::_sensor_function_template | ( | uint8_t | pin, |
float | param1, | ||
float | param2, | ||
uint8_t | ADC_bits = 14 , |
||
bool | flag = false |
||
) |
Function to help lay out a new sensor interface. This need not be "void": it may return a value as well.
Details about sensor go here
pin | You often need to specify interface pins |
param1 | A variable for the sensor or to interpret its value |
param2 | A variable for the sensor or to interpret its value |
ADC_bits | You often need to specify how much the analog-to-digital converter should be oversampled; this can range from 10 (no oversampling) to 16 (maximum possible oversampling before certainty in the oversampling method drops) |
flag | Something that helps to set an option |
Example (made up):
float ALog::analogReadOversample | ( | uint8_t | pin, |
uint8_t | adc_bits = 10 , |
||
uint8_t | nsamples = 1 , |
||
bool | debug = false |
||
) |
Higher analog resolution through oversampling
This function incorporates oversampling to extend the ADC precision past ten bits by taking more readings and statistically combing them.
Returns a floating point number between 0 and 1023 in order to be intechangable with the Arduino core AnalogRead() function
It is often used within other sensor functinons to increase measurement precision.
pin | is the analog pin number |
adc_bits | is the reading precision in bits (2^adc_bits). The ATMega328 (Arduino Uno and ALog BottleLogger core chip) has a base ADC precision of 10 bits (returns values of 0-1023) A reasonable maximum precision gain is (base_value_bits)+6, so 16 bits is a reasonable maximum precision for the ALog BottleLogger. |
nsamples | is the number of times you want to poll the particular sensor and write the output to file. |
debug | is a flag that, if true, will write all of the values read during the oversampling to "Oversample.txt". |
Example:
Readings that require more bits of precision will take longer.
For analog measurements that do not require more than 10 bits of precision, use alog.readpin(int pin) or the standard Arduino "AnalogRead" function.
Based on eRCaGuy_NewAnalogRead::takeSamples(uint8_t analogPin)
Example:
void ALog::Anemometer_reed_switch | ( | uint8_t | interrupt_pin_number, |
unsigned long | reading_duration_milliseconds, | ||
float | meters_per_second_per_rotation | ||
) |
Anemometer that flips a reed switch each time it spins.
interrupt_pin_number | is the digital pin number corresponding to the appropriate interrupt; it uses the Arduino digitalPinToInterrupt(n_pin) function to properly attach the interrupt. On the ALog BottleLogger, this number will always be 3. |
reading_duration_milliseconds | How long will you count revolutions? Shorter durations save power, longer durations increase accuracy; very long durations will produce long-term averages. Typical values are a few seconds. |
meters_per_second_per_rotation | Conversion factor between revolutions and wind speed. For the Inspeed Vortex wind sensor that we have used (http://www.inspeed.com/anemometers/Vortex_Wind_Sensor.asp), this is: 2.5 mph/Hz = 1.1176 (m/s)/Hz |
This function depends on the global variable rotation_count.
Example:
void ALog::Barometer_BMP180 | ( | ) |
Read absolute pressure in mbar.
This function reads the absolute pressure in mbar (hPa). BMP180 sensor incorporates on board temperature correction. Uses I2C protocol.
Example:
void ALog::Decagon5TE | ( | uint8_t | excitPin, |
uint8_t | dataPin | ||
) |
Reads a Decagon Devices 5TE soil moisture probe.
NEEDS TESTING with current ALog version.
Returns Dielectric permittivity [-unitless-], electrical conductivity [dS/m], and temperature [degrees C]. Soil moisture is calculated through postprocessing.
Uses SoftwareSerial, and therefore has the potential to go unstable; however, we have a time limit, so this won't crash the logger: it will just keep the logger from recording good data.
Modified from Steve Hicks' code for an LCD reader by Andy Wickert
excitPin | activates the probe and powers it |
dataPin | receives incoming serial data at 1200 bps |
Example:
void ALog::DecagonGS1 | ( | uint8_t | pin, |
float | Vref, | ||
uint8_t | ADC_resolution_nbits = 14 |
||
) |
Ruggedized Decagon Devices soil moisture sensor
pin | Analog pin number |
Vref | is the reference voltage of the ADC; on the ALog, this is a precision 3.3V regulator (unless a special unit without this regulator is ordered; the regulator uses significant power) |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) |
Example:
void ALog::endAnalog | ( | ) |
Turn off power to analog sensors
Actually just turns off 3V3 regulator that could power anything. Keeping this around for backwards compatibility; look to sensorPowerOff() for the preferred version of this.
void ALog::endLogging | ( | ) |
Endslogging and returns to sleep
Ends line, turns of SD card, and resets alarm: ready to sleep.
Also runs tipping bucket rain gauge code (function that records time stamp) if one is attached and activated.
IMPORTANT: If the logger is not writing data to the card, and the card is properly inserted, the manually-set delay here may be the problem. We think we have made it long enough, but because it is hard-coded, there could be an unforeseen circumstance in which it is not!
float ALog::get_3V3_measured_voltage | ( | ) |
Retrieve the ALog's 3.3V regulator's actual measured voltage under load, stored in the EEPROM.
It is stored in bytes 2, 3, 4, and 5 of the EEPROM.
float ALog::get_5V_measured_voltage | ( | ) |
Retrieve the ALog's 5V charge pump's actual measured voltage under load, stored in the EEPROM.
It is stored in bytes 6, 7, 8, and 9 of the EEPROM.
uint16_t ALog::get_serial_number | ( | ) |
Retrieve the ALog's serial number from EEPROM .
It is stored in bytes 0 and 1 of the EEPROM.
bool ALog::get_use_sleep_mode | ( | ) |
Does the logger enter a low-power sleep mode? T/F.
void ALog::goToSleep_if_needed | ( | ) |
Places logger into sleep mode iff this is being used.
Function is accessible from Arduino sketch; is designed for cases in which an external override may be required.
void ALog::HackHD | ( | int | control_pin, |
bool | want_camera_on | ||
) |
HackHD camera control function
Control the HackHD camera: this function turns the HackHD on or off and records the time stamp from when the HackHD turns on/off in a file called "camera.txt".
Because this function turns the camera on or off, you have to ensure that you write a mechanism to keep it on for some time in your code. This could be checking the time each time you wake and deciding what to do, for example. In short: this function is a lower-level utility that requires the end-user to write the rest of the camera control sequence themselves.
control_pin | is the pin connected to the HackHD on/off switch; Dropping control_pin to GND for 200 ms turns camera on or off. |
want_camera_on | is true if you want to turn the camera on, false if you want to turn the camera off. |
CAMERA_IS_ON is a global varaible attached to this function that saves the state of the camera; it will be compared to "want_camera_on", such that this function will do nothing if the camera is already on (or off) and you want it on (or off).
Power requirements:
Example (not tested):
This example could be used to capture flow during a flash flood. See:
void ALog::HM1500LF_humidity_with_external_temperature | ( | uint8_t | humidPin, |
float | R0_therm, | ||
float | B_therm, | ||
float | Rref_therm, | ||
float | T0degC_therm, | ||
uint8_t | thermPin_therm, | ||
uint8_t | ADC_resolution_nbits = 14 |
||
) |
HM1500LF Relative humidity sensor with external temperature correction
This function measures the relative humidity of using a HTM1500 relative humidity sensor and an external thermistor. The relative humidity and temperature are measured using an oversampling method. Results are displayed on the serial monitor and saved onto the SD card to four decimal places. Temperature and relative humidity are recorded.
humidPin | is the analog pin connected to the humidity output voltage of the module. |
R0_therm | is the resistance of the thermistor at the known temperature. |
B_therm | is the B- or β- parameter of the thermistor. |
Rref_therm | is the resistance of the corresponding reference resistor for that analog pin. |
T0degC_therm | is a thermistor calibration. |
thermPin_therm | is the analog pin connected to the tempurature output voltage of the module. |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10) |
Example:
float ALog::Honeywell_HSC_analog | ( | int | pin, |
float | Vsupply, | ||
float | Vref, | ||
float | Pmin, | ||
float | Pmax, | ||
int | TransferFunction_number, | ||
int | units, | ||
uint8_t | ADC_resolution_nbits = 14 |
||
) |
Cost-effective pressure sensor from Honeywell
Datasheet: http://sensing.honeywell.com/index.php?ci_id=151133
See also the Honeywell_HSC_analog example.
pin | Analog pin number |
Vsupply | Supply voltage to sensor |
Vref | is the reference voltage of the ADC; on the ALog, this is a precision 3.3V regulator (unless a special unit without this regulator is ordered; the regulator uses significant power) |
Pmin | Minimum pressure in range of sensor |
Pmax | Maximum pressure in range of sensor |
Pmax | Maximum pressure in range of sensor |
TransferFunction_number | 1, 2, 3, or 4: which transfer function is used to convert voltage to pressure
|
units | Output units
|
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) |
Example:
void ALog::HTM2500LF_humidity_temperature | ( | uint8_t | humidPin, |
uint8_t | thermPin, | ||
float | Rref_therm, | ||
uint8_t | ADC_resolution_nbits = 14 |
||
) |
HTM2500LF Relative humidity and temperature sensor
This function measures the relative humidity of using a HTM2500 tempurature and relative humidity module. The relative humidity and temperature is measured using a 14 bit oversampling method. Results are displayed on the serial monitor and saved onto the SD card to four decimal places.
humidPin | is the analog pin connected to the humidity output voltage of the module. |
thermPin | is the analog pin connected to the tempurature output voltage of the module. |
Rref_therm | is the value of the reference resistor that you use with the built-in thermistor (reference resistor supplied separately, placed in appropriate slot in header) |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10) |
Example:
This function is designed for ratiometric operation – that is, the humidity sensor must be powered by the same voltage regulator that is connected to the the analog reference pin – for the ALog v2.0, this is a high-precision 3V3 regulator.
void ALog::Inclinometer_SCA100T_D02_analog_Tcorr | ( | uint8_t | xPin, |
uint8_t | yPin, | ||
float | Vref, | ||
float | Vsupply, | ||
float | R0_therm, | ||
float | B_therm, | ||
float | Rref_therm, | ||
float | T0degC_therm, | ||
uint8_t | thermPin_therm, | ||
uint8_t | ADC_resolution_nbits = 14 |
||
) |
Inclinometer, including temperature correction from an external sensor.
xPin | Analog pin number corresponding to x-oriented tilts |
yPin | Analog pin number corresponding to y-oriented tilts |
Vref | is the reference voltage of the analog-digital comparator; it is 3.3V on the ALog. |
Vsupply | is the input voltage that drives the sensor, and is typically between 3.3 and 5V. |
R0_therm | is a thermistor calibration. |
B_therm | is the B- or β- parameter of the thermistor. |
Rref_therm | is the resistance of the corresponding reference resistor for that analog pin. |
T0degC_therm | is a thermistor calibration. |
thermPin_therm | is the analog pin connected to the tempurature output voltage of the module. |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10). It is applied to both the inclinomter and its temperature correction |
Example:
void ALog::initialize | ( | char * | _logger_name, |
char * | _datafilename, | ||
int | _hourInterval, | ||
int | _minInterval, | ||
int | _secInterval, | ||
bool | _ext_int = false , |
||
bool | _LOG_ALL_SENSORS_ON_BUCKET_TIP = false |
||
) |
Pass all variables needed to initialize logging.
_logger_name | Name associated with this data logger; often helps to relate it to the project or site |
_datafilename | Name of main data file saved to SD card; often helps to relate it to the project or site; used to be limited to 8.3 file naming convention, but now strictly is not. (I still use 8.3 names for safety's sake!) |
_hourInterval | How many hours to wait before logging again; can range from 0-24. |
_minInterval | How many minutes to wait before logging again; can range from 0-59. |
_secInterval | How many seconds to wait before logging again; can range from 0-59. |
If all time-setting functions are 0, then the logger will not sleep, and instead will log continuously. This sets the flag "_use_sleep_mode" to be false.
_ext_int | External interrupt, set to be a tipping-bucket rain gauge, that triggers event-based logging of a timestamp |
_LOG_ALL_SENSORS_ON_BUCKET_TIP | Flag that tells the logger to read every sensor when the bucket tips (if _ext_int is true) and write their outputs to "datafile" (i.e. the main data file whose name you specify with _filename; this is in addition to writing the timestamp of the rain gauge bucket tip. |
ALog Data logger model does not need to be set: it is automatically determined from the MCU type and is used to modify pinout-dependent functions.
Example:
void ALog::linearPotentiometer | ( | uint8_t | linpotPin, |
float | Rref, | ||
float | slope, | ||
char * | _distance_units, | ||
float | intercept = 0 , |
||
uint8_t | ADC_resolution_nbits = 14 , |
||
bool | Rref_on_GND_side = true |
||
) |
Linear potentiometer (radio tuner) to measure distance
Distance based on resistance in a sliding potentiometer whose resistance may be described as a linear function
linpotPin | Analog pin number |
Rref | Resistance value of reference resistor [ohms] |
slope | Slope of the line (distance = (slope)R + R0) |
intercept | (R0) of the line (distance = (slope)R + R0) |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) |
_distance_units | is the name of the units of distance that are used in the linear calibration equation, and are therefore the units of this function's output. |
Rref_on_GND_side | indicates the configuration of the voltage divider. True if using Alog provided Reference resistor terminals. If false, the reference resitor must be instead connected via the screw terminals. This is set true for external sensors that are built to require a VCC-side reference resistor. |
The output units will be whatever you have used to create your linear calibration equation
Example:
void ALog::maxbotixHRXL_WR_analog | ( | uint8_t | nping = 10 , |
uint8_t | sonicPin = A0 , |
||
uint8_t | EX = 99 , |
||
bool | writeAll = true , |
||
uint8_t | ADC_resolution_nbits = 10 |
||
) |
Newer 1-mm precision MaxBotix rangefinders: analog readings
This function measures the distance between the ultrasonic sensor and an \ acoustically-reflective surface, typically water or snow. Measures distance in milimeters. Results are displayed on the serial monitor and saved onto the SD card.
nping | is the number of range readings to take (number of pings). The mean range will be calculated and output to the serial monitor and SD card followed by the standard deviation. |
sonicPin | is the analog input channel hooked up to the maxbotix sensor. |
EX | is a digital output pin used for an excitation pulse. If maxbotix sensor is continuously powered, a reading will be taken when this pin is flashed high. Set to '99' if excitation pulse is not needed. |
writeAll | will write each reading of the sensor (each ping) to the serial monitor and SD card. |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) |
Example:
Note that sensor should be mounted away from supporting structure. These are the standard recommendations:
However, in our tests, the sensors with filtering algorithms function perfectly well even when positioned close to the mast, and a short mast increases the rigidity of the installation. This was tested in the lab by placing the MaxBotix sensor flush with table legs and testing distance readings to the floor.
float ALog::maxbotixHRXL_WR_Serial | ( | uint8_t | Ex, |
uint8_t | npings, | ||
bool | writeAll, | ||
int | maxRange, | ||
bool | RS232 = false |
||
) |
Uses the UART interface to record data from a MaxBotix sensor.
NOTE: THIS HAS CUASED LOGGERS TO FREEZE IN THE PAST; WHILE IT IS QUITE LIKELY THAT THE ISSUE IS NOW SOLVED, MORE TESTING IS REQUIRED. (ADW, 26 NOVEMBER 2016) (maybe solved w/ HW Serial?)
Ex | Excitation pin that turns the sensor on; if this is not needed (i.e. you are turning main power off and on instead), then just set this to a value that is not a pin, and ensure that you turn the power to the sensor off and on outside of this function |
npings | Number of pings over which you average; each ping itself includes ten short readings that the sensor internally processes |
writeAll | will write each reading of the sensor (each ping) to the serial monitor and SD card. |
maxRange | The range (in mm) at which the logger maxes out; this will be remembered to check for errors and to become a nodata values |
RS232 | this is set true if you use inverse (i.e. RS232-style) logic; it works at standard logger voltages (i.e. it is not true RS232). If false, TTL logic will be used. |
Example:
void ALog::Pyranometer | ( | uint8_t | analogPin, |
float | raw_mV_per_W_per_m2, | ||
float | gain, | ||
float | V_ref, | ||
uint8_t | ADC_resolution_nbits = 14 |
||
) |
Pyranometer wtih instrumentation amplifier
Pyranomiter is from Kipp and Zonen
nominal raw_output_per_W_per_m2_in_mV = 10./1000.; // 10 mV at 1000 W/m**2
Actual raw output is based on calibration.
analogPin | is the pin that receives the amplified voltage input |
raw_mV_per_W_per_m2 | is the conversion factor of the pyranometer: number of millivolts per (watt/meter^2). This does not include amplification! |
gain | is the amplification factor |
Vref | is the reference voltage of the ADC; on the ALog, this is a precision 3.3V regulator (unless a special unit without this regulator is ordered; the regulator uses significant power) |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) |
Example:
float ALog::readPin | ( | uint8_t | pin | ) |
Read the analog value of a pin.
This function returns the analog to digital converter value (0 - 1023). Results are displayed on the serial monitor and saved onto the SD card.
pin | is the analog pin number to be read. |
Example:
float ALog::readPinOversample | ( | uint8_t | pin, |
uint8_t | adc_bits | ||
) |
Read the analog value of a pin, with extra resolution from oversampling
This function incorporates oversampling to extend the ADC precision past ten bits by taking more readings and statistically combing them. Results are displayed on the serial monitor and saved onto the SD card.
pin | is the analog pin number to be read. |
adc_bits | is the reading precision in bits (2^adc_bits). The ATMega328 (Arduino Uno and ALog BottleLogger core chip) has a base ADC precision of 10 bits (returns values of 0-1023) A reasonable maximum precision gain is (base_value_bits)+6, so 16 bits is a reasonable maximum precision for the ALog BottleLogger. |
Example:
Output values will range from 0-1023, but be floating-point.
Readings that require more bits of precision will take longer.
void ALog::sensorPowerOff | ( | ) |
Turn OFF power to 3V3 regulator that connects to screw terminals.
This cuts 3V3 power to external devices.
void ALog::sensorPowerOn | ( | ) |
Turn ON power to 3V3 regulator that connects to screw terminals.
This powers external devices.
void ALog::set_LEDpin | ( | int8_t | _pin | ) |
Set which pin to use for the main indicator LED.
Run this, if needed, before setupLogger()
void ALog::set_RTCpowerPin | ( | int8_t | _pin | ) |
Set which pin activates the 3V3 regulator to power the RTC (real-time clock).
void ALog::set_SDpowerPin | ( | int8_t | _pin | ) |
Set which pin activates the 3V3 regulator to power the SD card.
void ALog::set_SensorPowerPin | ( | int8_t | _pin | ) |
Set which pin activates the 3V3 regulator to power sensors and any other external 3V3 devices that receive power from the ALog's 3V3 regulator.
void ALog::setupLogger | ( | ) |
void ALog::sleep | ( | ) |
Puts the ALog data logger into a low-power sleep mode
Sets the "IS_LOGGING" flag to false, disables the watchdog timer, and puts the logger to sleep.
void ALog::startAnalog | ( | ) |
Turn on power to analog sensors
Actually just turns on 3V3 regulator that could power anything. Keeping this around for backwards compatibility; look to sensorPowerOn() for the preferred version of this.
void ALog::startLogging | ( | ) |
Wakes the logger and starts logging
Wakes the logger: sets the watchdog timer (a failsafe in case the logger hangs), checks and clears alarm flags, looks for rain gauge bucket tips (if they occur during the middle of a logging event (ignore) or if they include a command to read all sensors with a tip), and starts to log to "datafile", if it can.
If the logger cannot reach the SD card, it sends out an LED warning message of 20 rapid flashes.
float ALog::thermistorB | ( | float | R0, |
float | B, | ||
float | Rref, | ||
float | T0degC, | ||
uint8_t | thermPin, | ||
uint8_t | ADC_resolution_nbits = 14 , |
||
bool | Rref_on_GND_side = true , |
||
bool | oversample_debug = false , |
||
bool | record_results = true |
||
) |
Read the analog value of a pin, with extra resolution from oversampling
This function measures temperature using a thermistor characterised with the B (or β) parameter equation, which is a simplification of the Steinhart-Hart equation
The function compares the thermistor risistance with the reference resistor using a voltage divider.
It returns a float of the temperature in degrees celsius. Results are displayed on the serial monitor and saved onto the SD card to four decimal places.
R0 | is the resistance of the thermistor at the known temperature |
T0degC. | [Ω] |
B | is the β parameter of the thermistor. [K] |
Rref | is the resistance of the corresponding reference resistor for \ the analog pin set by ThermPin (below). [Ω] |
T0degC | is the temperature at which R0 was calibrated. [°C] |
thermPin | is the analog pin number to be read. [-] |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) [bits] |
Rref_on_GND_side | indicates the configuration of the voltage divider. True if using Alog provided Reference resistor terminals. If false, the reference resitor must be instead connected via the screw terminals. This is set true for external sensors that are built to require a VCC-side reference resistor. |
oversample_debug | is true if you want a separate file, "Oversample.txt", to record every individual reading used in the oversampling. |
record_results | is true if you want to save results to the SD card and print to the serial monitor. |
Examples:
void ALog::ultrasonicMB_analog_1cm | ( | uint8_t | nping, |
uint8_t | EX, | ||
uint8_t | sonicPin, | ||
bool | writeAll | ||
) |
Old 1-cm resolution Maxbotix ultrasonic rangefinders: analog measurements
This function measures the distance between the ultrasonic sensor and an acustically reflective surface, typically water or snow. Measures distance in centimeters. Results are displayed on the serial monitor and saved onto the SD card.
This is for the older MaxBotix sensors, whose maximum precision is in centimeters.
nping | is the number of range readings to take (number of pings). The mean range will be calculated and output to the serial monitor and SD card followed by the standard deviation. |
EX | is a digital output pin used for an excitation pulse. If maxbotix sensor is continuously powered a reading will be taken when this pin is flashed high. Set to '99' if excitation pulse is not needed. |
sonicPin | is the analog input channel hooked up to the maxbotix sensor. |
writeAll | will write each reading of the sensor (each ping) to the serial monitor and SD card. |
Example:
Note that sensor should be mounted away from supporting structure. For a mast that is 5 meters high (or higher) the sensor should be mounted at least 100cm away from the mast. For a mast that is 2.5 meters high (or lower) the sensor should be at least 75cm away from the mast.
void ALog::vdivR | ( | uint8_t | pin, |
float | Rref, | ||
uint8_t | ADC_resolution_nbits = 10 , |
||
bool | Rref_on_GND_side = true |
||
) |
Resistance from a simple voltage divider
pin | Analog pin number |
Rref | Resistance value of reference resistor [ohms] |
ADC_resolution_nbits | (10-16 for the ALog BottleLogger) is the number of bits of ADC resolution used (oversampling for >10 bits) |
Rref_on_GND_side | indicates the configuration of the voltage divider. True if using Alog provided Reference resistor terminals. If false, the reference resitor must be instead connected via the screw terminals. This is set true for external sensors that are built to require a VCC-side reference resistor. |
Example:
void ALog::Wind_Vane_Inspeed | ( | uint8_t | vanePin | ) |
Wind vane: resistance changes with angle to wind.
vanePin | is the analog pin that reads the wind vane resistance |
This function is specialized for the Inspeed eVane2. Here, a resistance of 0 equates to wind from the north, and resistence increases in a clockwise direction.
Connect one wire to power supply, one wire to analog pin, one wire to GND
From documentation:
Example: