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 [1]:
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 [2]:
oled.write("Hello World")
In [3]:
oled.clear()
Import the ALS library, create an instance of the ALS Pmod, and read the value from the sensor.
In [4]:
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 [5]:
oled.write("Light value : " + str(als.read()))
In [6]:
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.