Question: Python newbie here. Currently I'm making a heartbeat signal detector with an Arduino for my school project. I want to draw a plotter graph with

Python newbie here.

Currently I'm making a heartbeat signal detector with an Arduino for my school project.

I want to draw a plotter graph with a signal value that I sent from Arduino to Python, but I'm still not sure exact way to make a correct array and plot it in Python.

My arduino is connected with bluetooth module, and it is continuously send double integer value around 30~40 times/second.

In Python,I want to write a script that will receive 20 seconds of data, store it in a file, and plot it.

I built my code based on my basic C knowledge.

/////////////////////////////////

import serial, sys

from time import sleep

import time

import matplotlib.pyplot as plt

def read_BLE( ser ):

msg = ""

if( ser.in_waiting > 0 ):

msg = ser.readline( ser.in_waiting ).decode('utf-8')

return msg

with serial.Serial(port='COM7', baudrate=9600, timeout=1) as ser:

command = 'AT+IMME1'

ser.write(command.encode('utf-8'))

sleep(1)

command = 'AT+ROLE1'

ser.write(command.encode('utf-8'))

sleep(1)

command = 'AT+CON4006A0950082'

ser.write(command.encode('utf-8'))

sleep(1)

values = [] # Initiate your list before the loop!

currenttime = []

while True:

max_time = 20 #limit time : 20seconds

start_time = time.time() # remember when we started

if (time.time() - start_time) > max_time:

break

currenttime.append(time.time() - start_time)

values.append(read_BLE(ser)) # python list has no set length. just append to it.

plt.plot(currenttime, values)

//////////////////////////////////

looks like I got to use numpy though

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!