Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include "MAX30100_PulseOximeter.h"
- #include <TinyGPS++.h>
- #define REPORTING_PERIOD_MS 1000
- #define RXD2 16
- #define TXD2 17
- #define RXD1 4
- #define TXD1 2
- #define Btn 12
- #define LED 13
- PulseOximeter pox;
- TinyGPSPlus gps;
- char c;
- String dataIn;
- int8_t indexOfA, indexOfB;
- String data1, data2;
- String lonGPS = "";
- String latGPS = "";
- float oTemp;
- float BPM, SpO2;
- uint32_t tsLastReport = 0;
- const int MPU6050_addr = 0x68;
- int16_t AccX, AccY, AccZ, Temp, GyroX, GyroY, GyroZ;
- void setup()
- {
- Serial.begin(115200);
- Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
- Serial1.begin(9600, SERIAL_8N1, RXD1, TXD1);
- initHR_O2();
- initMPU6050();
- pinMode(Btn,INPUT);
- pinMode(LED,OUTPUT);
- digitalWrite(LED,LOW);
- }
- void loop() {
- pox.update();
- if(digitalRead(Btn)){
- digitalWrite(LED,HIGH);
- delay(500);
- digitalWrite(LED,LOW);
- }
- if (millis() - tsLastReport > REPORTING_PERIOD_MS)
- {
- //********************************************************************
- //------------------------Get and Show Temprature Data
- readNano_Data();
- //------------------------Get and Show GPS Data
- readGPS_Data();
- //------------------------Get and Show Motion Data
- readMPU6050();
- //------------------------Get and Show Heart and Oxygen Data
- readHR_O2();
- Serial.println("-------------------------------------");
- //********************************************************************
- tsLastReport = millis();
- }
- }//end of LOOP
- void initMPU6050() {
- Wire.begin();
- Wire.beginTransmission(MPU6050_addr);
- Wire.write(0x6B);
- Wire.write(0);
- Wire.endTransmission(true);
- }
- void initHR_O2() {
- Serial.print("Initializing Pulse Oximeter..");
- if (!pox.begin())
- {
- Serial.println("FAILED");
- for (;;);
- }
- else
- {
- Serial.println("SUCCESS");
- }
- // The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
- pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
- }
- void readHR_O2() {
- BPM = pox.getHeartRate();
- SpO2 = pox.getSpO2();
- Serial.print("Heart rate:");
- Serial.print(BPM);
- Serial.print(" bpm / SpO2:");
- Serial.print(SpO2);
- Serial.println(" %");
- }
- void readMPU6050() {
- Wire.beginTransmission(MPU6050_addr);
- Wire.write(0x3B);
- Wire.endTransmission(false);
- Wire.requestFrom(MPU6050_addr, 14, true);
- AccX = Wire.read() << 8 | Wire.read();
- AccY = Wire.read() << 8 | Wire.read();
- AccZ = Wire.read() << 8 | Wire.read();
- Temp = Wire.read() << 8 | Wire.read();
- GyroX = Wire.read() << 8 | Wire.read();
- GyroY = Wire.read() << 8 | Wire.read();
- GyroZ = Wire.read() << 8 | Wire.read();
- Serial.print(AccX);
- Serial.print("\t");
- Serial.print(AccY);
- Serial.print("\t");
- Serial.println(AccZ);
- Serial.print(GyroX);
- Serial.print("\t");
- Serial.print(GyroY);
- Serial.print("\t");
- Serial.println(GyroZ);
- }
- void displayGPSInfo()
- {
- Serial.print(F("Location: "));
- if (gps.location.isValid())
- {
- lonGPS = String(gps.location.lng(), 6);
- latGPS = String(gps.location.lat(), 6);
- Serial.print(latGPS);
- Serial.print(F(","));
- Serial.print(lonGPS);
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" Date/Time: "));
- if (gps.date.isValid())
- {
- Serial.print(gps.date.month());
- Serial.print(F("/"));
- Serial.print(gps.date.day());
- Serial.print(F("/"));
- Serial.print(gps.date.year());
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.print(F(" "));
- if (gps.time.isValid())
- {
- if (gps.time.hour()+3 < 10) Serial.print(F("0"));
- Serial.print(gps.time.hour()+3);
- Serial.print(F(":"));
- if (gps.time.minute() < 10) Serial.print(F("0"));
- Serial.print(gps.time.minute());
- Serial.print(F(":"));
- if (gps.time.second() < 10) Serial.print(F("0"));
- Serial.print(gps.time.second());
- Serial.print(F("."));
- if (gps.time.centisecond() < 10) Serial.print(F("0"));
- Serial.print(gps.time.centisecond());
- }
- else
- {
- Serial.print(F("INVALID"));
- }
- Serial.println();
- }
- void parseData() {
- indexOfA = dataIn.indexOf("A");
- indexOfB = dataIn.indexOf("B");
- data1 = dataIn.substring(0, indexOfA);
- data2 = dataIn.substring(indexOfA + 1, indexOfB);
- }
- void ShowRxData() {
- Serial.println("Object Temp: " + data1);
- Serial.println("Ambiant Temp: " + data2);
- }
- void resetData() {
- c = 0;
- dataIn = "";
- }
- void readGPS_Data() {
- // This sketch displays information every time a new sentence is correctly encoded.
- while (Serial2.available() > 0)
- if (gps.encode(Serial2.read()))
- displayGPSInfo();
- }
- void readNano_Data() {
- while (Serial1.available() > 0) {
- c = Serial1.read();
- if (c == '\n') {
- break;
- }
- else {
- dataIn += c;
- }
- }
- if (c == '\n') {
- parseData();
- ShowRxData();
- resetData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement