This repository has been archived by the owner on Oct 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SensorSquad.ino
114 lines (100 loc) · 3.02 KB
/
SensorSquad.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
#include <SparkFunLSM9DS1.h>
#include <SparkFunCCS811.h>
#define CCS811_ADDR 0x5B //Default I2C Address
Adafruit_BMP280 bme;
LSM9DS1 imu;
CCS811 mySensor(CCS811_ADDR);
int geiger_input = 2;
int count = 0;
void setup() {
Serial.begin(9600);
Serial.println("SENSOR SQUAD: time ax ay az mx my mz gx gy gz temp pressure humidity co2 voc geigercount");
if (!bme.begin()) {
Serial.println("Failed to communicate with BMP280");
//while (1);
}
imu.settings.device.commInterface = IMU_MODE_I2C;
if (!imu.begin())
{
Serial.println("Failed to communicate with LSM9DS1");
//while (1);
}
CCS811Core::status returnCode = mySensor.begin();
switch ( returnCode )
{
case CCS811Core::SENSOR_ID_ERROR:
Serial.println("CCS811 beginCore exited with: ID_ERROR");
break;
case CCS811Core::SENSOR_I2C_ERROR:
Serial.println("CCS811 beginCore exited with: I2C_ERROR");
break;
case CCS811Core::SENSOR_INTERNAL_ERROR:
Serial.println("CCS811 beginCore exited with: INTERNAL_ERROR");
break;
case CCS811Core::SENSOR_GENERIC_ERROR:
Serial.println("CCS811 beginCore exited with: GENERIC_ERROR");
break;
}
pinMode(geiger_input, INPUT);
digitalWrite(geiger_input,HIGH);
attachInterrupt(digitalPinToInterrupt(geiger_input), countPulse, FALLING);
}
void loop() {
float temperature = bme.readTemperature();
int pressure = bme.readPressure();
int humidity = analogRead(A1); // in range from 0 to 1023
int co2 = 0;
int voc = 0;
if (mySensor.dataAvailable())
{
mySensor.readAlgorithmResults();
co2 = mySensor.getCO2();
voc = mySensor.getTVOC();
}
imu.readAccel();
imu.readMag();
imu.readGyro();
Serial.print(millis());
Serial.print(", ");
Serial.print(imu.ax); // Print x-axis data
Serial.print(", ");
Serial.print(imu.ay); // print y-axis data
Serial.print(", ");
Serial.print(imu.az); // print z-axis data
Serial.print(", ");
Serial.print(imu.mx); // Print x-axis data
Serial.print(", ");
Serial.print(imu.my); // print y-axis data
Serial.print(", ");
Serial.print(imu.mz); // print z-axis data
Serial.print(", ");
Serial.print(imu.gx); // Print x-axis data
Serial.print(", ");
Serial.print(imu.gy); // print y-axis data
Serial.print(", ");
Serial.print(imu.gz); // print z-axis data
Serial.print(", ");
Serial.print(temperature);
Serial.print(", ");
Serial.print(pressure);
Serial.print(", ");
Serial.print(humidity);
Serial.print(", ");
Serial.print(co2);
Serial.print(", ");
Serial.print(voc);
Serial.print(", ");
Serial.print(count);
Serial.println();
delay(2000);
}
void countPulse(){
detachInterrupt(digitalPinToInterrupt(geiger_input));
count++;
while(digitalRead(geiger_input)==0){
}
attachInterrupt(0,countPulse,FALLING);
}