# Running DAC-ADC Pmod Example "adc.read()" hangs with Pmod AD1

**URL:** <https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441>\
**Category:** Support\
**Created:** [July 7, 2022, 8:31pm UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441 "2022-07-07T20:31:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![adowney2](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@adowney2](https://discuss.pynq.io/u/adowney2)\
**Post date:** [July 7, 2022, 8:31pm UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/1 "2022-07-07T20:31:19Z")

</div>

I am trying to run the example " DAC-ADC Pmod Examples …" that can be found at the link below on a PYNQ-Z1. [https://github.com/Xilinx/PYNQ/blob/v2.5/boards/Pynq-Z1/base/notebooks/pmod/pmod\_dac\_adc.ipynb](https://github.com/Xilinx/PYNQ/blob/v2.5/boards/Pynq-Z1/base/notebooks/pmod/pmod_dac_adc.ipynb)

However, instead of a PmodAD4 I have a Pmod AD1 (The PmodAD4 is out of stock).

I am able to run all of the setup code,

```auto
from pynq.overlays.base import BaseOverlay
from pynq.lib import Pmod_ADC, Pmod_DAC
ol = BaseOverlay("base.bit")
dac = Pmod_DAC(ol.PMODB)
adc = Pmod_ADC(ol.PMODA)

```

I am able to write to the DAC (I can see this on an oscilloscope so I know it’s working).  
`dac.write(0.35)`

But when I come to read from the ADC, it hangs,  
`sample = adc.read()`

I can leave it for several minutes but it will never complete, and just stays as `[*]`. I tried restarting the PYNQ-Z1, restarting the kernel, and writing some of my own code but it always hangs at the same line. If I interrupt the kernel I get the error below, but I am not sure how to read into this error or what causes it.

> * * *
> 
> KeyboardInterrupt Traceback (most recent call last)  
> in ()  
> ----\> 1 sample = adc.read()
> 
> /opt/python3.6/lib/python3.6/site-packages/pynq/lib/pmod/pmod\_adc.py in read(self, ch1, ch2, ch3)  
> 202  
> 203 # Send the command  
> → 204 self.microblaze.write\_blocking\_command(cmd)  
> 205  
> 206 # Read the last sample from ADC
> 
> /opt/python3.6/lib/python3.6/site-packages/pynq/lib/pmod/pmod.py in write\_blocking\_command(self, command)  
> 152 “”"  
> 153 self.write(MAILBOX\_OFFSET + MAILBOX\_PY2IOP\_CMD\_OFFSET, command)  
> → 154 while self.read(MAILBOX\_OFFSET + MAILBOX\_PY2IOP\_CMD\_OFFSET) != 0:  
> 155 pass  
> 156
> 
> /opt/python3.6/lib/python3.6/site-packages/pynq/lib/pynqmicroblaze/pynqmicroblaze.py in read(self, offset, length)  
> 304 “”"  
> 305 if length == 1:  
> → 306 return self.mmio.read(offset)  
> 307 elif length \> 1:  
> 308 return [self.mmio.read(offset + 4\*i) for i in range(length)]
> 
> /opt/python3.6/lib/python3.6/site-packages/pynq/mmio.py in read(self, offset, length)  
> 140  
> 141 # Read data out  
> → 142 return int(self.array[idx])  
> 143  
> 144 def write(self, offset, data):
> 
> KeyboardInterrupt:

I am very new to Pynq, and to Juptyer notebooks in general (I come from an Ancaoda/spyder background) so I fully admit I may be missing something simple. Looking at the docs for the library call, I don’t see anything about this library only being for PmodAD2, but maybe there is a compatibility issue  
that I am running into?

[https://pynq.readthedocs.io/en/v2.7.0/pynq\_package/pynq.lib/pynq.lib.pmod.html?highlight=Pmod\_DAC#module-pynq.lib.pmod.pmod\_adc](https://pynq.readthedocs.io/en/v2.7.0/pynq_package/pynq.lib/pynq.lib.pmod.html?highlight=Pmod_DAC#module-pynq.lib.pmod.pmod_adc)

I am not sure how to get my PYNQ version number, as if I they `root@pynq:/home/xilinx# pynq --version` into the Jupyter terminal I get `bash: pynq: command not found`. However, if I open the file REVISION I see “Release 2018\_02\_16 e5c8aeb” so I assume that is my version.

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [July 8, 2022, 7:06am UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/2 "2022-07-08T07:06:12Z")

</div>

Hi @adowney2,

Welcome to our community.  
What board are you using? I would suggest you get the latest SD Card image version (2.7) from here [PYNQ - Python productivity for Zynq - Board](http://www.pynq.io/board.html).

It is also likely that the driver you are trying to use does not work for that PMOD. You can use the PYNQ Peripherals project to write the driver for that PMOD. [GitHub - Xilinx/PYNQ\_Peripherals](https://github.com/Xilinx/PYNQ_Peripherals)

Mario

---

<div class="post-metadata">

**Author:** ![adowney2](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@adowney2](https://discuss.pynq.io/u/adowney2)\
**Post date:** [July 8, 2022, 3:57pm UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/3 "2022-07-08T15:57:55Z")

</div>

Thanks for the help,

- I am using a PYNQ-Z1.
- I just installed the image last week, but there is a chance I could have installed an old one. How could I check what version I have? I would love to be able to figure this out.
  - From a Jupyter terminal, if I log and type `pynq --version' I get `bash: pynq: command not found`
  - However, if I open the file REVISION in the pynq directory I see “Release 2018\_02\_16 e5c8aeb” so I assume that is my version.

- On the driver issue, how would I know what Pmods that driver would work for? I am getting the feeling that the PMODS are hit and miss in terms of working out of the box and are a Diligent thing that I will have to work around.

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [July 8, 2022, 5:11pm UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/4 "2022-07-08T17:11:06Z")

</div>

Hi,

In a notebook you can do

```python
import pynq
print(pynq. __version__ )

```

Each notebook should state which PMOD works with it. Also, the driver for each PMOD is open source, so you can check if the code implements the functionality to talk to the PMOD.  
Writing your own driver if this is what you need should be relatively easy with the [PYNQ Peripherals project](https://github.com/Xilinx/PYNQ_Peripherals)

Mario

---

<div class="post-metadata">

**Author:** ![adowney2](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@adowney2](https://discuss.pynq.io/u/adowney2)\
**Post date:** [July 8, 2022, 9:24pm UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/5 "2022-07-08T21:24:30Z")

</div>

Thanks, This is helpful, Let me work through these ones by one.

```auto
import pynq 
print(pynq. __version__ )

```

returns

> * * *
> 
> AttributeError Traceback (most recent call last)  
> in ()  
> 1 import pynq  
> ----\> 2 print(pynq. **version** )
> 
> AttributeError: module ‘pynq’ has no attribute ‘ **version** ’

form the source file it, it has the following, but no **version**.

> **author** = “Yun Rock Qu”  
> **copyright** = “Copyright 2016, Xilinx”  
> **email** = “[pynq\_support@xilinx.com](mailto:pynq_support@xilinx.com)”
> 
> **all** = [‘lib’, ‘tests’]

For the PMOD, thanks!  
I looked in the source code and in the header, I see “Pmod\_ADC(object)” is only for " The Pmod AD2 (PB 200-217) ". To me, I thought that this worked for all ADC Pmods. I will have to look for / create a driver for the AD1. Here is a link to the source code.  
[pynq.lib.pmod.pmod\_adc — Python productivity for Zynq (Pynq)](https://pynq.readthedocs.io/en/v2.7.0/_modules/pynq/lib/pmod/pmod_adc.html#Pmod_ADC) Thanks for your help on this.

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [July 9, 2022, 9:16am UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/6 "2022-07-09T09:16:31Z")

</div>

Hi,

Well, based on this. It would appear that you have in the best case scenario the PYNQ 2.3 version or older. Which is really old.  
Please get the SD Card image for the 2.7 version.

Mario

---

<div class="post-metadata">

**Author:** ![adowney2](https://avatars.discourse-cdn.com/v4/letter/a/8e8cbc/32.png) [@adowney2](https://discuss.pynq.io/u/adowney2)\
**Post date:** [July 9, 2022, 3:32pm UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/7 "2022-07-09T15:32:09Z")

</div>

Thanks, you were correct. I installed an older version. That is updated now. With 2.7 `print(pynq. __version__ )` returns 2.7.0

I think that closes out all the questions I had on this thread. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![marioruiz](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/marioruiz/32/2177_2.png) [@marioruiz](https://discuss.pynq.io/u/marioruiz)\
**Post date:** [July 11, 2022, 7:02am UTC](https://discuss.pynq.io/t/running-dac-adc-pmod-example-adc-read-hangs-with-pmod-ad1/4441/8 "2022-07-11T07:02:41Z")

</div>


