Being new to Python and this community, I am trying to plot the pulse return from a transducer. The pulse return is 400 uSecs in duration and occurs every 100 milliseconds. So far I can plot the received values that are constantly being received and the plot graphs these in a strip chart fashion scrolling from right to left. I would like to be able to present the plot similar to how an oscilloscope would display the return pulse. I am not all that familiar with Numpy arrays yet. I am not sure what I am forgetting in writing the proper syntax for this. Here is a snippet of the code I am having issues with.
### Parameters ##################
x = 300 # Number of points to display
y_range = [0,300] # Range of possible Y values to display
#y_range = list(np.arange(0, 300))
xs = list(np.arange(0, 300))
ys = [0] * x
plot1.set_ylim(y_range)
### Initialize communication with the pico and read value from ADC
reading = analogio.AnalogIn(board.ADC0)
### Create plot line
line, = plot1.plot(xs, ys, color= "yellow")
### Start Thread
def plot():
def animate(i, ys):
# Read data from Pico
DATA = reading.value/20
# Add y to list
ys.append(DATA)
# Limit y list to set number of items
ys = ys[- x:]
#ys = ys(np.arange(0, 300))
# Update line with new y values
line.set_ydata(ys)
print("ADC:", DATA)
return line,
### Set up plot to call animate() function
ani = animation.FuncAnimation(fig, animate, fargs=(ys,),interval=.0001, blit=True)
print("thread starting")
t = threading.Thread(name='plot', target=plot)
t.setDaemon(True)
t.start()