/*
This project is to simulate a SPO2 sensor module.
A standard sensor uses i2c to communicate and it generally has many complexities
of operation involving real world problems. The real sensor also has a Heart Rate
monitor and an interrupt when an heartbeat is detected.
Our goal is to outline the IOT aspect of the project. Our required data is only the
oxygen saturation level.
So we have simplified the sensor and used one slider only to supply the SPO2 value.
To Add this chip to your project:
1. Create a new project.
2. Add a custom chip with the name "spo2-sensor", choose c for your coding language.
3. copy entire code from the XXX.chip.json file from this project and paste to your
projects XXX.chip.json file. make sure old contents are deleted.
4. copy entire code from the XXX.chip.c file from this project and paste to your
projects XXX.chip.c file. make sure old contents are deleted.
5. make the appropriate connections, pin 22 of ESP -> custom chip SCL and
custom chip SDA -> pin 21 of ESP. Make the appropriate power connections also.
How to get values from the custom chip:
Our chips i2c address is 0x11.
On receiving a read request, at this address, custom chip will send back 1 byte,
SPO2 value.
As it is only a single byte value, we do not need to implement any special structure
or logic for it. We can read it on the fly whenever required or have a polling method
as outlined in example.
*/
#include "Wire.h"
#define SADD 0x11 // slave address where we want to transmit
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Wire.begin(21, 22); // SDA, SCL
}
void loop() {
// put your main code here, to run repeatedly:
Wire.requestFrom(SADD, 1);
// If data is available from the device
if (Wire.available()) {
// Read the data
byte data = Wire.read();
// Process the data (for example, print it)
Serial.print("Oxygen Saturation is: ");
Serial.print(data);
Serial.println("%");
}
delay(1000); // this speeds up the simulation
}