Alora Library
Library for using Alora shield
 All Classes Namespaces Files Functions Variables Macros Pages
AloraSensorKit.h
Go to the documentation of this file.
1 
8 #ifndef ALORA_ALORASENSORKIT_H
9 #define ALORA_ALORASENSORKIT_H
10 
11 #include <Wire.h>
12 #include <Arduino.h>
13 #include <Adafruit_Sensor.h>
14 #include <Adafruit_BME280.h>
15 #include <ClosedCube_HDC1080.h>
16 #include <NMEAGPS.h>
17 #include <Streamers.h>
18 #include "Adafruit_TSL2591.h"
19 #include <SparkFunCCS811.h>
20 
21 #include "GpioExpander.h"
22 
23 #include <RTClib.h>
24 #undef SECONDS_PER_DAY
25 
26 #include "AllAboutEE_MAX11609.h"
27 using namespace AllAboutEE;
28 
29 #include "AloraIMULSM9DS1Adapter.h"
30 
32 #if !defined(ALORA_IMU_SENSOR)
33  #define ALORA_IMU_SENSOR AloraIMULSM9DS1Adapter
34 #endif
35 
37 #if !defined(ALORA_SENSOR_USE_CCS811)
38  #define ALORA_SENSOR_USE_CCS811 1
39 #endif
40 
42 #if !defined(ALORA_SENSOR_QUERY_INTERVAL)
43  #define ALORA_SENSOR_QUERY_INTERVAL 300
44 #endif
45 
47 #if !defined(ALORA_USE_MAX11609)
48  #define ALORA_USE_MAX11609 1
49 #endif
50 
52 #if !defined(ALORA_USE_AIR_QUALITY_GAS_SENSOR)
53  #define ALORA_USE_AIR_QUALITY_GAS_SENSOR 1
54 #endif
55 
57 #if !defined(ALORA_USE_IMU_SENSOR)
58  #define ALORA_USE_IMU_SENSOR 1
59 #endif
60 
62 #if !defined(ALORA_USE_GPIO_EXPANDER)
63  #define ALORA_USE_GPIO_EXPANDER 1
64 #endif
65 
67 #if !defined(ALORA_USE_HDC1080_SENSOR)
68  #define ALORA_USE_HDC1080_SENSOR 1
69 #endif
70 
72 #if !defined(ALORA_USE_BME280_SENSOR)
73  #define ALORA_USE_BME280_SENSOR 1
74 #endif
75 
77 #if !defined(ALORA_USE_TSL2591_SENSOR)
78  #define ALORA_USE_TSL2591_SENSOR 1
79 #endif
80 
82 #define ALORA_HDC1080_ADDRESS 0x40
83 
85 #define ALORA_I2C_ADDRESS_CCS811 0x5A
86 
88 #if ALORA_IMU_SENSOR == ALORA_IMU_SENSOR_LSM9DS1
89  #define ALORA_I2C_ADDRESS_IMU_M 0x1E
90 #elif ALORA_IMU_SENSOR == ALORA_IMU_SENSOR_LSM303AGR
91  #define ALORA_I2C_ADDRESS_IMU_M 0x3C
92 #endif
93 
95 #if ALORA_IMU_SENSOR == ALORA_IMU_SENSOR_LSM9DS1
96  #define ALORA_I2C_ADDRESS_IMU_AG 0x6B
97 #elif ALORA_IMU_SENSOR == ALORA_IMU_SENSOR_LSM303AGR
98  #define ALORA_I2C_ADDRESS_IMU_AG 0x32
99 #endif
100 
102 #if !defined(ALORA_MAGNETIC_SENSOR_PIN)
103  #define ALORA_MAGNETIC_SENSOR_PIN 35
104 #endif
105 
107 #if !defined(ALORA_ADC_GAS_HEATER_PIN)
108  #define ALORA_ADC_GAS_HEATER_PIN 13
109 #endif
110 
112 #if !defined(ALORA_ADC_GAS_CHANNEL)
113  #define ALORA_ADC_GAS_CHANNEL 1
114 #endif
115 
117 #if !defined(ALORA_GPS_ENABLE_PIN)
118  #define ALORA_GPS_ENABLE_PIN 12
119 #endif
120 
124 struct SensorValues {
125  float T1;
126  float P;
127  float H1;
128  float T2;
129  float H2;
130  double lux;
131  uint16_t gas;
132  uint16_t co2;
133  float accelX;
134  float accelY;
135  float accelZ;
136  float gyroX;
137  float gyroY;
138  float gyroZ;
139  float magX;
140  float magY;
141  float magZ;
142  float magHeading;
143  int magnetic;
144  float windSpeed;
145  gps_fix gpsFix;
146 };
147 
148 
156 public:
157  AloraSensorKit(uint8_t enablePin = 16, uint8_t activeLogic = HIGH);
158  ~AloraSensorKit();
159 
160  void begin();
161  void run();
162  void turnOff();
163  void turnOn();
164  void scanAndPrintI2C(Print& print);
165  void printSensingTo(Print& print);
166  void printSensingTo(String& str);
167  uint16_t readADC(uint8_t channel);
168  DateTime getDateTime();
169  SensorValues& getLastSensorData();
170  void initGPS(Stream* gpsStream);
171  NMEAGPS* getGPSObject();
172  GpioExpander* getIOExpander();
173  ALORA_IMU_SENSOR* getIMUSensorAdapter();
174  void setCCS811WakeLogic(uint8_t wakeLogic = LOW);
175 
176 private:
177  uint8_t enablePin;
180  NMEAGPS* gps = NULL;
181  Stream* gpsStream = NULL;
182  Adafruit_BME280* bme280 = NULL;
183  ClosedCube_HDC1080* hdc1080 = NULL;
184  Adafruit_TSL2591* tsl2591 = NULL;
185  CCS811* ccs811 = NULL;
186  ALORA_IMU_SENSOR* imuSensor = NULL;
187  GpioExpander* ioExpander = NULL;
188  MAX11609* max11609 = NULL;
189  RTC_DS3231* rtc = NULL;
192  uint32_t lastSensorQuerryMs = 0;
194  uint8_t ccs811WakeLogic;
196  void doAllSensing();
197  void readBME280(float& T, float& P, float& H);
198  void readHDC1080(float& T, float& H);
199  void readTSL2591(double& lux);
200  void configureTSL2591Sensor();
201  void readGas(uint16_t& gas, uint16_t& co2);
202  void readAccelerometer(float &ax, float &ay, float &az);
203  void readMagnetometer(float &mx, float &my, float &mz, float &mH);
204  void readGyro(float &gx, float &gy, float &gz);
205  void readMagneticSensor(int& mag);
206  void readWindSpeed(float& windspeed);
207  void readGPS(gps_fix& fix);
208 };
209 
210 #endif
float magZ
Definition: AloraSensorKit.h:141
float accelZ
Definition: AloraSensorKit.h:135
float gyroY
Definition: AloraSensorKit.h:137
float T2
Definition: AloraSensorKit.h:128
Definition: AloraSensorKit.h:155
float gyroZ
Definition: AloraSensorKit.h:138
Definition: Adafruit_TSL2591.h:120
float P
Definition: AloraSensorKit.h:126
gps_fix gpsFix
Definition: AloraSensorKit.h:145
Definition: AllAboutEE_MAX11609.h:12
Definition: GpioExpander.h:36
float magY
Definition: AloraSensorKit.h:140
uint8_t enablePin
Definition: AloraSensorKit.h:177
float accelY
Definition: AloraSensorKit.h:134
#define ALORA_IMU_SENSOR
Definition: AloraSensorKit.h:33
uint8_t enablePinActiveLogic
Definition: AloraSensorKit.h:178
float accelX
Definition: AloraSensorKit.h:133
Definition: AloraSensorKit.h:124
uint16_t gas
Definition: AloraSensorKit.h:131
uint8_t ccs811WakeLogic
Definition: AloraSensorKit.h:194
uint16_t co2
Definition: AloraSensorKit.h:132
float H2
Definition: AloraSensorKit.h:129
float T1
Definition: AloraSensorKit.h:125
SensorValues lastSensorData
Definition: AloraSensorKit.h:191
float windSpeed
Definition: AloraSensorKit.h:144
int magnetic
Definition: AloraSensorKit.h:143
float H1
Definition: AloraSensorKit.h:127
float magX
Definition: AloraSensorKit.h:139
double lux
Definition: AloraSensorKit.h:130
float magHeading
Definition: AloraSensorKit.h:142
float gyroX
Definition: AloraSensorKit.h:136