Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-256
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-256
2022-256
Commits
265cdf82
Commit
265cdf82
authored
May 26, 2022
by
Kashmika Gamage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SpO2 and heart rate monitoring .ino file
parent
23b5305e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
277 additions
and
0 deletions
+277
-0
diabeta_device/OximeterAndLCDAndFirebase.ino
diabeta_device/OximeterAndLCDAndFirebase.ino
+277
-0
No files found.
diabeta_device/OximeterAndLCDAndFirebase.ino
0 → 100644
View file @
265cdf82
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <Arduino.h>
#include "Wire.h"
#include <LiquidCrystal_I2C.h>
#include <Firebase_ESP_Client.h>
//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
#define REPORTING_PERIOD_MS 1000
#define WIFI_SSID "SLT-4G -kaami"
#define WIFI_PASSWORD "Pari22@%"
// Insert Firebase project API Key
#define API_KEY "AIzaSyD5IRuR9PAvwRZzbUcLlRXr7iSkHjEobcs"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "https://diabeta-e2bfe-default-rtdb.firebaseio.com/"
//Define Firebase Data object
FirebaseData
fbdo
;
FirebaseAuth
auth
;
FirebaseConfig
config
;
unsigned
long
sendDataPrevMillis
=
0
;
int
count
=
0
;
int
beatCount
=
0
;
bool
signupOK
=
false
;
WiFiClient
client
;
// Connections : SCL PIN - D1 , SDA PIN - D2 , INT PIN - D0
PulseOximeter
pox
;
LiquidCrystal_I2C
lcd
(
0x27
,
16
,
2
);
//float BPM, SpO2;
uint32_t
tsLastReport
=
0
;
float
heartBeats
[
10
];
void
onBeatDetected
()
{
Serial
.
println
(
"Beat Detected!"
);
}
void
setup
()
{
Serial
.
begin
(
115200
);
lcd
.
begin
();
lcd
.
backlight
();
lcd
.
clear
();
startUp
();
delay
(
100
);
startUp
();
delay
(
100
);
startUp
();
delay
(
100
);
Serial
.
println
(
"Connecting to "
);
Serial
.
println
(
WIFI_SSID
);
lcd
.
clear
();
lcd
.
setCursor
(
0
,
0
);
lcd
.
print
(
"Connecting to "
);
lcd
.
setCursor
(
0
,
1
);
lcd
.
print
(
WIFI_SSID
);
WiFi
.
begin
(
WIFI_SSID
,
WIFI_PASSWORD
);
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
{
delay
(
500
);
Serial
.
print
(
"."
);
}
Serial
.
println
(
""
);
Serial
.
println
(
"WiFi connected"
);
Serial
.
print
(
"IP address:
\t
"
);
Serial
.
println
(
WiFi
.
localIP
());
lcd
.
clear
();
lcd
.
setCursor
(
0
,
0
);
lcd
.
print
(
"Connected to "
);
lcd
.
setCursor
(
0
,
1
);
lcd
.
print
(
WiFi
.
localIP
());
delay
(
2000
);
/* Assign the api key (required) */
config
.
api_key
=
API_KEY
;
/* Assign the RTDB URL (required) */
config
.
database_url
=
DATABASE_URL
;
/* Sign up */
if
(
Firebase
.
signUp
(
&
config
,
&
auth
,
""
,
""
))
{
Serial
.
println
(
"ok"
);
signupOK
=
true
;
}
else
{
Serial
.
printf
(
"%s
\n
"
,
config
.
signer
.
signupError
.
message
.
c_str
());
}
/* Assign the callback function for the long running token generation task */
config
.
token_status_callback
=
tokenStatusCallback
;
//see addons/TokenHelper.h
Firebase
.
begin
(
&
config
,
&
auth
);
Firebase
.
reconnectWiFi
(
true
);
pinMode
(
16
,
OUTPUT
);
Serial
.
print
(
"Initializing Pulse Oximeter.."
);
if
(
!
pox
.
begin
())
{
Serial
.
println
(
"FAILED"
);
for
(;;);
}
else
{
Serial
.
println
(
"SUCCESS"
);
pox
.
setOnBeatDetectedCallback
(
onBeatDetected
);
}
delay
(
10
);
}
void
loop
()
{
pox
.
update
();
float
BPM
=
pox
.
getHeartRate
();
float
SpO2
=
pox
.
getSpO2
();
if
(
millis
()
-
tsLastReport
>
REPORTING_PERIOD_MS
)
{
Serial
.
print
(
"Heart rate:"
);
Serial
.
print
(
BPM
);
Serial
.
print
(
" bpm / SpO2:"
);
Serial
.
print
(
pox
.
getSpO2
());
Serial
.
println
(
" %"
);
lcd
.
backlight
();
lcd
.
clear
();
lcd
.
setCursor
(
0
,
0
);
lcd
.
print
(
"HR: "
);
lcd
.
setCursor
(
6
,
0
);
lcd
.
print
(
BPM
);
lcd
.
print
(
"bpm"
);
lcd
.
setCursor
(
0
,
1
);
lcd
.
print
(
"SPo2: "
);
lcd
.
setCursor
(
6
,
1
);
lcd
.
print
(
pox
.
getSpO2
());
lcd
.
print
(
"%"
);
delay
(
10
);
heartBeats
[
beatCount
]
=
BPM
;
beatCount
++
;
tsLastReport
=
millis
();
if
(
BPM
>
20
&&
beatCount
>
10
)
{
beatCount
=
0
;
pox
.
shutdown
();
if
(
Firebase
.
RTDB
.
setFloat
(
&
fbdo
,
"2/HR"
,
pox
.
getHeartRate
()))
{
Serial
.
println
(
"Heart Rate PASSED"
);
Serial
.
println
(
"PATH: "
+
fbdo
.
dataPath
());
Serial
.
println
(
"TYPE: "
+
fbdo
.
dataType
());
}
else
{
Serial
.
println
(
"FAILED"
);
Serial
.
println
(
"REASON: "
+
fbdo
.
errorReason
());
}
if
(
Firebase
.
RTDB
.
setInt
(
&
fbdo
,
"2/SPo2"
,
pox
.
getSpO2
()))
{
Serial
.
println
(
"SPo2 Level PASSED"
);
Serial
.
println
(
"PATH: "
+
fbdo
.
dataPath
());
Serial
.
println
(
"TYPE: "
+
fbdo
.
dataType
());
}
else
{
Serial
.
println
(
"FAILED"
);
Serial
.
println
(
"REASON: "
+
fbdo
.
errorReason
());
}
pox
.
resume
();
}
else
{
}
delay
(
10
);
}
}
void
bubbleSort
()
{
for
(
int
i
=
0
;
i
<
9
;
i
++
)
{
for
(
int
o
=
0
;
o
<
(
10
-
(
i
+
1
));
o
++
)
{
if
(
heartBeats
[
o
]
>
heartBeats
[
o
+
1
])
{
float
t
=
heartBeats
[
o
];
heartBeats
[
o
]
=
heartBeats
[
o
+
1
];
heartBeats
[
o
+
1
]
=
t
;
}
}
}
}
void
image02
()
{
lcd
.
clear
();
byte
image07
[
8
]
=
{
B00000
,
B01100
,
B11110
,
B11111
,
B11111
,
B11111
,
B11111
,
B11111
};
byte
image06
[
8
]
=
{
B00000
,
B00000
,
B00000
,
B00000
,
B00001
,
B00011
,
B00011
,
B00011
};
byte
image22
[
8
]
=
{
B00001
,
B00001
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
};
byte
image23
[
8
]
=
{
B11111
,
B11111
,
B11111
,
B11111
,
B01111
,
B00111
,
B00011
,
B00001
};
byte
image24
[
8
]
=
{
B11111
,
B11111
,
B11111
,
B11111
,
B11110
,
B11100
,
B11000
,
B10000
};
byte
image25
[
8
]
=
{
B10000
,
B10000
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
};
byte
image09
[
8
]
=
{
B00000
,
B00000
,
B00000
,
B00000
,
B10000
,
B11000
,
B11000
,
B11000
};
byte
image08
[
8
]
=
{
B00000
,
B01110
,
B11111
,
B11111
,
B11111
,
B11111
,
B11111
,
B11111
};
lcd
.
createChar
(
0
,
image07
);
lcd
.
createChar
(
1
,
image06
);
lcd
.
createChar
(
2
,
image22
);
lcd
.
createChar
(
3
,
image23
);
lcd
.
createChar
(
4
,
image24
);
lcd
.
createChar
(
5
,
image25
);
lcd
.
createChar
(
6
,
image09
);
lcd
.
createChar
(
7
,
image08
);
lcd
.
setCursor
(
4
,
0
);
lcd
.
write
(
byte
(
0
));
lcd
.
setCursor
(
3
,
0
);
lcd
.
write
(
byte
(
1
));
lcd
.
setCursor
(
3
,
1
);
lcd
.
write
(
byte
(
2
));
lcd
.
setCursor
(
4
,
1
);
lcd
.
write
(
byte
(
3
));
lcd
.
setCursor
(
5
,
1
);
lcd
.
write
(
byte
(
4
));
lcd
.
setCursor
(
6
,
1
);
lcd
.
write
(
byte
(
5
));
lcd
.
setCursor
(
6
,
0
);
lcd
.
write
(
byte
(
6
));
lcd
.
setCursor
(
5
,
0
);
lcd
.
write
(
byte
(
7
));
}
void
startUp
()
{
image02
();
lcd
.
setCursor
(
9
,
0
);
lcd
.
print
(
"Dia"
);
lcd
.
setCursor
(
9
,
1
);
lcd
.
print
(
"Beta"
);
delay
(
2000
);
lcd
.
clear
();
lcd
.
setCursor
(
9
,
0
);
lcd
.
print
(
"Dia"
);
lcd
.
setCursor
(
9
,
1
);
lcd
.
print
(
"Beta"
);
delay
(
100
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment