Live Plotting BNC input using Python

Applications, development tools, FPGA, C, WEB
Post Reply
Elf
Posts: 1
Joined: Wed Jul 13, 2016 5:36 am

Live Plotting BNC input using Python

Post by Elf » Wed Aug 24, 2016 7:01 am

Hi, I'm trying to make an updating graph of an analogue input to the Pitaya in python (I'm using matplotlib).
I've taken the sample code to plot from an analogue input, and combined it with some code from a live-plotting tutorial, but the graph still doesn't update with new values, and I'm not sure which part of the code is preventing it from doing so (but I think it's to do with the triggering?)
My code is below, any help is appreciated.

Code: Select all

#------PLOT FAST ANALOGUE SIGNAL FT. MATLAB------
#---importing---
import sys
import time
import redpitaya_scpi as scpi
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style

#---connecting to Pitaya---
rp_s = scpi.scpi('ip_address_here')
rp_s.tx_txt('ACQ:START')
rp_s.tx_txt('ACQ:TRIG NOW')
#---making a figure---
style.use('fivethirtyeight')
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)

#---getting the data and updating---
def animate(i):
	plt.ion()
	while 1:
	    rp_s.tx_txt('ACQ:TRIG:STAT?') #get trigger status
	    if rp_s.rx_txt() == 'TD': #TD is disabled
	        break
	rp_s.tx_txt('ACQ:SOUR1:DATA?')
	buff_string = rp_s.rx_txt()
	buff_string = buff_string.strip('{}\n\r').replace("  ", "").split(',')
	buff = map(float, buff_string)
	ax1.clear()
	ax1.plot(buff)

#---Plotting---
ani = animation.FuncAnimation(fig, animate, interval = 1000)
plt.show()

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Live Plotting BNC input using Python

Post by Nils Roos » Wed Aug 24, 2016 11:47 am

but I think it's to do with the triggering?
You are quite right, the "ACQ:START" and "ACQ:TRIG NOW" belong inside the animate() function before the while loop. The way it is now, you are always reading the same buffered samples over and over.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 79 guests