To use a peripheral two software components are required; a driver application written in C for the IOP, and a Python module. These components are provided as part of the Pynq package for supported peripherals. See the IO Processors: Writing your own software section of the documentation for writing drivers for your own peripherals.
The Python module instantiates the peripheral, and loads the driver application to the appropriate IOP. The IOP will also be reset and start executing the new application.
The Python module will send commands which the IOP will interpret and execute. The Python module may also send the data if necessary. The IOP will read from and write data into the shared memory area.
This examples requires the PmodOLED (OLED), and PmodALS (Ambient Light Sensor). Plug the PmodALS into PMODA, and PmodOLED into the top row of PMODB. (Currently, the PmodALS can only be used in the top row of a Pmod port.)
OLED displaying light reading from ambient light sensor:
Execute the next cell to load the FPGA fabric with the desired overlay, and then import the OLED module and instantiate it on PMODB:
In :from pynq import Overlay from pynq.iop import Pmod_OLED from pynq.iop import PMODB ol = Overlay("base.bit") ol.download() oled = Pmod_OLED(PMODB)
Try writing a message to the OLED.
In :oled.write("Hello World")
Import the ALS library, create an instance of the ALS Pmod, and read the value from the sensor.
In :from pynq.iop import Pmod_ALS from pynq.iop import PMODA als = Pmod_ALS(PMODA) als.read()
Write the value from the ALS to the OLED. The ALS sensor returns an 8-bit value.
In :oled.write("Light value : " + str(als.read()))
In :import time from pynq.iop import Pmod_ALS from pynq.iop import PMODA als = Pmod_ALS(PMODA) als.set_log_interval_ms(100) als.start_log() time.sleep(1) als.stop_log() als.get_log()
For information on other supported peripherals and their API, see the pynq.iop package section of the documentation.