Cardiotachometer-Python Application

1,992

19

Introduction: Cardiotachometer-Python Application

Python is a programming language that lets you work quickly and integrate systems more effectively. More and more people are learning and using PYTHON. As a hardware engineer, we can learn and use python by combining hardware design and realize projects.

This instructable will introduce a project about Heart rate monitor. Nowadays, people pay more and more attention to their health, so the heart rate becomes one of the concerns. Use a blood oxygen sensor and ESP8266 to build a simple monitor.

Supplies

Hardware:

The MAX30100 is a sensor that can read heart rate and blood oxygen. It’s working principle is that the ADC value of heart rate can be obtained by infrared LED light irradiation.

  • Micro USB cable
  • Dupont Line
  • Breadboard

Software:

  • Python3
  • Visual Studio code
  • uPyCraft_v1.1

Step 1: Connection

Before connecting ESP8266 and MAX30100, you need to solder a pull-up resistor with a resistance of 4.7KΩ to the SCL and SDA pins of the MAX30100 module. The MAX30100 pins connections:

sensor ------ MakePython ESP8266
VIN------3V3
GND------GND
SCL------IO5
SDA------IO4

Connect MakePython ESP8266 and PC with Micro USB cable.

Step 2: Software on PC

Python3

  • You can download from here: https://www.python.org/downloads/.
  • Choose the 3.8.5 version, download and install it.
  • “Add Python 3.8 to PATH” selection must be checked during the installation process, as Figure 1.

Visual Studio code

  • You can download the Visual Studio code from here: https://code.visualstudio.com/. Install according to the installation wizard.
  • Open the Visual Studio code, and search for python under the Extensions page and install it, as Figure 2.
  • Open the Python file, click the button “Run Python in Terminal” on right to run the program.
  • Uncommon function libraries used by the program must be installed before running the program, as the following libraries:
import numpy as np
import matplotlib.pyplot as plt
import serial
import json
import time
import random

It will prompt that some libraries are not installed after the program runs. You can run the following command in cmd.exe to install and uninstall libraries:

pip install xxx   // xxx is library name
pip uninstall xxx   // xxx is library name
pip list    //   print installed libraries
  • After the installation is complete, the python program can be exited and executed on the PC.

Code

You can get the code from here: https://github.com/Makerfabs/Project_Wifi_Cardiotachometer.

The code is “/Project_Wifi_Cardiotachometer/heartbeat.py”.

  • Change code in “/Project_Wifi_Cardiotachometer/heartbeat.py”, change "ip_port" to your own Lan IP.
#udp init
import socket
BUFSIZE = 1024
ip_port = ('192.168.1.125', 80)
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # udp
server.bind(ip_port)

·

  • Setup UDP connection and get data.
# Set server port
ip_port = ('192.168.1.234', 80)
# Set udp
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Set bind mod
server.bind(ip_port)

def udp_get_list(list_length, level): 
  • Averaging filter.
def avg_filter(src_list, level):<br>
  • Draw a heart rate curve.
plt.clf()
        plt.title("Heart Rate:" + str(heart_rate))
        plt.ylabel("IR data")

        temp_x = np.arange(len(avg_list_y))
        plt.plot(temp_x, temp_y)

        #plt.ylim(Y_MID - y_width,Y_MID + y_width)

        for temp in lowest_point_list:
            plt.plot(temp, avg_list_y[temp], "ro")

        plt.draw()

Step 3: Firmware

uPyCraft_V1.1

On the official website of MicroPython, there are simple and typical application cases.

  • Open uPyCraft_v1.1, select the tools:” Tool > board > esp8266” and “Tools > port > com”, click the connected button on right. If the connection is not successful, the prompt will be shown as “open the serial error, please try again”. You have to update the firmware to promise the connection successfully. The firmware download link is http://www.micropython.org/resources/firmware/esp8266-20191220-v1.12.bin.

Open “Tools>BurnFirmware”, set the parameter, as Figure 3, and click OK.

  • Open the Python file, and click the “DownloadAndRun” button on right. The program has been downloaded to the board, you can see it in the “device” menu on the left, as Figure 4.

Code

SSID = "Makerfabs"      #Modify here with SSID
PASSWORD = "20160704"   #Modify here with PWD
  • Get your PC Lan IP and change code in "/Project_Wifi_Cardiotachometer/py8266/workSpace/test.py".
def main():
  wifi.connect()
  ip_port = ('192.168.1.125', 80)
  client = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
  • Connect the board to the PC by USB cable, and use the uPyCraft_V1.1 to download all files in "/Project_Wifi_Cardiotachometer/py8266/workSpace/".

Step 4: Operation

  • Use the command line to run the file: “/Project_Wifi_Cardiotachometer/heartbeat.py” on the PC, reset the board and put your finger on the sensor. The heart rate waveform will be displayed on the PC.

Step 5: Show

Be the First to Share

    Recommendations

    • Lamps and Lighting Contest

      Lamps and Lighting Contest
    • First Time Author Contest

      First Time Author Contest
    • Space Contest

      Space Contest

    Comments