Transcript for:
Introduction to Pulse Oximetry with Raspberry Pi

Welcome to Embedded Projects. Today we are going to see an interesting project of how to create a pulse oximetry by using Raspberry Pi. So, Pulse Oximetry is a non-invasive method for monitoring the pulse and oxygen saturation.

so along with the pulse oximetry we are going we are also going to measure the heart rate for that we have the sensor called max 30100 which which is the integrated pulse oximetry and heart rate monitor so by using the max 30100 we are going to measure both the pulse oximetry and also heart rate together okay so max 30100 is basically a low noise analog signal processing it will detect the oximetry and heart rate signals and gives a better quality okay so this is the max so as you can see this is the max so it is very compact max 301 double zero sensor it is very compact and it is based on i2c communication okay so this we are going to connect with the raspberry pi using i2c communication so we know that i2c communication is which is pronounced as i square c is asynchronous multi master multi slave and package switch to single ended serial communication bus okay so this is basically invented by philips semiconductor and it is widely used for attaching the low speed peripheral ics to the processors and microcontrollers which has a shorter distance uh likely to say it's an intraboard communications so we are going to connect max 30100 by using this I2C bus only and then when we come to oximeter what is oximetry what is called oximetry is nothing but a non-invasive method for measuring the person oxygen saturation okay so by using this we can measure the person's oxygen saturation and this sensor does that work and what is the oxygen saturation means it's a fraction of oxygen actually it is related to hemoglobin so in hemoglobin related to the total hemoglobin in the blood so human body requires and and regulates very precise and specific balance of oxygen in the blood so blood will have the balance of oxygen we should have in the blood so this we use for measuring that oxygen saturation levels okay uh right now i have placed the sensor in the open type actually the sensor should be somewhat closed in the uh some enclosure so that we can keep our finger and no other light interference should affect the sensor so it should be closed in some enclosures plastic enclosure so that when we keep the finger it should not be affected by the external lights as far as possible okay right now for the testing purpose how we can connect to the raspberry pi i just kept in the open space okay so now we can check uh see how we can uh connect as you as you as you all know the i2c has a four wires uh vcc ground sda scl so we need to connect the so we need to connect the sensor with so i just make it small okay so we need to connect the sensor here so we need we need to give 3.3 voltage or 5 volt we can use either 3.3 or 5 volt this sensor comes with internal pull up so i am giving 5 volt and here you can see the gpio2 and gpio3 is there right so these are sda scl and ground so we need to connect the sda of sensor to the sda of the gpio and scl of sensor to the scl of the gpio so this is how the connections will be sda to sda and scl to scl and we have to give the power supply vcc and ground so this is only a four wire connection you can leave the rest of the interrupt and any other connection that you can use it in Other boards like Arduino or any other microcontroller for connecting with the Raspberry Pi only four wires is Sufficient. Okay. So this is how the sensors can be connected.

Okay. Now, let let us go to the Raspberry Pi through VNC So I'm just opening the VNC. Okay, it's already open, right?

Okay so the raspberry pi is already booted and connected to the system via vnc so this is the vnc raspberry pi screen okay so this is the raspberry pi screen so first of all i am going to check whether the i2c device whatever the i2c device i have connected is activated or not so in my last video i have shown you how to activate the i2c but again i will show you how to do that so for that you have to go to sudo raspi config okay so you have to go to the sudo raspi config and in the interfacing options okay uh just a second So you have to go to the sudo raspi config and in the interfacing options you have to go to the i2c okay and you have to say yes for i2c so that i2c will be enabled so after that you can start using your i2c devices so in our last video we connected ads 115 for adc through i2c now we are going to connect the max through i2c so now i2c is enabled and after enabling the i2c you can check whether it is actually enabled or not by checking it in the boot config after reboot you can check it in the boot config so you can go to the cat boot config dot txt file you can see it is added so i'm just gripping the word i2c alone okay so it will be showing dt param equal to i2c arm equal to on so this is the thing how you can check whether the i2c is enabled or not and also you can check it in the models okay so you can just ls they okay and you can grip it to see and you can see the I to C device that it is I to C 1 in the earlier board set is I to C 0 so I am just going to detect whether the sensor whatever the sensor I connected to the Raspberry Pi is directed or not so far that I have the command sudo I to C detect I fun so it will give the list of i2c devices connected so you can connect multiple i2c devices in the same i2c port and based on the address you can access ok so by using only two wire you can connect so many devices to the two wire and you can access the device based on the address so now the address of the max 2030100 is 57 ok so based on this address we can access so this is how i can verify the idc is connected or not okay fine next you have to download the files i have given in the github okay in the link in the below the description in the description so after downloading it has the library file for max 30100 and all and also it has a test application test python file for testing the max so i just going to transfer those files here so these are the files i'm just transferring to the raspberry pi through vnc so it is transferred just getting back okay to the desktop by default it will be in the desktop and just taking it to the pi directory fine so now the file is transferred from the system to raspberry pi i just ls okay it's there so i'm just making and getting into the cd to the folder fine so it has the two files one is max 30100.py this is the library file ok so this file will be used for getting the data from the sensor all you have to do is you need to just import this library file to your program and use it ok so i will just show you the file inside the library file what it is so for that i am just going to use the idle and max 30100 so you can see it has some macros and pulse width sample rate so whatever the things essential for the sensor is there also you can change the led current so you can see here so these are the things that is the required for the max it has the required classes so by using this class you are going to create the object in the file and you can directly use it okay so enable disable so all these functions are there inside the max model okay so now i am going to open the test file so for opening the test file I'm just opening sudo idle okay and I have the file name test max 30100.py so this is the code it's a simple code okay so this is the entire code it's a simple code raspberry pi you know as you know the raspberry pi is a single board computer and which is very easy to program and here we are most of the time we are using python in the in some other videos you can also see javascript and c plus plus using but in mostly we are using the python so the name raspberry pi pi stands for python right so we are going to use the python so this is a simple python script for reading the data from the max sensor max 30100 sensor so initially what we are going to do is we are going to import the max library and the time library time library for creating the delay and max library for getting the data from the sensors okay and after that so you can create a instance uh for your chip actually you can create an instance or object for the max class so next two lines these lines are we are creating the Instance so this is the line that is creating the instance for your max class okay, and after that I am going to enable the SpO2 okay, so I'm just enabling the SpO2 and then I can directly read from the sensor by using the read sensor So this is the read sensor function of the max class okay, so by in the while loop because we are going to we are going to create an instance once and in the while loop i am going to read the data again and again and print it in the terminal okay so here you can see i am just reading from the sensor so sensor consists of two values one is ir and one is red okay so red and ir so the latest values are available in the ir and red variables of the max class so we are going to get that value the latest values and display it in the screen ok so to read a current sensor values from the max chip you are going to use dot read sensor function and after that it will retrieve the latest values and store it in the buffer and to get the values from the stored place you have to access the variables dot ir and dot red so that is what we are doing we are accessing the variables dot ir and dot red and getting the latest value that is stored there okay so If you perform another sensor read you will see the value in the dot red parameter So whenever you perform a read sensor you will see the value in the parameter So after getting the value dot ir and dot red value you are going to store The dot ir is nothing but your odd pulse and dot red is nothing but your spvotos So I am just dividing it by 100 because it will be in the terms of multiples so i'm just dividing it by under and getting the final required value and this values i'm just going to print it here okay i'm just going to print it here so i'm printing both ir and red values so this is a simple code and this code is uploaded in the jitab repository along with the library you can download and use it okay so now let us test the sensor so for testing the sensor i am just going to Let us make it big. Now let us test the sensor. For testing the sensor, I am just going to run this code. Run model.

It is giving some junk values. After that, it is giving some junk values. Now I am going to place my finger so that the value will get stabilized.

So I am just keeping my finger in the sensor. So you have to wait for some time. It will take some time to stabilize the actual values.

So that is why when you see the oximetry readers available in the market, it will take some time. It will give you in percentage and after 100% is completed, it will give the actual values. It will take some time to stabilize the user values.

Okay, I think it is Somewhat stabilized. Okay, so I am getting the value of pulse and SPO two values here So these are the stabilized uncalibrated values then you can calibrate it to the actual thing What about if there is a difference between the actual value and the red value you can calibrate it accordingly So this is how the sensor will read there pulse and spo2 values from your finger okay so it is very easy to integrate so all you have to do is to you need you have to activate the i2c and then after activating the i2c you have to connect the sensor and check whether the sensor is detected by using the I2C detect and then you have to download the library and just run the test file and you can add this code to your actual application program ok so this is the last stored buffer value whatever you are getting there is the last stored buffer value and after some time it will become zero ok so this is how it will work so it will take some time to stabilize the value it is receiving okay now you can see it is zero and again i'm going to keep my finger so and it is processing right now after processing it will give the actual data until it is processing the values will be stored in the buffer so you got the value so now you got the value so this is how it works so thanks for watching