pynq.iop package — Python productivity for Zynq (Pynq) v1.0

# pynq.iop package

## Submodules

## pynq.iop.arduino_analog module

class `pynq.iop.arduino_analog.``Arduino_Analog`(if_id, gr_pin)

  Bases: `object`

  This class controls the Arduino Analog.

  XADC is an internal analog controller in the hardware. This class provides API to do analog reads from IOP.

  `iop`

    _IOP – I/O processor instance used by Arduino_Analog class.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_running`

    int – The state of the log (0: stopped, 1: started).

  `log_interval_ms`

    int – Time in milliseconds between samples on the same channel.

  `gr_pin`

    list – A list of analog pins getting sampled.

  `num_channels`

    int – The number of channels sampled.

  `get_log`()

    Return list of logged samples.

    Parameters: | None –
    Returns: | List of valid voltage samples (floats) from the ADC sensor.
    Return type: | list

  `get_log_raw`()

    Return list of logged raw samples.

    Parameters: | None –
    Returns: | List of valid raw samples from the analog device.
    Return type: | list

  `read`()

    Read the voltage value from the analog peripheral.

    Parameters: | None –
    Returns: | The float values after translation.
    Return type: | list

  `read_raw`()

    Read the analog raw value from the analog peripheral.

    Parameters: | None –
    Returns: | The raw values from the analog device.
    Return type: | list

  `reset`()

    Resets the system monitor for analog devices.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_log_interval_ms`(log_interval_ms)

    Set the length of the log for the analog peripheral.

    This method can set the time interval between two samples, so that users can read out multiple values in a single log.

    Parameters: | log_interval_ms (int) – The time between two samples in milliseconds, for logging only.
    Returns: |
    Return type: | None

  `start_log`()

    Start recording multiple voltage values (float) in a log.

    This method will first call set_log_interval_ms() before writting to the MMIO.

    Parameters: | None –
    Returns: |
    Return type: | None

  `start_log_raw`()

    Start recording raw data in a log.

    This method will first call set_log_interval_ms() before writting to the MMIO.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log`()

    Stop recording the voltage values in the log.

    This can be done by calling the stop_log_raw() method.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log_raw`()

    Stop recording the raw values in the log.

    Simply write 0xC to the MMIO to stop the log.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.arduino_io module

class `pynq.iop.arduino_io.``Arduino_IO`(if_id, index, direction)

  Bases: `object`

  This class controls the Arduino IO pins as inputs or outputs.

  Note

  The parameter ‘direction’ determines whether the instance is input/output: ‘in’ : receiving input from offchip to onchip. ‘out’ : sending output from onchip to offchip.

  Note

  The index of the Arduino pins: upper row, from right to left: {0, 1, ..., 13}. (D0 - D13) lower row, from left to right: {14, 15,..., 19}. (A0 - A5)

  `iop`

    _IOP – The _IOP object returned from the DevMode.

  `index`

    int – The index of the Arduino pin, from 0 to 19.

  `direction`

    str – Input ‘in’ or output ‘out’.

  `read`()

    Receive the value from the offboard Arduino IO device.

    Note

    Only use this function when direction is ‘in’.

    Parameters: | None –
    Returns: | The data (0 or 1) on the specified Arduino IO pin.
    Return type: | int

  `write`(value)

    Send the value to the offboard Arduino IO device.

    Note

    Only use this function when direction is ‘out’.

    Parameters: | value (int) – The value to be written to the Arduino IO device.
    Returns: |
    Return type: | None

## pynq.iop.devmode module

class `pynq.iop.devmode.``DevMode`(if_id, switch_config)

  Bases: `object`

  Control an IO processor running the developer mode program.

  This class will wait for Python to send commands to Pmod / Arduino IO, IIC, or SPI.

  `if_id`

    int – The interface ID (1,2,3) corresponding to (PMODA,PMODB,ARDUINO).

  `iop`

    _IOP – IO processor instance used by DevMode.

  `iop_switch_config`

    list – IO processor switch configuration (8 or 19 integers).

  `mmio`

    MMIO – Memory-mapped IO instance to read and write instructions and data.

  `get_cmd_word`(cmd, dWidth, dLength)

    Build the command word.

    Note

    The returned command word has the following format: Bit [0] : valid bit. Bit [2:1] : command data width. Bit [3] : command type (read or write). Bit [15:8] : command burst length. Bit [31:16] : unused.

    Parameters:

    - cmd (int) – Either 1 (read IOP register) or 0 (write IOP register).
    - dWidth (int) – Command data width.
    - dLength (int) – Command burst length (currently only supporting dLength 1).

    Returns: | The command word following a specific format.
    Return type: | int

  `is_cmd_mailbox_idle`()

    Check whether the IOP command mailbox is idle.

    Parameters: | None –
    Returns: | True if IOP command mailbox idle.
    Return type: | bool

  `load_switch_config`(config=None)

    Load the IO processor’s switch configuration.

    This method will update switch config.

    Parameters: | config (list) – A switch configuration list of integers.
    Raises: | `TypeError` – If the config argument is not of the correct type.

  `read_cmd`(address, dWidth=4, dLength=1, timeout=10)

    Send a read command to the mailbox.

    Parameters:

    - address (int) – The address tied to IO processor’s memory map.
    - dWidth (int) – Command data width.
    - dLength (int) – Command burst length (currently only supporting dLength 1).
    - timeout (int) – Time in milliseconds before function exits with warning.

    Returns: | A list of data returned by MMIO read.
    Return type: | list

  `start`()

    Start the IO Processor.

    The IOP instance will start automatically after instantiation.

    This method will: 1. zero out mailbox CMD register; 2. load switch config; 3. set IOP status as “RUNNING”.

  `status`()

    Returns the status of the IO processor.

    Parameters: | None –
    Returns: | The IOP status (“IDLE”, “RUNNING”, or “STOPPED”).
    Return type: | str

  `stop`()

    Put the IO Processor into Reset.

    This method will set IOP status as “STOPPED”.

  `write_cmd`(address, data, dWidth=4, dLength=1, timeout=10)

    Send a write command to the mailbox.

    Parameters:

    - address (int) – The address tied to IO processor’s memory map.
    - data (int) – 32-bit value to be written (None for read).
    - dWidth (int) – Command data width.
    - dLength (int) – Command burst length (currently only supporting dLength 1).
    - timeout (int) – Time in milliseconds before function exits with warning.

    Returns: |
    Return type: | None

## pynq.iop.grove_adc module

class `pynq.iop.grove_adc.``Grove_ADC`(if_id, gr_pin)

  Bases: `object`

  This class controls the Grove IIC ADC.

  Grove ADC is a 12-bit precision ADC module based on ADC121C021. Hardware version: v1.2.

  `iop`

    _IOP – I/O processor instance used by Grove_ADC.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_running`

    int – The state of the log (0: stopped, 1: started).

  `log_interval_ms`

    int – Time in milliseconds between sampled reads of the Grove_ADC sensor.

  `get_log`()

    Return list of logged samples.

    Parameters: | None –
    Returns: | List of valid voltage samples (floats) from the ADC sensor.
    Return type: | list

  `get_log_raw`()

    Return list of logged raw samples.

    Parameters: | None –
    Returns: | List of valid raw samples from the ADC sensor.
    Return type: | list

  `read`()

    Read the ADC voltage from the Grove ADC peripheral.

    Parameters: | None –
    Returns: | The float value after translation.
    Return type: | float

  `read_raw`()

    Read the ADC raw value from the Grove ADC peripheral.

    Parameters: | None –
    Returns: | The raw value from the sensor.
    Return type: | int

  `reset`()

    Resets/initializes the ADC.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_log_interval_ms`(log_interval_ms)

    Set the length of the log for the Grove_ADC peripheral.

    This method can set the time interval between two samples, so that users can read out multiple values in a single log.

    Parameters: | log_interval_ms (int) – The time between two samples in milliseconds, for logging only.
    Returns: |
    Return type: | None

  `start_log`()

    Start recording multiple voltage values (float) in a log.

    This method will first call set_log_interval_ms() before writting to the MMIO.

    Parameters: | None –
    Returns: |
    Return type: | None

  `start_log_raw`()

    Start recording raw data in a log.

    This method will first call set_log_interval_ms() before writting to the MMIO.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log`()

    Stop recording the voltage values in the log.

    This can be done by calling the stop_log_raw() method.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log_raw`()

    Stop recording the raw values in the log.

    Simply write 0xC to the MMIO to stop the log.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.grove_buzzer module

class `pynq.iop.grove_buzzer.``Grove_Buzzer`(if_id, gr_pin)

  Bases: `object`

  This class controls the Grove Buzzer.

  The grove buzzer module has a piezo buzzer as the main component. The piezo can be connected to digital outputs, and will emit a tone when the output is HIGH. Alternatively, it can be connected to an analog pulse-width modulation output to generate various tones and effects. Hardware version: v1.2.

  `iop`

    _IOP – I/O processor instance used by Grove Buzzer.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_interval_ms`

    int – Time in milliseconds between sampled reads of the GROVE_BUZZER sensor.

  `play_melody`()

    Play a melody.

    Parameters: | None –
    Returns: |
    Return type: | None

  `play_tone`(tone_period, num_cycles)

    Play a single tone with tone_period for num_cycles

    Parameters:

    - tone_period (int) – The period of the tone in microsecond.
    - num_cycles (int) – The number of cycles for the tone to be played.

    Returns: |
    Return type: | None

## pynq.iop.grove_imu module

class `pynq.iop.grove_imu.``Grove_IMU`(if_id, gr_pin)

  Bases: `object`

  This class controls the Grove IIC IMU.

  Grove IMU 10DOF is a combination of grove IMU 9DOF (MPU9250) and grove barometer sensor (BMP180). MPU-9250 is a 9-axis motion tracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer and a Digital Motion Processor (DMP). BMP180 is a high precision, low power digital pressure sensor. Hardware version: v1.1.

  `iop`

    _IOP – I/O processor instance used by Grove_IMU.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `get_accl`()

    Get the data from the accelerometer.

    Parameters: | None –
    Returns: | A list of the acceleration data along X-axis, Y-axis, and Z-axis.
    Return type: | list

  `get_altitude`()

    Get the current altitude.

    Parameters: | None –
    Returns: | The altitude value.
    Return type: | float

  `get_atm`()

    Get the current pressure in relative atmosphere.

    Parameters: | None –
    Returns: | The related atmosphere.
    Return type: | float

  `get_compass`()

    Get the data from the magnetometer.

    Parameters: | None –
    Returns: | A list of the compass data along X-axis, Y-axis, and Z-axis.
    Return type: | list

  `get_gyro`()

    Get the data from the gyroscope.

    Parameters: | None –
    Returns: | A list of the gyro data along X-axis, Y-axis, and Z-axis.
    Return type: | list

  `get_heading`()

    Get the value of the heading.

    Parameters: | None –
    Returns: | The angle deviated from the X-axis, toward the positive Y-axis.
    Return type: | float

  `get_pressure`()

    Get the current pressure in Pa.

    Parameters: | None –
    Returns: | The pressure value.
    Return type: | float

  `get_temperature`()

    Get the current temperature in degree C.

    Parameters: | None –
    Returns: | The temperature value.
    Return type: | float

  `get_tiltheading`()

    Get the value of the tilt heading.

    Parameters: | None –
    Returns: | The tilt heading value.
    Return type: | float

  `reset`()

    Reset all the sensors on the grove IMU.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.grove_ledbar module

class `pynq.iop.grove_ledbar.``Grove_LEDbar`(if_id, gr_pin)

  Bases: `object`

  This class controls the Grove LED BAR.

  Grove LED Bar is comprised of a 10 segment LED gauge bar and an MY9221 LED controlling chip. Model: LED05031P. Hardware version: v2.0.

  `iop`

    _IOP – I/O processor instance used by Grove_LEDbar.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `read`()

    Reads the current status of LEDbar.

    Reads the current status of LEDbar and returns a 10-bit binary string. Each bit position corresponds to a LED position in the LEDbar, and bit value corresponds to the LED state.

    Red LED corresponds to the LSB, while green LED corresponds to the MSB.

    Parameters: | None –
    Returns: | String of 10 binary bits.
    Return type: | str

  `reset`()

    Resets the LEDbar.

    Clears the LEDbar, sets all LEDs to OFF state.

    Parameters: | None –
    Returns: |
    Return type: | None

  `write_binary`(data_in)

    Set individual LEDs in the LEDbar based on 10 bit binary input.

    Each bit in the 10-bit data_in points to a LED position on the LEDbar. Red LED corresponds to the LSB, while green LED corresponds to the MSB.

    Parameters: | data_in (int) – 10 LSBs of this parameter control the LEDbar.
    Returns: |
    Return type: | None

  `write_brightness`(data_in, brightness=[170, 170, 170, 170, 170, 170, 170, 170, 170, 170])

    Set individual LEDs with 3 level brightness control.

    Each bit in the 10-bit data_in points to a LED position on the LEDbar. Red LED corresponds to the LSB, while green LED corresponds to the MSB.

    Brightness of each LED is controlled by the brightness parameter. There are 3 perceivable levels of brightness: 0xFF : HIGH 0xAA : MED 0x01 : LOW

    Parameters:

    - data_in (int) – 10 LSBs of this parameter control the LEDbar.
    - brightness (list) – Each List element controls a single LED.

    Returns: |
    Return type: | None

  `write_level`(level, bright_level, green_to_red)

    Set the level to which the leds are to be lit in levels 1 - 10.

    Level can be set in both directions. set_level operates by setting all LEDs to the same brightness level.

    There are 4 preset brightness levels: bright_level = 0: off bright_level = 1: low bright_level = 2: medium bright_level = 3: maximum

    green_to_red indicates the direction, either from red to green when it is 0, or green to red when it is 1.

    Parameters:

    - level (int) – 10 levels exist, where 1 is minimum and 10 is maximum.
    - bright_level (int) – Controls brightness of all LEDs in the LEDbar, from 0 to 3.
    - green_to_red (int) – Sets the direction of the sequence.

    Returns: |
    Return type: | None

## pynq.iop.grove_light module

class `pynq.iop.grove_light.``Grove_Light`(if_id, gr_pin)

  Bases: `pynq.iop.grove_adc.Grove_ADC`

  This class controls the grove light sensor.

  This class inherits from the Grove_ADC class. To use this module, grove ADC has to be used as a bridge. The light sensor incorporates a Light Dependent Resistor (LDR) GL5528. Hardware version: v1.1.

  `iop`

    _IOP – I/O processor instance used by Grove ADC.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_running`

    int – The state of the log (0: stopped, 1: started).

  `log_interval_ms`

    int – Time in milliseconds between sampled reads of the Grove ADC sensor.

  `get_log`()

    Return list of logged light sensor resistances.

    Parameters: | None –
    Returns: | List of valid light sensor resistances.
    Return type: | list

  `read`()

    Read the light sensor resistance in from the light sensor.

    This method overrides the definition in Grove_ADC.

    Parameters: | None –
    Returns: | The light reading in terms of the sensor resistance.
    Return type: | float

  `start_log`()

    Start recording the light sensor resistance in a log.

    This method will call the start_log_raw() in the parent class.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log`()

    Stop recording light values in a log.

    This method will call the stop_log_raw() in the parent class.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.grove_oled module

class `pynq.iop.grove_oled.``Grove_OLED`(if_id, gr_pin)

  Bases: `object`

  This class controls the Grove IIC OLED.

  Grove LED 128×64 Display module is an OLED monochrome 128×64 matrix display module. Model: OLE35046P. Hardware version: v1.1.

  `iop`

    _IOP – I/O processor instance used by Grove_OLED.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `clear`()

    Clear the OLED screen.

    This is done by writing empty strings into the OLED in Microblaze.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_contrast`(brightness)

    Set the contrast level for the OLED display.

    The contrast level is in [0, 255].

    Parameters: | brightness (int) – The brightness of the display.
    Returns: |
    Return type: | None

  `set_horizontal_mode`()

    Set the display mode to horizontal.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_inverse_mode`()

    Set the display mode to inverse.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_normal_mode`()

    Set the display mode to normal.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_page_mode`()

    Set the display mode to paged.

    Parameters: | None –
    Returns: |
    Return type: | None

  `set_position`(row, column)

    Set the position of the display.

    The position is indicated by (row, column).

    Parameters:

    - row (int) – The row number to start the display.
    - column (int) – The column number to start the display.

    Returns: |
    Return type: | None

  `write`(text)

    Write a new text string on the OLED.

    Clear the screen first to correctly show the new text.

    Parameters: | text (str) – The text string to be displayed on the OLED screen.
    Returns: |
    Return type: | None

## pynq.iop.grove_pir module

class `pynq.iop.grove_pir.``Grove_PIR`

  Bases: `object`

  This class controls the PIR motion sensor.

  The grove PIR motion sensor is attached to a Pmod or an Arduino interface. Hardware version: v1.2.

  `pir_iop`

    object – The Pmod IO or Arduino IO object.

  `read`()

    Receive the value from the PIR sensor.

    Returns 0 when there is no motion, and returns 1 otherwise.

    Parameters: | None –
    Returns: | The data (0 or 1) read from the PIR sensor.
    Return type: | int

## pynq.iop.grove_tmp module

class `pynq.iop.grove_tmp.``Grove_TMP`(if_id, gr_pin, version='v1.2')

  Bases: `pynq.iop.grove_adc.Grove_ADC`

  This class controls the grove temperature sensor.

  This class inherits from the Grove_ADC class. To use this module, grove ADC has to be used as a bridge. The temperature sensor uses a thermistor to detect the ambient temperature. Hardware version: v1.2.

  `iop`

    _IOP – I/O processor instance used by Grove ADC.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_running`

    int – The state of the log (0: stopped, 1: started).

  `log_interval_ms`

    int – Time in milliseconds between sampled reads of the Grove ADC sensor.

  `bValue`

    int – The thermistor constant.

  `get_log`()

    Return list of logged temperature samples.

    Parameters: | None –
    Returns: | List of valid temperature readings from the temperature sensor.
    Return type: | list

  `read`()

    Read temperature values in Celsius from temperature sensor.

    This method overrides the definition in Grove_ADC.

    Parameters: | None –
    Returns: | The temperature reading in Celsius.
    Return type: | float

  `start_log`()

    Start recording temperature in a log.

    This method will call the start_log_raw() in the parent class.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log`()

    Stop recording temperature in a log.

    This method will call the stop_log_raw() in the parent class.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.iop module

`pynq.iop.iop.``request_iop`(iop_id, mb_program)

  This is the interface to request an I/O Processor.

  It looks for active instances on the same IOP ID, and prevents users from instantiating different types of IOPs on the same interface. Users are notified with an exception if the selected interface is already hooked to another type of IOP, to prevent unwanted behavior.

  Two cases: 1. No previous IOP in the system with the same ID, or users want to request another instance with the same program. Do not raises an exception. 2. There is A previous IOP in the system with the same ID. Users want to request another instance with a different program. Raises an exception.

  Note

  When an IOP is already in the system with the same IOP ID, users are in danger of losing the old instances associated with this IOP.

  For bitstream base.bit, the IOP IDs are {1, 2, 3} <=> {PMODA, PMODB, arduino interface}. For different bitstreams, this mapping can be different.

  Parameters:

  - iop_id (int) – IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
  - mb_program (str) – Program to be loaded on the IOP.

  Returns: | An _IOP object with the updated Microblaze program.
  Return type: | _IOP

  Raises:

  - `ValueError` – When the IOP name or the GPIO name cannot be found in the PL.
  - `LookupError` – When another IOP is in the system with the same IOP ID.

## pynq.iop.iop_const module

## pynq.iop.pmod_adc module

class `pynq.iop.pmod_adc.``Pmod_ADC`(if_id)

  Bases: `object`

  This class controls an Analog to Digital Converter Pmod.

  The Pmod AD2 (PB 200-217) is an analog-to-digital converter powered by AD7991. Users may configure up to 4 conversion channels at 12 bits of resolution.

  `iop`

    _IOP – I/O processor instance used by the ADC

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_running`

    int – The state of the log (0: stopped, 1: started).

  `get_log`()

    Get the log of voltage values.

    First stop the log before getting the log.

    Parameters: | None –
    Returns: | List of voltage samples from the ADC.
    Return type: | list

  `get_log_raw`()

    Get the log of raw values.

    First stop the log before getting the log.

    Parameters: | None –
    Returns: | List of raw samples from the ADC.
    Return type: | list

  `read`(ch1=1, ch2=0, ch3=0)

    Get the voltage from the Pmod ADC.

    When ch1, ch2, and ch3 values are 1 then the corresponding channel is included.

    For each channel selected, this method reads and returns one sample.

    Note

    The 4th channel is not available due to the jumper setting on ADC.

    Note

    This method reads the voltage values from ADC.

    Parameters:

    - ch1 (int) – 1 means include channel 1, 0 means do not include.
    - ch2 (int) – 1 means include channel 2, 0 means do not include.
    - ch3 (int) – 1 means include channel 3, 0 means do not include.

    Returns: | The voltage values read from the 3 channels of the Pmod ADC.
    Return type: | list

  `read_raw`(ch1=1, ch2=0, ch3=0)

    Get the raw value from the Pmod ADC.

    When ch1, ch2, and ch3 values are 1 then the corresponding channel is included.

    For each channel selected, this method reads and returns one sample.

    Note

    The 4th channel is not available due to the jumper (JP1) setting on ADC.

    Note

    This method reads the raw value from ADC.

    Parameters:

    - ch1 (int) – 1 means include channel 1, 0 means do not include.
    - ch2 (int) – 1 means include channel 2, 0 means do not include.
    - ch3 (int) – 1 means include channel 3, 0 means do not include.

    Returns: | The raw values read from the 3 channels of the Pmod ADC.
    Return type: | list

  `reset`()

    Reset the Pmod ADC.

    Parameters: | None –
    Returns: |
    Return type: | None

  `start_log`(ch1=1, ch2=0, ch3=0, log_interval_us=100)

    Start the log of voltage values with the interval specified.

    This parameter log_interval_us can set the time interval between two samples, so that users can read out multiple values in a single log.

    Parameters:

    - ch1 (int) – 1 means include channel 1, 0 means do not include.
    - ch2 (int) – 1 means include channel 2, 0 means do not include.
    - ch3 (int) – 1 means include channel 3, 0 means do not include.
    - log_interval_us (int) – The length of the log in milliseconds, for debug only.

    Returns: |
    Return type: | None

  `start_log_raw`(ch1=1, ch2=0, ch3=0, log_interval_us=100)

    Start the log of raw values with the interval specified.

    This parameter log_interval_us can set the time interval between two samples, so that users can read out multiple values in a single log.

    Parameters:

    - ch1 (int) – 1 means include channel 1, 0 means do not include.
    - ch2 (int) – 1 means include channel 2, 0 means do not include.
    - ch3 (int) – 1 means include channel 3, 0 means do not include.
    - log_interval_us (int) – The length of the log in milliseconds, for debug only.

    Returns: |
    Return type: | None

  `stop_log`()

    Stop the log of voltage values.

    This is done by sending the reset command to IOP. There is no need to wait for the IOP.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log_raw`()

    Stop the log of raw values.

    This is done by sending the reset command to IOP. There is no need to wait for the IOP.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.pmod_als module

class `pynq.iop.pmod_als.``Pmod_ALS`(if_id)

  Bases: `object`

  This class controls a light sensor Pmod.

  The Digilent Pmod ALS demonstrates light-to-digital sensing through a single ambient light sensor. This is based on an ADC081S021 analog-to-digital converter and a TEMT6000X01 ambient light sensor.

  `iop`

    _IOP – I/O processor instance used by ALS

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_interval_ms`

    int – Time in milliseconds between sampled reads of the ALS sensor

  `get_log`()

    Return list of logged samples.

    Parameters: | None –
    Returns: |
    Return type: | List of valid samples from the ALS sensor [0-255]

  `read`()

    Read current light value measured by the ALS Pmod.

    Parameters: | None –
    Returns: | The current sensor value.
    Return type: | int

  `set_log_interval_ms`(log_interval_ms)

    Set the length of the log in the ALS Pmod.

    This method can set the length of the log, so that users can read out multiple values in a single log.

    Parameters: | log_interval_ms (int) – The length of the log in milliseconds, for debug only.
    Returns: |
    Return type: | None

  `start_log`()

    Start recording multiple values in a log.

    This method will first call set_log_interval_ms() before writting to the MMIO.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log`()

    Stop recording multiple values in a log.

    Simply write to the MMIO to stop the log.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.pmod_cable module

class `pynq.iop.pmod_cable.``Pmod_Cable`(if_id, index, direction, cable)

  Bases: `pynq.iop.pmod_io.Pmod_IO`

  This class can be used for a cable connecting Pmod interfaces.

  This class inherits from the Pmod IO class.

  Note

  When 2 Pmods are connected using a cable, the parameter ‘cable’ decides whether the cable is a ‘loopback’ or ‘straight’ cable. The default is a straight cable (no internal wire twisting). For pin mapping, please check the Pmod IO class.

  `iop`

    _IOP – The _IOP object returned from the DevMode.

  `index`

    int – The index of the Pmod pin, from 0 to 7.

  `direction`

    str – Input ‘in’ or output ‘out’.

  `cable`

    str – Either ‘straight’ or ‘loopback’.

  `read`()

    Receive the value from the Pmod cable.

    This class overrides the read() method in the Pmod IO class.

    Note

    Only use this function when direction = ‘in’.

    When two Pmods are connected on the same board, for any received raw value, a “straignt” cable flips the upper 4 pins and the lower 4 pins: A Pmod interface <=> Another Pmod interface {vdd,gnd,3,2,1,0} <=> {vdd,gnd,7,6,5,4} {vdd,gnd,7,6,5,4} <=> {vdd,gnd,3,2,1,0}

    A “loop-back” cable satisfies the following mapping between two Pmods: A Pmod interface <=> Another Pmod interface {vdd,gnd,3,2,1,0} <=> {vdd,gnd,3,2,1,0} {vdd,gnd,7,6,5,4} <=> {vdd,gnd,7,6,5,4}

    Parameters: | None –
    Returns: | The data (0 or 1) on the specified Pmod IO pin.
    Return type: | int

  `set_cable`(cable)

    Set the type for the cable.

    Note

    The default cable type is ‘straight’. Only straight cable or loop-back cable can be recognized.

    Parameters: | cable (str) – Either ‘straight’ or ‘loopback’.
    Returns: |
    Return type: | None

## pynq.iop.pmod_dac module

class `pynq.iop.pmod_dac.``Pmod_DAC`(if_id, value=None)

  Bases: `object`

  This class controls a Digital to Analog Converter Pmod.

  The Pmod DA4 (PB 200-245) is an 8 channel 12-bit digital-to-analog converter run via AD5628.

  `iop`

    _IOP – I/O processor instance used by the DAC

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `write`(value)

    Write a floating point number onto the DAC Pmod.

    Note

    User is not allowed to use a number outside of the range [0.00, 2.00] as the input value.

    Parameters: | value (float) – The value to be written to the DAC Pmod
    Returns: |
    Return type: | None

## pynq.iop.pmod_dpot module

class `pynq.iop.pmod_dpot.``Pmod_DPOT`(if_id)

  Bases: `object`

  This class controls a digital potentiometer Pmod.

  The Pmod DPOT (PB 200-239) is a digital potentiometer powered by the AD5160. Users may set a desired resistance between 60 ~ 10k ohms.

  `iop`

    _IOP – I/O processor instance used by DPOT

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `write`(val, step=0, log_ms=0)

    Write the value into the DPOT.

    This method will write the parameters “value”, “step”, and “log_ms” all together into the DPOT Pmod. The parameter “log_ms” is only used for debug; users can ignore this parameter.

    Parameters:

    - val (int) – The initial value to start, in [0, 255].
    - step (int) – The number of steps when ramping up to the final value.
    - log_ms (int) – The length of the log in milliseconds, for debug only.

    Returns: |
    Return type: | None

## pynq.iop.pmod_iic module

class `pynq.iop.pmod_iic.``Pmod_IIC`(if_id, scl_pin, sda_pin, iic_addr)

  Bases: `object`

  This class controls the Pmod IIC pins.

  Note

  The index of the Pmod pins: upper row, from left to right: {vdd,gnd,3,2,1,0}. lower row, from left to right: {vdd,gnd,7,6,5,4}.

  `iop`

    _IOP – The _IOP object returned from the DevMode.

  `scl_pin`

    int – The SCL pin number.

  `sda_pin`

    int – The SDA pin number.

  `iic_addr`

    int – The IIC device address.

  `sr_addr`

    int – The IIC device SR address (base address + 0x104).

  `dtr_addr`

    int – The IIC device DTR address (base address + 0x108).

  `cr_addr`

    int – The IIC device CR address (base address + 0x100).

  `rfd_addr`

    int – The IIC device RFD address (base address + 0x120).

  `drr_addr`

    int – The IIC device DRR address (base address + 0x10C).

  `receive`(num_bytes)

    This method receives IIC bytes from the device.

    Parameters: | num_bytes (int) – Number of bytes to be received from the device.
    Returns: | iic_bytes – A list of 8-bit bytes received from the driver.
    Return type: | list
    Raises: | `RuntimeError` – Timeout when waiting for the RX FIFO to fill.

  `send`(iic_bytes)

    This method sends the command or data to the driver.

    Parameters: | iic_bytes (list) – A list of 8-bit bytes to be sent to the driver.
    Returns: |
    Return type: | None
    Raises: | `RuntimeError` – Timeout when waiting for the FIFO to be empty.

## pynq.iop.pmod_io module

class `pynq.iop.pmod_io.``Pmod_IO`(if_id, index, direction)

  Bases: `object`

  This class controls the Pmod IO pins as inputs or outputs.

  Note

  The parameter ‘direction’ determines whether the instance is input/output: ‘in’ : receiving input from offchip to onchip. ‘out’ : sending output from onchip to offchip. The index of the Pmod pins: upper row, from left to right: {vdd,gnd,3,2,1,0}. lower row, from left to right: {vdd,gnd,7,6,5,4}.

  `iop`

    _IOP – The _IOP object returned from the DevMode.

  `index`

    int – The index of the Pmod pin, from 0 to 7.

  `direction`

    str – Input ‘in’ or output ‘out’.

  `read`()

    Receive the value from the offboard Pmod IO device.

    Note

    Only use this function when direction is ‘in’.

    Parameters: | None –
    Returns: | The data (0 or 1) on the specified Pmod IO pin.
    Return type: | int

  `write`(value)

    Send the value to the offboard Pmod IO device.

    Note

    Only use this function when direction is ‘out’.

    Parameters: | value (int) – The value to be written to the Pmod IO device.
    Returns: |
    Return type: | None

## pynq.iop.pmod_led8 module

class `pynq.iop.pmod_led8.``Pmod_LED8`(if_id, index)

  Bases: `object`

  This class controls a single LED on the LED8 Pmod.

  The Pmod LED8 (PB 200-163) has eight high-brightness LEDs. Each LED can be individually illuminated from a logic high signal.

  `iop`

    _IOP – I/O processor instance used by LED8.

  `index`

    int – Index of the pin on LED8, from 0 to 7.

  `off`()

    Turn off a single LED.

    Parameters: | None –
    Returns: |
    Return type: | None

  `on`()

    Turn on a single LED.

    Parameters: | None –
    Returns: |
    Return type: | None

  `read`()

    Retrieve the LED state.

    Parameters: | None –
    Returns: | The data (0 or 1) read out from the selected pin.
    Return type: | int

  `toggle`()

    Flip the bit of a single LED.

    Note

    The LED will be turned off if it is on. Similarly, it will be turned on if it is off.

    Parameters: | None –
    Returns: |
    Return type: | None

  `write`(value)

    Set the LED state according to the input value

    Note

    This method does not take into account the current LED state.

    Parameters: | value (int) – Turn on the LED if value is 1; turn it off if value is 0.
    Returns: |
    Return type: | None

## pynq.iop.pmod_oled module

class `pynq.iop.pmod_oled.``Pmod_OLED`(if_id, text=None)

  Bases: `object`

  This class controls an OLED Pmod.

  The Pmod OLED (PB 200-222) is 128x32 pixel monochrome organic LED (OLED) panel powered by the Solomon Systech SSD1306.

  `iop`

    _IOP – I/O processor instance used by the OLED

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `clear`()

    Clear the OLED screen.

    This is done by sending the clear command to the IOP.

    Parameters: | None –
    Returns: |
    Return type: | None

  `draw_line`(x1, y1, x2, y2)

    Draw a straight line on the OLED.

    Parameters:

    - x1 (int) – The x-position of the starting point.
    - y1 (int) – The y-position of the starting point.
    - x2 (int) – The x-position of the ending point.
    - y2 (int) – The y-position of the ending point.

    Returns: |
    Return type: | None

  `draw_rect`(x1, y1, x2, y2)

    Draw a rectangle on the OLED.

    Parameters:

    - x1 (int) – The x-position of the starting point.
    - y1 (int) – The y-position of the starting point.
    - x2 (int) – The x-position of the ending point.
    - y2 (int) – The y-position of the ending point.

    Returns: |
    Return type: | None

  `write`(text, x=0, y=0)

    Write a new text string on the OLED.

    Parameters:

    - text (str) – The text string to be displayed on the OLED screen.
    - x (int) – The x-position of the display.
    - y (int) – The y-position of the display.

    Returns: |
    Return type: | None

## pynq.iop.pmod_pwm module

class `pynq.iop.pmod_pwm.``Pmod_PWM`(if_id, index)

  Bases: `object`

  This class uses the PWM of the IOP.

  `iop`

    _IOP – I/O processor instance used by Pmod_PWM.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `generate`(period, duty_cycle)

    Generate pwm signal with desired period and percent duty cycle.

    Parameters:

    - period (int) – The period of the tone (us), between 1 and 65536.
    - duty_cycle (int) – The duty cycle in percentage.

    Returns: |
    Return type: | None

  `stop`()

    Stops PWM generation.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.pmod_timer module

class `pynq.iop.pmod_timer.``Pmod_Timer`(if_id, index)

  Bases: `object`

  This class uses the timer’s capture and generation capabilities.

  `iop`

    _IOP – I/O processor instance used by Pmod_Timer.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `clk`

    int – The clock period of the IOP in ns.

  `event_count`(period)

    Count the number of rising edges detected in (period+2) clocks.

    Parameters: | period (int) – A parameter related to the period of the generated signals.
    Returns: | The number of events detected.
    Return type: | int

  `event_detected`(period)

    Detect a rising edge or high-level in (period+2) clocks.

    Parameters: | period (int) – A parameter related to the period of the generated signals.
    Returns: | 1 if any event is detected, and 0 if no event is detected.
    Return type: | int

  `generate_pulse`(period, times=0)

    Generate pulses every (period+2) clocks for a number of times.

    The default is to generate pulses every (period+2) IOP clocks forever until stopped. The pulse width is equal to the IOP clock period.

    Parameters:

    - period (int) – A parameter related to the period of the generated signals.
    - times (int) – The number of times for which the pulses are generated.

    Returns: |
    Return type: | None

  `get_period_ns`()

    Measure the period between two successive rising edges.

    Parameters: | None –
    Returns: | Measured period in ns.
    Return type: | int

  `stop`()

    This method stops the timer.

    Parameters: | None –
    Returns: |
    Return type: | None

## pynq.iop.pmod_tmp2 module

class `pynq.iop.pmod_tmp2.``Pmod_TMP2`(if_id)

  Bases: `object`

  This class controls a temperature sensor Pmod.

  The Pmod TMP2 (PB 200-221) is an ambient temperature sensor powered by ADT7420.

  `iop`

    _IOP – I/O processor instance used by TMP2.

  `mmio`

    MMIO – Memory-mapped I/O instance to read and write instructions and data.

  `log_interval_ms`

    int – Time in milliseconds between sampled reads of the TMP2 sensor.

  `get_log`()

    Return list of logged samples.

    Parameters: | None –
    Returns: |
    Return type: | List of valid samples from the temperature sensor in Celsius.

  `read`()

    Read current temperature value measured by the Pmod TMP2.

    Parameters: | None –
    Returns: | The current sensor value.
    Return type: | float

  `set_log_interval_ms`(log_interval_ms)

    Set the sampling interval for the Pmod TMP2.

    Parameters: | log_interval_ms (int) – Time in milliseconds between sampled reads of the TMP2 sensor
    Returns: |
    Return type: | None

  `start_log`()

    Start recording multiple values in a log.

    This method will first call set_log_interval_ms() before writting to the MMIO.

    Parameters: | None –
    Returns: |
    Return type: | None

  `stop_log`()

    Stop recording multiple values in a log.

    Simply write to the MMIO to stop the log.

    Parameters: | None –
    Returns: |
    Return type: | None

## Module contents