espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
12.99k stars 7.29k forks source link

Smart watch band for Heart Rate and GPS via Lora sending #2274

Closed rayhong77 closed 4 years ago

rayhong77 commented 5 years ago

Hardware:

Board: ESP LoRa32 TTGO 3pcs Core Installation/update date: 2/JAN/2019 IDE name: Arduino IDE with espressif Flash Frequency: ?40Mhz? PSRAM enabled: YES Upload Speed: 115200 Computer OS: Windows 10

Description:

Hello, I am such a newbie of these arduino things.

It's TTGO ESP32 LoRa Board, I connected Max30010 to 21,22 PINs and will connect Neo-6m GPS to 16,17 PINs.

Before GPS connection, I tried Heart Rate sensor works first and it works standalone with max30100 library. However, as my code as below, i mixed serveral codes for working together. They would conflict each pox.begin(HR sensor) with others. Maybe SPI and U8g2 When screen and LoRa work well, the heart rate sensor can't read the value(IR LED is okay). I used libarary includes file without modifying.

I am stuck for this problem. please advice me. This is so important project for me. i worry about GPS connection too.

Sketch: (leave the backquotes for code formatting)


//Change the code below by your sketch
[CODE]

#include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
//#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
#include "MAX30100_PulseOximeter.h"
#include <SPI.h>
#include <LoRa.h>
#include <Arduino.h>
#include <U8g2lib.h>  //U8g2 
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, 16, 15, 4);

// company logo for first step
static const unsigned char company_logo[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0xfc,0x00,0x7f,0xc0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0xff,0x01,0xff,0xe0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0xff,0x83,0xff,0xf0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0xff,0xc3,0xff,0xf8,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x9f,0xc7,0xe1,0xf8,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x07,0xe7,0xc0,0xf8,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x03,0xe7,0x80,0x7c,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x03,0xe7,0x80,0x7c,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x03,0xe7,0x80,0x7c,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x03,0xe7,0x80,0x7c,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x07,0xe7,0xc0,0xf8,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x1f,0xc7,0xe1,0xf8,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x7f,0xc3,0xff,0xf8,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x7f,0x83,0xff,0xf0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x7f,0x01,0xff,0xe0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x0f,0x7c,0x00,0x7f,0xc0,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0x00
,0xfe,0x1f,0x9f,0xe7,0xf3,0xf8,0x61,0x80,0xcf,0x8f,0xc7,0xff,0xf0
,0xff,0x3f,0xd0,0x24,0x0a,0x00,0x61,0x80,0xdd,0xcf,0xe7,0xff,0xf0
,0xe7,0xb9,0xd0,0x14,0x0a,0x00,0x91,0x41,0x5c,0x1c,0x77,0x03,0x80
,0xe3,0xf0,0xd0,0x14,0x1a,0x00,0x91,0x41,0x5f,0x9c,0x77,0xe1,0x80
,0xe3,0xf0,0xf0,0x17,0xf3,0xf9,0x09,0x22,0x4f,0xdc,0x77,0xe1,0x80
,0xe3,0xf0,0xd0,0x14,0x1a,0x01,0xf9,0x22,0x41,0xfc,0x77,0x01,0x80
,0xef,0x39,0xd0,0x34,0x0a,0x02,0x05,0x14,0x78,0xfe,0xf7,0x01,0x80
,0xff,0x3f,0x90,0x24,0x0a,0x02,0x05,0x1c,0x5f,0xcf,0xe7,0x01,0x80
,0xfc,0x0f,0x0f,0xc4,0x0b,0xfc,0x03,0x08,0x4f,0x87,0xc6,0x01,0x80
};

//battery on charge?
static const unsigned char battery_charging_data[] PROGMEM = {
0x7f,0xff,0xc0
,0x9e,0x0f,0x60
,0xbf,0xff,0xc0
,0xbf,0xbf,0xa0
,0xf3,0x8f,0xb0
,0xf8,0x03,0xb0
,0xfe,0x39,0xb0
,0xff,0xff,0xa0
,0xbf,0xff,0xc0
,0x9f,0xff,0x60
,0x7f,0xff,0xc0
};
//battery Low image
static const unsigned char battery_low_data[] PROGMEM = {
0x7f,0xff,0xc0
,0x9c,0x00,0x60
,0xbe,0x00,0x20
,0xfe,0x00,0x20
,0xfe,0x00,0x30
,0xbe,0x00,0x30
,0xbe,0x00,0x30
,0xfe,0x00,0x20
,0xbe,0x00,0x20
,0xbc,0x00,0x60
,0x7f,0xff,0xc0
};

//battery half image
static const unsigned char battery_half_data[] PROGMEM = {
0x7f,0xff,0xc0
,0xdf,0xf0,0x60
,0xbf,0xf0,0x20
,0xbf,0xf0,0x20
,0xbf,0xf0,0x30
,0xbf,0xf0,0x30
,0xff,0xf0,0x30
,0xff,0xf0,0x20
,0xbf,0xf0,0x20
,0xdf,0xf0,0x60
,0x7f,0xff,0xc0
};

//battery Full image
static const unsigned char battery_full_data[] PROGMEM = {
0x7f,0xff,0xc0
,0xdf,0xff,0x60
,0xbf,0xff,0xe0
,0xbf,0xff,0xe0
,0xff,0xff,0xb0
,0xff,0xff,0xb0
,0xff,0xff,0xb0
,0xff,0xff,0xe0
,0xbf,0xff,0xe0
,0xdf,0xff,0x60
,0x7f,0xff,0xc0
};

//LoRa icon
static const unsigned char lora_data[] PROGMEM = {
0x07,0xf0,0x00,0x00
,0x0c,0x18,0x00,0x00
,0x00,0x20,0x00,0x00
,0xc0,0x07,0xc0,0x00
,0xc0,0x0e,0xe0,0x00
,0xc1,0xc4,0x6f,0x80
,0xc2,0x67,0xc1,0x80
,0xc6,0x27,0xc7,0x80
,0xc2,0x64,0xcd,0x80
,0xf9,0xc4,0x6f,0x80
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x20,0x00,0x00
,0x0c,0x18,0x00,0x00
,0x07,0xf0,0x00,0x00
};

//GPS icon
static const unsigned char gps_data[] PROGMEM = {
0x07,0x80
,0x0f,0xe0
,0x1f,0xf0
,0x3c,0x70
,0x38,0x78
,0x78,0x38
,0x38,0x78
,0x3c,0xf0
,0x1f,0xf0
,0x1f,0xe0
,0x0f,0xe0
,0x0f,0xc0
,0x07,0x80
,0x03,0x80
,0x01,0x00
};

//Heart icon
static const unsigned char heart_data[] PROGMEM = {
0x18,0x30
,0x7c,0x7c
,0xfe,0xfe
,0xff,0xfe
,0xff,0xfe
,0xff,0xfe
,0x7f,0xfc
,0x7f,0xfc
,0x3f,0xf8
,0x1f,0xf0
,0x1f,0xf0
,0x0f,0xe0
,0x07,0xc0
,0x03,0x80
,0x00,0x00
};

//OLED pins to ESP32 GPIOs via this connecthin:
//OLED_SDA — GPIO4
//OLED_SCL — GPIO15
//OLED_RST — GPIO16

//SSD1306 display(0x3c, 4, 15);

// WIFI_LoRa_32 ports

// GPIO5 — SX1278’s SCK
// GPIO19 — SX1278’s MISO
// GPIO27 — SX1278’s MOSI
// GPIO18 — SX1278’s CS
// GPIO14 — SX1278’s RESET
// GPIO26 — SX1278’s IRQ(Interrupt Request)

#define SS 18
#define RST 14
#define DI0 26
// #define BAND 429E6 //915E6

// #define BAND 434500000.00
#define BAND 915E6

#define spreadingFactor 9
// #define SignalBandwidth 62.5E3
#define SignalBandwidth 31.25E3
#define preambleLength 8
#define codingRateDenominator 8
#define REPORTING_PERIOD_MS     1000
PulseOximeter pox;

uint32_t tsLastReport = 0;

String lat_x = "127.1122547"; //Temp variable value for Neo-6m Latitude
String lat_y = "35.1225631"; //Temp variable value for Neo-6m Longitude
String band_sn = "DO3478-16695" ;  // Serial Number of Product

void onBeatDetected()
{
    Serial.println("Beat!");
}

void setup() {
  pinMode(25,OUTPUT); //Send success, LED will bright 1 second  
  pinMode(16,OUTPUT);
  digitalWrite(16, LOW); // set GPIO16 low to reset OLED
  delay(50);
  digitalWrite(16, HIGH);

    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
  pox.setOnBeatDetectedCallback(onBeatDetected);

  u8g2.begin();
  Serial.begin(115200);
  while (!Serial); //If just the the basic function, must connect to a computer 
  SPI.begin(5,19,27,18);
  LoRa.setPins(SS,RST,DI0);
  Serial.println("LoRa Sender");
  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  Serial.print("LoRa Spreading Factor: ");
  Serial.println(spreadingFactor);
  LoRa.setSpreadingFactor(spreadingFactor);

  Serial.print("LoRa Signal Bandwidth: ");
  Serial.println(SignalBandwidth);
  LoRa.setSignalBandwidth(SignalBandwidth);

  LoRa.setCodingRate4(codingRateDenominator);
  LoRa.setPreambleLength(preambleLength);
  Serial.println("LoRa Initial OK!");
}

int steps = 0;

void loop(void) {

  pox.update();
  int bpm = pox.getHeartRate();
  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {       
        Serial.println(String(bpm) + " BPM");
        tsLastReport = millis();
  }
  u8g2.clearBuffer(); 
  do {
        if(steps == 0){
          u8g2.drawBitmap(15, 15, 13, 32, company_logo);
            delay(2000);
         }
         else {    
          u8g2.drawBitmap(100, 2, 3, 11, battery_half_data);
          u8g2.drawBitmap(65, 2, 4, 15, lora_data);
          u8g2.drawBitmap(45, 2, 2, 15, gps_data);
          u8g2.drawBitmap(2, 45, 2, 15, heart_data);
          u8g2.setFont(u8g2_font_unifont_h_symbols);
          u8g2.setCursor(21, 60);
          u8g2.print(bpm);  // 심박수치     
          u8g2.setFont(u8g2_font_fub20_tf);
          u8g2.drawStr( 50, 60, "13:26"); //Need to change for now time.
         }
   } 
  while( u8g2.nextPage() );
  steps++;  

  Serial.println(band_sn);
  Serial.println(lat_x);
  Serial.println(lat_y);
  // send packet
  LoRa.beginPacket();
  LoRa.print(bpm + ":"); 
  LoRa.print(band_sn + ":");
  LoRa.print(lat_x + ":");
  LoRa.print(lat_y);
  LoRa.endPacket();      

delay(2500);
}

[/CODE]

### Debug Messages:

Enable Core debug level: Debug on tools menu of Arduino IDE, then put the serial output here

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This stale issue has been automatically closed. Thank you for your contributions.