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.



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


  • 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

Connect MakePython ESP8266 and PC with Micro USB cable.

Step 2: Software on PC


  • You can download from here:
  • 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: 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.


You can get the code from here:

The code is “/Project_Wifi_Cardiotachometer/”.

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


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

def udp_get_list(list_length, level): 
  • Averaging filter.
def avg_filter(src_list, level):<br>
  • Draw a heart rate curve.
        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")


Step 3: Firmware


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

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.


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/".
def main():
  ip_port = ('', 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/” 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