Which MicroPython libraries should I use for ECG with ESP32?

Hello everyone, I'm trying to make ECG using esp32 with micropython, I need help to find the libraries to use in code.
18 Replies
wafa_ath
wafa_ath4mo ago
Hi, you can use the machine library for hardware interaction and time for delays.and you can save and plot the data by matplotlib, do you have something specific you want to do!?
Razali Abdelrahmen
Only those txo librairies?, also, Can I use AI to analyse data ?, I mean I want to make GUI with tkinter and add button analyze which takes the data and makes analysis of the patient .
wafa_ath
wafa_ath4mo ago
Those are basic libraries, For AI analysis use Python on your computer. Save the ECG data from the ESP32 and transfer it to your computer. Because micropython is not that strong for ai tasks
Razali Abdelrahmen
Ok thank you so much, If I find problems can I ask you again ?,sorry it's my first project.
wafa_ath
wafa_ath4mo ago
Absolutely, you can ask in any time, you are very welcome
Razali Abdelrahmen
Hi again, I wanna plot a list of data that contains the values of ECG, thony of micropython doesn't know the library matplotlib.pyplot, what should I do ?, can I plot it in spyder ? If yes how I can do it ?, thank you
Dtynin
Dtynin3mo ago
@Razali Abdelrahmen I don't think thonny support standard Python libraries like matplotlib.
Dtynin
Dtynin3mo ago
using Spyder would be better for plotting your ECG data.. and Yes you can use Spyder
melta101
melta1013mo ago
how are you going to showcase the plot?
melta101
melta1013mo ago
On your device or somewhere else? OLED, LCD, etc.. Cant imagine matplotlib to run on those...
Dtynin
Dtynin3mo ago
@Razali Abdelrahmen you can import the library matplotlib.pyplot as plt then use plt.plot(data)...hope this helps??
melta101
melta1013mo ago
I have a doubt, How does matplotLib get to know which display is used, As we are not passing any display object info to Matplotlib
Razali Abdelrahmen
I wanna plot the graph of an ECG on pc
Razali Abdelrahmen
This message is printed : no module named matplotlib
Razali Abdelrahmen
But my data is on thony, how can I plot it in spyder ?
Enthernet Code
Enthernet Code3mo ago
Thonny is not suitable for matplotlib based plotting, Spyder is a good alternative where you can easily plot your ECG data using matplotlib. You can manually transfer your ECG data to Spyder or load it from a file and then use matplotlib to create the plots. If you're plotting your ecg data directly from a list
import matplotlib.pyplot as plt

ecg_data = [100, 120, 130, 110, 115, 140, 150, 130, 125, 135, 120, 110]

plt.figure(figsize=(10, 5))
plt.plot(ecg_data, marker='o', linestyle='-', color='b', label='ECG Signal')
plt.title('ECG Data Visualization')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude (mV)')
plt.grid(True)
plt.legend()
plt.show()
import matplotlib.pyplot as plt

ecg_data = [100, 120, 130, 110, 115, 140, 150, 130, 125, 135, 120, 110]

plt.figure(figsize=(10, 5))
plt.plot(ecg_data, marker='o', linestyle='-', color='b', label='ECG Signal')
plt.title('ECG Data Visualization')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude (mV)')
plt.grid(True)
plt.legend()
plt.show()
If you're using a csv file
import matplotlib.pyplot as plt
import csv

ecg_data = []
with open('ecg_data.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
ecg_data.append(float(row[0]))

plt.figure(figsize=(10, 5))
plt.plot(ecg_data, marker='o', linestyle='-', color='g', label='ECG Signal')
plt.title('ECG Data Visualization')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude (mV)')
plt.grid(True)
plt.legend()
plt.show()
import matplotlib.pyplot as plt
import csv

ecg_data = []
with open('ecg_data.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
ecg_data.append(float(row[0]))

plt.figure(figsize=(10, 5))
plt.plot(ecg_data, marker='o', linestyle='-', color='g', label='ECG Signal')
plt.title('ECG Data Visualization')
plt.xlabel('Time (s)')
plt.ylabel('Amplitude (mV)')
plt.grid(True)
plt.legend()
plt.show()
Hope this helps
melta101
melta1013mo ago
Then i have a way, you can use serial port to transfer data from micropython to your desktop then on PC, use python, pyserial to read data, and plot normally
wafa_ath
wafa_ath3mo ago
Hey @Razali Abdelrahmen first In Thonny Save your ECG data to a file then open and plot it in Spyder using matplotlib it's that easy 😁
Want results from more Discord servers?
Add your server