Programming PYNQ-Z1’s onboard peripherals¶
Using the base overlay, each of the highlighted devices can be controlled using their corresponding pynq classes.
To demonstrate this, we will first download the base overlay to ensure
it is loaded, and then import the LED, RGBLED, Switch and Button classes
from the module
from pynq import Overlay from pynq.board import LED from pynq.board import RGBLED from pynq.board import Switch from pynq.board import Button Overlay("base.bit").download()
Controlling a single LED¶
Now we can instantiate objects of each of these classes and use their methods to manipulate the corresponding peripherals. Let’s start by instantiating a single LED and turning it on and off.
led0 = LED(0)
Check the board and confirm the LD0 is ON
Let’s then toggle led0 using the sleep() method to see the LED flashing.
import time from pynq.board import LED from pynq.board import Button led0 = LED(0) for i in range(20): led0.toggle() time.sleep(.1)