On a PYNQ-Z1 board, is there a demo/example where the xadc is read? For starters, getting on value per python call would be nice. Then, how to read “as fast as possible” and streaming data would be the next step.
Thank you
On a PYNQ-Z1 board, is there a demo/example where the xadc is read? For starters, getting on value per python call would be nice. Then, how to read “as fast as possible” and streaming data would be the next step.
Thank you
Hi Chris,
I also looked for sample codes to read the xadc, but couldn’t find.
Then I made 2 instructive codes.
If you need to measure the voltage only once with A0 analog input on pynq-z1, the following code is the easiest.
from pynq.overlays.base import BaseOverlay
from pynq.lib.arduino.arduino_analog import Arduino_Analog
ol = BaseOverlay('base.bit')
xadc = Arduino_Analog(ol.ARDUINO, [0])
print(xadc.read())
When using other analog inputs, please change the list in the Arduino_Analog function, e.g., using A1 → [1], A2 → [2] etc.
We can achieve the fastest voltage reading by using the circular buffer.
The fastest sampling rate should be 1 kS/s.
from pynq.overlays.base import BaseOverlay
from pynq.lib.arduino.arduino_analog import Arduino_Analog
import matplotlib.pyplot as plt
from time import sleep
ol = BaseOverlay('base.bit')
xadc = Arduino_Analog(ol.ARDUINO, [0])
# Select the sampling interval in the unit of ms.
xadc.set_log_interval_ms(1)
xadc.start_log()
# Wait for stacking data.
sleep(1)
v = xadc.get_log()
print(v[0])
The analog input can be changed in the same manner as the first sample code.
It seems we can use only 1kS/s sampling rate as long as accessing to xadc via python, though the ADC installed in Zynq has 1MS/s sampling rate.
Best,
Tomo
Hi,Ohnamuchi0530. Thanks for ur answer. But if i don’t want to use the “base.bit”, and I want to creat my own bit.file. What IP should I use? And I wonder how to read the analog input in jupyter now. thank you very much.