-
Notifications
You must be signed in to change notification settings - Fork 5
/
GY521_interrupt.ino
84 lines (57 loc) · 2.03 KB
/
GY521_interrupt.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
#include <MPU6050.h>
const uint8_t MPU_addr=0x68; // I2C address of the MPU-6050
MPU6050 testUnit(MPU_addr);
const byte interruptPin = D7;
const uint8_t threshold = 20;
const uint8_t duration = 10;
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("I'm Awake!");
Serial.print("Motion detect Status : "); Serial.println(testUnit.getMotionStatus(),BIN);
setupMotionInt();
testUnit.setInterruptLatch(0);
testUnit.setInterruptLatchClear(0);
testUnit.setInterruptDrive(0);
testUnit.setInterruptMode(1);
Serial.println(testUnit.getInterruptMode());
Serial.println(testUnit.getInterruptDrive());
Serial.println(testUnit.getInterruptLatch());
Serial.println(testUnit.getInterruptLatchClear());
Serial.println("Going to sleep. . .");
ESP.deepSleep(0);
}
void loop() {
}
void setupMotionInt(){
testUnit.initialize();
Serial.println(testUnit.testConnection());
// Ensure the accelerometer is running
testUnit.setSleepEnabled(false);
testUnit.setWakeCycleEnabled(false);
testUnit.setStandbyXAccelEnabled(false);
testUnit.setStandbyYAccelEnabled(false);
testUnit.setStandbyZAccelEnabled(false);
//Set the accelerometer HPF to reset settings
testUnit.setDHPFMode(MPU6050_DHPF_RESET);
//Set the accelerometer LPF to 256Hz Bandwidth
testUnit.setDLPFMode(MPU6050_DLPF_BW_256);
//Enable the motion interrupt
testUnit.setIntEnabled(0b00000000);
testUnit.setIntMotionEnabled(true);
//Set the motion detection duration
testUnit.setMotionDetectionDuration(duration); //Duration in ms
//Set the motion detection threshold
testUnit.setMotionDetectionThreshold(threshold); // Threshold in 2mg
//1 ms delay
delay(1);
//Set the accelerometer HPF to HOLD settings
testUnit.setDHPFMode(MPU6050_DHPF_HOLD);
// Set the wakeup frequency
testUnit.setWakeFrequency(MPU6050_WAKE_FREQ_5);
testUnit.setStandbyXGyroEnabled(true);
testUnit.setStandbyYGyroEnabled(true);
testUnit.setStandbyZGyroEnabled(true);
// Enable cycle mode
testUnit.setWakeCycleEnabled(true);
}