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

###  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
    #   Limit y list to set number of items
        ys = ys[- x:]
        #ys = ys(np.arange(0, 300))
    #   Update line with new y values
        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)
  • 1
    $\begingroup$ Hi R Bowles, and welcome to the site! There may not be enough information here to help. Can you edit to add more explanation (and possibly source code) to show what you're doing and where the problem is? $\endgroup$
    – luser droog
    Sep 30 at 3:48
  • $\begingroup$ I have included code for the plot routine. As explained before, It plots the changing ADC values but presents it similar to a chart recorder in a continuous line. I want to be able to capture and plot the return from a piezo that is that is fired every 100 milliseconds with a duration of 200 microseconds. $\endgroup$
    – R Bowles
    Oct 1 at 17:02
  • $\begingroup$ @R. Bowles Thank you. +1 I think there's a better chance you'll get an answer now. $\endgroup$
    – luser droog
    Oct 2 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.