ALog  v0.3.2
Open-source Arduino-based data logger library, designed for field science
ALog.h
Go to the documentation of this file.
1 
45 // DEFINE SELF / INCLUDE GUARD //
48 
49 #ifndef ALog_h
50 #define ALog_h
51 
53 // INCLUDE LIBRARIES //
55 
56 // Arduino 1.0 libraries now default; no if/else
57 #include <Arduino.h>
58 
59 // Standard libraries
60 #include <SdFat.h>
61 #include <Wire.h>
62 #include <DS3231.h>
63 #include <math.h>
64 #include <avr/sleep.h>
65 #include <avr/wdt.h>
66 #include <stdlib.h> // For turning incoming ASCII character
67  // strings into int with atol
68 #include <EEPROM.h> // Save serial number and reference voltage
69  // Serial number cannot be written here
70  // (This is for the program to configure each logger)
71 #include <SoftwareSerial.h>
72 #include <EEPROM.h>
73 
74 // Sensor-centric libraries
75 #include <SFE_BMP180.h>
76 //#include <Adafruit_Sensor.h>
77 //#include <Adafruit_BMP085_U.h>
78 //#include <eRCaGuy_NewAnalogRead.h>
79 //#include <AtlasNW.h>
80 
81 // Outside of class definitions
82 void wakeUpNow();
83 void wakeUpNow_tip();
84 void _ISR_void();
85 void _anemometer_count_increment();
86 void _internalDateTime(uint16_t* date, uint16_t* time); // Callback: SD DT stamp
87 
88 // The rest of the library
89 class ALog {
90 
91  public:
92  // Constructor
93  ALog();
94 
95  // Initialization
96  void initialize(char* _logger_name, char* _datafilename, \
97  int _hourInterval, int _minInterval, int _secInterval, \
98  bool _ext_int=false, bool _LOG_ALL_SENSORS_ON_BUCKET_TIP=false);
99  void setupLogger();
100 
101  // Code for sleeping, starting up from sleep, synching SD card
102  void sleep();
103  void goToSleep_if_needed(); // Same as above, but checks if sleep is being used
104  void startLogging();
105  void endLogging();
106  void startAnalog(); // DEPRECATED
107  void endAnalog(); // DEPRECATED
108  void sensorPowerOn();
109  void sensorPowerOff();
110 
111  // Getters and setters
112  bool get_use_sleep_mode();
113  void set_LEDpin(int8_t _pin);
114  void set_SDpowerPin(int8_t _pin);
115  void set_RTCpowerPin(int8_t _pin);
116  void set_SensorPowerPin(int8_t _pin);
117  // Important subset: EEPROM: Serial number and calibrations
118  uint16_t get_serial_number();
119  float get_3V3_measured_voltage();
120  float get_5V_measured_voltage();
121 
122  // Sensors - standard procedure (wake up, log, sleep)
123  float readPin(uint8_t pin);
124  float readPinOversample(uint8_t pin, uint8_t adc_bits);
125  float analogReadOversample(uint8_t pin, uint8_t adc_bits=10, \
126  uint8_t nsamples=1, bool debug=false);
127  float thermistorB(float R0, float B, float Rref, float T0degC, \
128  uint8_t thermPin, uint8_t ADC_resolution_nbits=14, \
129  bool Rref_on_GND_side=true, bool oversample_debug=false, \
130  bool record_results=true);
131  // Print order: Distance [cm], standard deviation [cm]
132  void ultrasonicMB_analog_1cm(uint8_t nping, uint8_t EX, uint8_t sonicPin, \
133  bool writeAll);
134  float maxbotixHRXL_WR_Serial(uint8_t Ex, uint8_t npings, bool writeAll, \
135  int maxRange, bool RS232=false);
136  // Print order: Distance [cm], standard deviation [cm]
137  void maxbotixHRXL_WR_analog(uint8_t nping=10, uint8_t sonicPin=A0,
138  uint8_t EX=99, bool writeAll=true, uint8_t ADC_resolution_nbits=10);
139  void Decagon5TE(uint8_t excitPin, uint8_t dataPin); // Poorly-tested
140  void DecagonGS1(uint8_t pin, float Vref, uint8_t ADC_resolution_nbits=14);
141  void vdivR(uint8_t pin, float Rref, uint8_t ADC_resolution_nbits=10, \
142  bool Rref_on_GND_side=true);
143  // FLEX SENSOR READING DOES NOT STABLIIZE: CHANGES CONSISTENTLY WITH TIME.
144  //void flex(int flexPin, float Rref, float calib1, float calib2);
145  void linearPotentiometer(uint8_t linpotPin, float Rref, float slope, \
146  char* _distance_units, float intercept=0, \
147  uint8_t ADC_resolution_nbits=14, bool Rref_on_GND_side=true);
148  void HTM2500LF_humidity_temperature(uint8_t humidPin, uint8_t thermPin, \
149  float Rref_therm, uint8_t ADC_resolution_nbits=14);
150  void HM1500LF_humidity_with_external_temperature(uint8_t humidPin, \
151  float R0_therm, float B_therm, float Rref_therm, float T0degC_therm, \
152  uint8_t thermPin_therm, uint8_t ADC_resolution_nbits=14);
153  void Inclinometer_SCA100T_D02_analog_Tcorr(uint8_t xPin, uint8_t yPin, \
154  float Vref, float Vsupply, float R0_therm, float B_therm, \
155  float Rref_therm, float T0degC_therm, uint8_t thermPin_therm, \
156  uint8_t ADC_resolution_nbits=14);
157  void Anemometer_reed_switch(uint8_t interrupt_pin_number,
158  unsigned long reading_duration_milliseconds, \
159  float meters_per_second_per_rotation);
160  void Wind_Vane_Inspeed(uint8_t vanePin);
161  void Pyranometer(uint8_t analogPin, float raw_mV_per_W_per_m2, \
162  float gain, float V_ref, uint8_t ADC_resolution_nbits=14);
163  void Barometer_BMP180();
164  void _sensor_function_template(uint8_t pin, float param1, \
165  float param2, uint8_t ADC_bits=14, bool flag=false);
166 
167  // Sensors - triggered
168  // Camera on/off function; decision made in end-user Arduino script
169  void HackHD(int control_pin, bool want_camera_on);
170  float Honeywell_HSC_analog(int pin, float Vsupply, float Vref, \
171  float Pmin, float Pmax, int TransferFunction_number, int units, \
172  uint8_t ADC_resolution_nbits=14);
173 
174  private:
175  void pinUnavailable(uint8_t pin);
176  char *nameFile(char * _sitecode);
177 
178  // Sleep and alarms
179  void sleepNow();
180  void sleepNow_nap();
181  // wakeUpNow defined outside of class; see above
182  void alarm(uint8_t hourInterval, uint8_t minInterval, \
183  uint8_t secInterval);
184  void displayAlarms(); //debug tool delete if desired.
185  void checkAlarms(); //debug tool delete if desired.
186  void displayTime(); //debug tool delete if desired.
187  // LED signals
188  void LEDwarn(uint8_t nflash);
189  void LEDgood();
190  void LEDtimeWrong(uint8_t ncycles);
191 
192  // Time
193  void unixDatestamp();
194 
195  // Logger-computer communications
196  void name();
197  void print_time();
198  void set_time_main();
199  void announce_start();
200  void startup_sequence();
201  void establishContact_Tx();
202  bool establishContact_Rx();
203 
204  // Clock and SD card power
205  void SDon_RTCon();
206  void SDoff_RTCsleep();
207 
208  // Clock setting
209  void clockSet();
210  void GetDateStuff(byte& Year, byte& Month, byte& Day, byte& DoW,
211  byte& Hour, byte& Minute, byte& Second);
212 
213  // Sensor utility codes
214  float _vdivR(uint8_t pin, float Rref, uint8_t adc_bits=10, \
215  bool Rref_on_GND_side=true, bool oversample_debug=false);
216  // I don't trust the software serial version -- should do some lab testing
217  // to make sure that chances of clock speed / interrupt problems,
218  // especially with so much time in sleep mode, are near-0.
219  //int maxbotix_soft_Serial_parse(int Ex, int Rx, bool RS232=false);
220  int maxbotix_Serial_parse(uint8_t Ex);
221  float standard_deviation_from_array(float values[], int nvalues, \
222  float mean);
223  float standard_deviation_from_array(int values[], int nvalues, float mean);
224 
225  // Special sensor codes
226  // Rain gauge - will wake logger up and cause it to log to a different file
227  // The default interrupt is Pin 3, INT1 on ATmega328 (ALog BottleLogger).
228  // This runs of bool _ext_int = true in loger.initialize()
229  void TippingBucketRainGage();
230 
231  // Logging
232  void start_logging_to_datafile();
233  void start_logging_to_otherfile(char* filename);
234  void end_logging_to_otherfile();
235  void start_logging_to_headerfile();
236  void end_logging_to_headerfile();
237  void endLine();
238 
239 };
240 
241 // End include guard
242 #endif
void Decagon5TE(uint8_t excitPin, uint8_t dataPin)
Definition: ALog.cpp:3149
float get_5V_measured_voltage()
Definition: ALog.cpp:644
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)
Definition: ALog.cpp:253
ALog()
ALog library for the Arduino-based data loggers.
Definition: ALog.cpp:251
float analogReadOversample(uint8_t pin, uint8_t adc_bits=10, uint8_t nsamples=1, bool debug=false)
Definition: ALog.cpp:2633
void set_SensorPowerPin(int8_t _pin)
Definition: ALog.cpp:599
void Wind_Vane_Inspeed(uint8_t vanePin)
Definition: ALog.cpp:2527
void vdivR(uint8_t pin, float Rref, uint8_t ADC_resolution_nbits=10, bool Rref_on_GND_side=true)
Definition: ALog.cpp:3483
float readPinOversample(uint8_t pin, uint8_t adc_bits)
Definition: ALog.cpp:1486
void HackHD(int control_pin, bool want_camera_on)
Definition: ALog.cpp:2912
void setupLogger()
Definition: ALog.cpp:392
void endLogging()
Definition: ALog.cpp:1310
void Pyranometer(uint8_t analogPin, float raw_mV_per_W_per_m2, float gain, float V_ref, uint8_t ADC_resolution_nbits=14)
Definition: ALog.cpp:2571
void startLogging()
Definition: ALog.cpp:1228
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)
Definition: ALog.cpp:1544
void sensorPowerOff()
Definition: ALog.cpp:1402
void Anemometer_reed_switch(uint8_t interrupt_pin_number, unsigned long reading_duration_milliseconds, float meters_per_second_per_rotation)
Definition: ALog.cpp:2429
void endAnalog()
Definition: ALog.cpp:1425
bool get_use_sleep_mode()
Definition: ALog.cpp:549
float readPin(uint8_t pin)
Definition: ALog.cpp:1443
void set_LEDpin(int8_t _pin)
Definition: ALog.cpp:562
void _sensor_function_template(uint8_t pin, float param1, float param2, uint8_t ADC_bits=14, bool flag=false)
Definition: ALog.cpp:2821
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)
Definition: ALog.cpp:3374
void goToSleep_if_needed()
Definition: ALog.cpp:1214
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)
Definition: ALog.cpp:3541
float maxbotixHRXL_WR_Serial(uint8_t Ex, uint8_t npings, bool writeAll, int maxRange, bool RS232=false)
Definition: ALog.cpp:2095
Definition: ALog.h:89
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)
Definition: ALog.cpp:1965
void sleep()
Definition: ALog.cpp:1198
void Barometer_BMP180()
Definition: ALog.cpp:2729
void set_RTCpowerPin(int8_t _pin)
Definition: ALog.cpp:585
void HTM2500LF_humidity_temperature(uint8_t humidPin, uint8_t thermPin, float Rref_therm, uint8_t ADC_resolution_nbits=14)
Definition: ALog.cpp:1646
void ultrasonicMB_analog_1cm(uint8_t nping, uint8_t EX, uint8_t sonicPin, bool writeAll)
Definition: ALog.cpp:1841
float get_3V3_measured_voltage()
Definition: ALog.cpp:631
uint16_t get_serial_number()
Definition: ALog.cpp:619
void startAnalog()
Definition: ALog.cpp:1413
void set_SDpowerPin(int8_t _pin)
Definition: ALog.cpp:572
void DecagonGS1(uint8_t pin, float Vref, uint8_t ADC_resolution_nbits=14)
Definition: ALog.cpp:3311
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)
Definition: ALog.cpp:2312
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)
Definition: ALog.cpp:1743
void sensorPowerOn()
Definition: ALog.cpp:1392