PYNQ Version : 2.5.1
Board: PYNQ-Z1


I am trying to integrate an Adafruit DS3231 RTC in my design. I have used the AXI-IIC IP in my overlay and am trying to set up the time in Jupyter Notebooks. When attempting to use the libraries provided by Ada-fruit, I receive the error “AttributeError: ‘AxiIIC’ object has no attribute ‘try_lock’”. I was wondering if there was an example on setting up the DS3231 or other RTC that I could look at or if there is a way to correct the ‘try_lock error’.
Below is an image of my code and the error:


Looks like you are trying to mix a Python driver for an Arduino IIC controller with an AXI IIC.
You would need to port the Arduino driver to the PYNQ/AXI IIC or write your own using the PYNQ API.

I’m not familiar with it, but depending on the RTC device, this could be straightforward. E.g. if you just need to read back data with PYNQ IIC calls and interpret the data you get.


1 Like

Thank you for your response.

I have been trying to use the circuit python libraries provided at to implement.

How exactly would I go about porting an arduino driver, or is there any resources in writing my own in the PYNQ API?

The functions available in the AX IIIC aren’t too helpful in setting the time on the RTC.

I apologize for my ignorance, I am new to PYNQ.

What do you mean the AXI IIC isn’t helpful?
IIC basically reads or writes bytes from and address at register offsets. Depending on the peripheral, it can be very straight forward to write a simple driver.
Have a look at the source Python driver you are referring to:

You should be able to replace the i2c_bit.RWBit calls with AXI IIC calls. I see some functions are called from other libraries. You need to work out which functions you need, and what you need to read/write.

You could also check the data sheet for the chip in the peripheral you are using and write something from scratch, but it should be easier to piece something together from the existing source code.


Okay, this is a bit overwhelming as I have never coded a driver before.

So I see that the i2C_bit function is contained int the adafruit_register library. The class “RWBit” is a single read/writable bit register.

lost_power = i2c_bit.RWBit(0x0F, 7)

would an adequate IIC conversion to the above be something like:

lost_power = i2c.write(0x0F, 7)

would I have to write up libraries to replace the adafruit ones to work for IIC? Is there a good resource to learn more about PYNQ/python/RTC driver creation?

I appreciate your time.