Skip to content

Commit 300f2b9

Browse files
First release of the library
- Developed basic functionality - Developed interrupt handling
1 parent 3052320 commit 300f2b9

File tree

12 files changed

+1449
-2
lines changed

12 files changed

+1449
-2
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1-
# D7S_Arduino_Library
2-
Arduino IDE library to use the D7S sensor
1+
# D7S Arduino Library
2+
3+
This library improve the use of the D7S sensor developed by Omron.
4+
5+
## Getting Started
6+
7+
Just download the lastest realease and place it your Arduino IDE library folder. See [https://www.arduino.cc/en/Guide/Libraries](https://www.arduino.cc/en/Guide/Libraries)
8+
9+
### Installing
10+
11+
The D7S sensor must be connected to the I2C bus.
12+
13+
On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5. On the Arduino Mega, SDA is digital pin 20 and SCL is 21. (See [https://www.arduino.cc/en/Guide/Libraries](https://www.arduino.cc/en/Reference/Wire))
14+
15+
## Authors
16+
17+
* **Alessandro Pasqualini** - [alessandro1105](https://github.com/alessandro1105)
18+
19+
## Contributors
20+
21+
This project has been developed with the contribution of [Futura Elettronica](http://www.futurashop.it), [Elettronica In](http://www.elettronicain.it), [Open Electronics](https://www.open-electronics.org).
22+
23+
## License
24+
25+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
Copyright 2017 Alessandro Pasqualini
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
13+
@author Alessandro Pasqualini <[email protected]>
14+
@url https://github.com/alessandro1105
15+
16+
This project has been developed with the contribution of Futura Elettronica.
17+
- http://www.futurashop.it
18+
- http://www.elettronicain.it
19+
- https://www.open-electronics.org
20+
*/
21+
22+
#include <D7S.h>
23+
24+
//old earthquake data
25+
float oldSI = 0;
26+
float oldPGA = 0;
27+
28+
//flag variables to handle collapse/shutoff only one time during an earthquake
29+
bool shutoffHandled = false;
30+
bool collapseHandled = false;
31+
32+
//function to handle shutoff event
33+
void handleShutoff() {
34+
//put here the code to handle the shutoff event
35+
Serial.println("-------------------- SHUTOFF! --------------------");
36+
Serial.println("Shutting down all device!");
37+
//stop all device
38+
while (1)
39+
;
40+
}
41+
42+
//function to handle collapse event
43+
void handleCollapse() {
44+
//put here the code to handle the collapse event
45+
Serial.println("-------------------- COLLAPSE! --------------------");
46+
}
47+
48+
49+
void setup() {
50+
// Open serial communications and wait for port to open:
51+
Serial.begin(9600);
52+
while (!Serial) {
53+
; // wait for serial port to connect. Needed for native USB port only
54+
}
55+
56+
//--- STARTING ---
57+
Serial.print("Starting D7S communications (it may take some time)...");
58+
//start D7S connection
59+
D7S.begin();
60+
//wait until the D7S is ready
61+
while (!D7S.isReady()) {
62+
Serial.print(".");
63+
delay(500);
64+
}
65+
Serial.println("STARTED");
66+
67+
//--- SETTINGS ---
68+
//setting the D7S to switch the axis at inizialization time
69+
Serial.println("Setting D7S sensor to switch axis at inizialization time.");
70+
D7S.setAxis(SWITCH_AT_INSTALLATION);
71+
72+
//--- INITIALIZZAZION ---
73+
Serial.println("Initializing the D7S sensor in 2 seconds. Please keep it steady during the initializing process.");
74+
delay(2000);
75+
Serial.print("Initializing...");
76+
//start the initial installation procedure
77+
D7S.initialize();
78+
//wait until the D7S is ready (the initializing process is ended)
79+
while (!D7S.isReady()) {
80+
Serial.print(".");
81+
delay(500);
82+
}
83+
Serial.println("INITIALIZED!");
84+
85+
//--- CHECKING FOR PREVIUS COLLAPSE ---
86+
//check if there there was a collapse (if this is the first time the D7S is put in place the installation data may be wrong)
87+
if (D7S.isInCollapse()) {
88+
handleCollapse();
89+
}
90+
91+
//--- RESETTING EVENTS ---
92+
//reset the events shutoff/collapse memorized into the D7S
93+
D7S.resetEvents();
94+
95+
//--- READY TO GO ---
96+
Serial.println("\nListening for earthquakes!");
97+
98+
}
99+
100+
void loop() {
101+
102+
//checking if there is an earthquake occuring right now
103+
if (D7S.isEarthquakeOccuring()) {
104+
105+
//check if the shutoff event has been handled and if the shutoff condition is met
106+
//the call of D7S.isInShutoff() is executed after to prevent useless I2C call
107+
if (!shutoffHandled && D7S.isInShutoff()) {
108+
handleShutoff();
109+
shutoffHandled = true;
110+
}
111+
112+
//check if the shutoff event has been handled and if the shutoff condition is met
113+
//the call of D7S.isInShutoff() is executed after to prevent useless I2C call
114+
if (!collapseHandled && D7S.isInCollapse()) {
115+
handleCollapse();
116+
collapseHandled = true;
117+
}
118+
119+
//print information about the current earthquake
120+
float currentSI = D7S.getInstantaneusSI();
121+
float currentPGA = D7S.getInstantaneusPGA();
122+
123+
if (currentSI > oldSI || currentPGA > oldPGA) {
124+
//getting instantaneus SI
125+
Serial.print("\tInstantaneus SI: ");
126+
Serial.print(currentSI);
127+
Serial.println(" [m/s]");
128+
129+
//getting instantaneus PGA
130+
Serial.print("\tInstantaneus PGA (Peak Ground Acceleration): ");
131+
Serial.print(currentPGA);
132+
Serial.println(" [m/s^2]\n");
133+
134+
//save the current data
135+
oldSI = currentSI;
136+
oldPGA = currentPGA;
137+
}
138+
139+
} else {
140+
//reset the old earthquake data
141+
oldPGA = 0;
142+
oldSI = 0;
143+
//reset the flag of the handled events
144+
shutoffHandled = false;
145+
collapseHandled = false;
146+
//reset D7S events
147+
D7S.resetEvents();
148+
}
149+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2017 Alessandro Pasqualini
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
13+
@author Alessandro Pasqualini <[email protected]>
14+
@url https://github.com/alessandro1105
15+
16+
This project has been developed with the contribution of Futura Elettronica.
17+
- http://www.futurashop.it
18+
- http://www.elettronicain.it
19+
- https://www.open-electronics.org
20+
*/
21+
22+
#include <D7S.h>
23+
24+
void setup() {
25+
// Open serial communications and wait for port to open:
26+
Serial.begin(9600);
27+
while (!Serial) {
28+
; // wait for serial port to connect. Needed for native USB port only
29+
}
30+
31+
//--- STARTING ---
32+
Serial.print("Starting D7S communications (it may take some time)...");
33+
//start D7S connection
34+
D7S.begin();
35+
Serial.println("STARTED\n");
36+
37+
//clearing earthquake measured data
38+
Serial.print("Clearing earthquake data...");
39+
D7S.clearEarthquakeData();
40+
Serial.println("CLEARED!\n");
41+
42+
//clearing installation data
43+
Serial.print("Clearing installation data...");
44+
D7S.clearInstallationData();
45+
Serial.println("CLEARED!\n");
46+
47+
//clearing lastest offset data
48+
Serial.print("Clearing lastest offset data...");
49+
D7S.clearLastestOffsetData();
50+
Serial.println("CLEARED!\n");
51+
52+
//clearing selftest data
53+
Serial.print("Clearing Earthquake data...");
54+
D7S.clearSelftestData();
55+
Serial.println("CLEARED!\n");
56+
57+
//clearing all data
58+
Serial.print("Clearing all data...");
59+
D7S.clearAllData();
60+
Serial.println("CLEARED!\n");
61+
62+
}
63+
64+
void loop() {
65+
// put your main code here, to run repeatedly:
66+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2017 Alessandro Pasqualini
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
13+
@author Alessandro Pasqualini <[email protected]>
14+
@url https://github.com/alessandro1105
15+
16+
This project has been developed with the contribution of Futura Elettronica.
17+
- http://www.futurashop.it
18+
- http://www.elettronicain.it
19+
- https://www.open-electronics.org
20+
*/
21+
22+
#include <D7S.h>
23+
24+
void setup() {
25+
// Open serial communications and wait for port to open:
26+
Serial.begin(9600);
27+
while (!Serial) {
28+
; // wait for serial port to connect. Needed for native USB port only
29+
}
30+
31+
//--- STARTING ---
32+
Serial.print("Starting D7S communications (it may take some time)...");
33+
//start D7S connection
34+
D7S.begin();
35+
//wait until the D7S is ready
36+
while (!D7S.isReady()) {
37+
Serial.print(".");
38+
delay(500);
39+
}
40+
Serial.println("STARTED\n");
41+
42+
//--- LASTEST DATA ---
43+
Serial.println("--- LASTEST EARTHQUAKES MEASURED ---\n");
44+
//print the lastest 5 earthquakes registered with all data
45+
for (int i = 0; i < 5; i++) { //the index must be from 0 to 4 (5 earthquakes total)
46+
Serial.print("Earthquake n. ");
47+
Serial.println(i+1);
48+
49+
//getting the lastest SI at index i
50+
Serial.print("\tSI: ");
51+
Serial.print(D7S.getLastestSI(i));
52+
Serial.println(" [m/s]");
53+
54+
//getting the lastest PGA at index i
55+
Serial.print("\tPGA (Peak Ground Acceleration): ");
56+
Serial.print(D7S.getLastestPGA(i));
57+
Serial.println(" [m/s^2]");
58+
59+
//getting the temperature at which the earthquake at index i has occured
60+
Serial.print("\tTemperature: ");
61+
Serial.print(D7S.getLastestTemperature(i));
62+
Serial.println(" [°C]\n");
63+
}
64+
}
65+
66+
void loop() {
67+
// put your main code here, to run repeatedly:
68+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright 2017 Alessandro Pasqualini
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
13+
@author Alessandro Pasqualini <[email protected]>
14+
@url https://github.com/alessandro1105
15+
16+
This project has been developed with the contribution of Futura Elettronica.
17+
- http://www.futurashop.it
18+
- http://www.elettronicain.it
19+
- https://www.open-electronics.org
20+
*/
21+
22+
#include <D7S.h>
23+
24+
void setup() {
25+
// Open serial communications and wait for port to open:
26+
Serial.begin(9600);
27+
while (!Serial) {
28+
; // wait for serial port to connect. Needed for native USB port only
29+
}
30+
31+
//--- STARTING ---
32+
Serial.print("Starting D7S communications (it may take some time)...");
33+
//start D7S connection
34+
D7S.begin();
35+
//wait until the D7S is ready
36+
while (!D7S.isReady()) {
37+
Serial.print(".");
38+
delay(500);
39+
}
40+
Serial.println("STARTED\n");
41+
42+
//--- LASTEST DATA ---
43+
Serial.println("--- RANKED EARTHQUAKES BY SI ---\n");
44+
//print the 5 greatest earthquakes registered with all data
45+
for (int i = 0; i < 5; i++) { //the index must be from 0 to 4 (5 earthquakes in total)
46+
Serial.print("Earthquake in postion ");
47+
Serial.println(i+1);
48+
49+
//getting the ranked SI at position i
50+
Serial.print("\tSI: ");
51+
Serial.print(D7S.getRankedSI(i));
52+
Serial.println(" [m/s]");
53+
54+
//getting the ranked PGA at position i
55+
Serial.print("\tPGA (Peak Ground Acceleration): ");
56+
Serial.print(D7S.getRankedPGA(i));
57+
Serial.println(" [m/s^2]");
58+
59+
//getting the temperature at which the earthquake at position i has occured
60+
Serial.print("\tTemperature: ");
61+
Serial.print(D7S.getRankedTemperature(i));
62+
Serial.println(" [°C]\n");
63+
}
64+
}
65+
66+
void loop() {
67+
// put your main code here, to run repeatedly:
68+
}

0 commit comments

Comments
 (0)