santh92
Junior Member level 1
Hi to all,
I am working on msp430 microcontroller by using that i am able to transfer the sine signal through UART and now want to plot that signal using python. But unfortunately i am unable to get the plot as i expected. Is there anyone can help me to solve this. and please explain me the matplotlib library of python. Thanks in advance
I am attaching my code below :
I am working on msp430 microcontroller by using that i am able to transfer the sine signal through UART and now want to plot that signal using python. But unfortunately i am unable to get the plot as i expected. Is there anyone can help me to solve this. and please explain me the matplotlib library of python. Thanks in advance
I am attaching my code below :
Code:
:???:
import sys
import serial
import numpy as np
import matplotlib.pyplot as plt
from collections import deque
port = "COM14"
baud = 460800
timeout=1
ser = serial.Serial()
ser.port = port
ser.baudrate = baud
ser.timeout = timeout
a1 = deque(([0.0])*256)
line, = plt.plot(a1)
plt.ion()
plt.title("Real Time Data Monitoring")
plt.xlabel("Time_Period")
plt.ylabel("Amplitude")
plt.ylim([0,300])
plt.grid()
try:
ser.open()
except:
sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) )
sys.exit(1)
while 1:
data = ser.read(3)
print(a1)
a1.appendleft((data))
datatoplot = a1.pop()
line.set_ydata(a1)
plt.draw()
plt.pause(0.0001)
:???:
Last edited by a moderator: