-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
178 lines (143 loc) · 3.59 KB
/
main.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <Arduino.h>
#include <wire.h>
#include "SD.h"
#include "Adafruit_BMP085.h"
#include "Adafruit_MPU6050.h"
#include "Adafruit_Sensor.h"
// #define startled
Adafruit_BMP085 bmp;
Adafruit_MPU6050 mpu;
#define buzzer 0;
#define red 4;
#define blue 9;
#define green 10;
#define pyro_channel_1 6;
#define pyro_channel_2 7;
const int chipSelect= 4;
// Adafruit_BMP085 Altitude ; setting default altitide to sea level
void setup() {
pinMode(4,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(0,OUTPUT);
digitalWrite(0,HIGH);
digitalWrite(0,LOW);
digitalWrite(0,HIGH);
digitalWrite(0,LOW);
Serial.begin(115200);
SD.begin(chipSelect);
while (!Serial)
{
delay(100);
}
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085/BMP180 sensor, check connections!");
while (1) {}
}
if (!mpu.begin())
{
Serial.println("failed to connect mpu");
while (1)
{
delay(100);
}
}
Serial.println("mpu found");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelorometer range set to: ");
switch (mpu.getAccelerometerRange())
{
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("gyro range set to:");
switch (mpu.getGyroRange())
{
case MPU6050_RANGE_250_DEG:
Serial.println("+-250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+-500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+-1000d deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_5_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
Serial.println("");
delay(100);
}
void loop() {
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
delay(100);
String dataString = "";
Serial.print("Pressure = ");
Serial.print(bmp.readPressure());
Serial.println(" Pa");
dataString+=String(bmp.readPressure());
Serial.print("altitude = ");
Serial.print(bmp.readAltitude());
Serial.println(" *m");
dataString+=String(bmp.readAltitude());
sensors_event_t a, g, temp; //mpu
mpu.getEvent(&a, &g , &temp);
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
dataString+=String(mpu.getAccelerometerRange());
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
dataString+=String(mpu.getGyroRange());
Serial.println("");
File datafile = SD.open("readings.txt",FILE_WRITE);
delay(500);
}