pynq.lib.pmod Package

The pynq.lib.pmod package is a collection of drivers for controlling peripherals attached to a PMOD port. The PMOD interface can control PMOD peripherals or Grove peripherals (via the PYNQ Grove shield)

pynq.lib.pmod.pmod_adc Module

class pynq.lib.pmod.pmod_adc.Pmod_ADC(mb_info)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_running

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

Type:int
get_log()[source]

Get the log of voltage values.

First stop the log before getting the log.

Returns:List of voltage samples from the ADC.
Return type:list
get_log_raw()[source]

Get the log of raw values.

First stop the log before getting the log.

Returns:List of raw samples from the ADC.
Return type:list
read(ch1=1, ch2=0, ch3=0)[source]

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)[source]

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()[source]

Reset the ADC.

Returns:
Return type:None
start_log(ch1=1, ch2=0, ch3=0, log_interval_us=100)[source]

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)[source]

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()[source]

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.

Returns:
Return type:None
stop_log_raw()[source]

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.

Returns:
Return type:None

pynq.lib.pmod.pmod_als Module

class pynq.lib.pmod.pmod_als.Pmod_ALS(mb_info)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged samples.

Returns:
Return type:List of valid samples from the ALS sensor [0-255]
read()[source]

Read current light value measured by the ALS Pmod.

Returns:The current sensor value.
Return type:int
set_log_interval_ms(log_interval_ms)[source]

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()[source]

Start recording multiple values in a log.

This method will first call set_log_interval_ms() before sending the command.

Returns:
Return type:None
stop_log()[source]

Stop recording multiple values in a log.

Simply send the command to stop the log.

Returns:
Return type:None

pynq.lib.pmod.pmod_cable Module

class pynq.lib.pmod.pmod_cable.Pmod_Cable(mb_info, index, direction, cable)[source]

Bases: pynq.lib.pmod.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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
index

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

Type:int
direction

Input ‘in’ or output ‘out’.

Type:str
cable

Either ‘straight’ or ‘loopback’.

Type:str
read()[source]

Receive the value from the Pmod cable.

This method overrides the read() method in the Pmod IO class. There are no new write() method defined in this class, so the read() will be inherited from 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}

Returns:The data (0 or 1) on the specified Pmod IO pin.
Return type:int
set_cable(cable)[source]

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.lib.pmod.pmod_dac Module

class pynq.lib.pmod.pmod_dac.Pmod_DAC(mb_info, value=None)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
write(value)[source]

Write a floating point number onto the DAC Pmod.

Note

Input value must be in the range [0.00, 2.50]

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

pynq.lib.pmod.pmod_dpot Module

class pynq.lib.pmod.pmod_dpot.Pmod_DPOT(mb_info)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
write(val, step=0, log_ms=0)[source]

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.lib.pmod.pmod_iic Module

class pynq.lib.pmod.pmod_iic.Pmod_IIC(mb_info, scl_pin, sda_pin, iic_addr)[source]

Bases: pynq.lib.pmod.pmod_devmode.Pmod_DevMode

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}.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
scl_pin

The SCL pin number.

Type:int
sda_pin

The SDA pin number.

Type:int
iic_addr

The IIC device address.

Type:int
sr_addr

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

Type:int
dtr_addr

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

Type:int
cr_addr

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

Type:int
rfd_addr

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

Type:int
drr_addr

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

Type:int
receive(num_bytes)[source]

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)[source]

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.lib.pmod.pmod_io Module

class pynq.lib.pmod.pmod_io.Pmod_IO(mb_info, index, direction)[source]

Bases: pynq.lib.pmod.pmod_devmode.Pmod_DevMode

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}.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
index

The index of the Pmod pin, starting from 0.

Type:int
direction

Input ‘in’ or output ‘out’.

Type:str
read()[source]

Receive the value from the offboard Pmod IO device.

Note

Only use this function when direction is ‘in’.

Returns:The data (0 or 1) on the specified Pmod IO pin.
Return type:int
write(value)[source]

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.lib.pmod.pmod_led8 Module

class pynq.lib.pmod.pmod_led8.Pmod_LED8(mb_info, index)[source]

Bases: pynq.lib.pmod.pmod_devmode.Pmod_DevMode

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
iop_switch_config

Microblaze processor IO switch configuration (8 integers).

Type:list
index

Index of the pin on LED8, starting from 0.

Type:int
off()[source]

Turn off a single LED.

Returns:
Return type:None
on()[source]

Turn on a single LED.

Returns:
Return type:None
read()[source]

Retrieve the LED state.

Returns:The data (0 or 1) read out from the selected pin.
Return type:int
toggle()[source]

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.

Returns:
Return type:None
write(value)[source]

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.lib.pmod.pmod_oled Module

class pynq.lib.pmod.pmod_oled.Pmod_OLED(mb_info, text=None)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
clear()[source]

Clear the OLED screen.

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

Returns:
Return type:None
draw_line(x1, y1, x2, y2)[source]

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)[source]

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)[source]

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.lib.pmod.pmod_pwm Module

class pynq.lib.pmod.pmod_pwm.Pmod_PWM(mb_info, index)[source]

Bases: object

This class uses the PWM of the IOP.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
generate(period, duty_cycle)[source]

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()[source]

Stops PWM generation.

Returns:
Return type:None

pynq.lib.pmod.pmod_tc1 Module

class pynq.lib.pmod.pmod_tc1.Pmod_TC1(mb_info)[source]

Bases: object

This class controls a thermocouple Pmod.

The Digilent PmodTC1 is a cold-junction thermocouple-to-digital converter module designed for a classic K-Type thermocouple wire. With Maxim Integrated’s MAX31855, this module reports the measured temperature in 14-bits with 0.25 degC resolution.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged samples.

Note

The logged samples are raw 32-bit samples captured from the sensor.

Returns:List of valid samples from the TC1 sensor
Return type:list
read_alarm_flags()[source]

Read the alarm flags from the raw value.

Returns:The alarm flags from the TC1. bit 0 = 1 if thermocouple connection is open-circuit; bit 1 = 1 if thermocouple connection is shorted to generated; bit 2 = 1 if thermocouple connection is shorted to VCC; bit 16 = 1 if any if bits 0-2 are 1.
Return type:u32
read_junction_temperature()[source]

Read the reference junction temperature.

Returns:The reference junction temperature in degC.
Return type:float
read_raw()[source]

Read full 32-bit register of TC1 Pmod.

Returns:The current register contents.
Return type:int
read_thermocouple_temperature()[source]

Read the reference junction temperature.

Returns:The thermocouple temperature in degC.
Return type:float
set_log_interval_ms(log_interval_ms)[source]

Set the length of the log in the TC1 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()[source]

Start recording multiple values in a log.

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

Returns:
Return type:None
stop_log()[source]

Stop recording multiple values in a log.

Simply write to the MMIO to stop the log.

Returns:
Return type:None
pynq.lib.pmod.pmod_tc1.reg_to_alarms(reg_val)[source]

Extracts Alarm flags from 32-bit register value.

Parameters:reg_val (int) – 32-bit TC1 register value
Returns:The alarm flags from the TC1. bit 0 = 1 if thermocouple connection is open-circuit; bit 1 = 1 if thermocouple connection is shorted to generated; bit 2 = 1 if thermocouple connection is shorted to VCC; bit 16 = 1 if any if bits 0-2 are 1.
Return type:u32
pynq.lib.pmod.pmod_tc1.reg_to_ref(reg_val)[source]

Extracts Ref Junction temperature from 32-bit register value.

Parameters:reg_val (int) – 32-bit TC1 register value
Returns:The reference junction temperature in degC.
Return type:float
pynq.lib.pmod.pmod_tc1.reg_to_tc(reg_val)[source]

Extracts Thermocouple temperature from 32-bit register value.

Parameters:reg_val (int) – 32-bit TC1 register value
Returns:The thermocouple temperature in degC.
Return type:float

pynq.lib.pmod.pmod_timer Module

class pynq.lib.pmod.pmod_timer.Pmod_Timer(mb_info, index)[source]

Bases: object

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

microblaze

Microblaze processor instance used by this module.

Type:Pmod
clk_period_ns

The clock period of the IOP in ns.

Type:int
event_count(period)[source]

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

Parameters:period (int) – The period of the generated signals.
Returns:The number of events detected.
Return type:int
event_detected(period)[source]

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

Parameters:period (int) – 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)[source]

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

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

Parameters:
  • period (int) – 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()[source]

Measure the period between two successive rising edges.

Returns:Measured period in ns.
Return type:int
stop()[source]

This method stops the timer.

Returns:
Return type:None

pynq.lib.pmod.pmod_tmp2 Module

class pynq.lib.pmod.pmod_tmp2.Pmod_TMP2(mb_info)[source]

Bases: object

This class controls a temperature sensor Pmod.

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

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged samples.

Returns:
Return type:List of valid samples from the temperature sensor in Celsius.
read()[source]

Read current temperature value measured by the Pmod TMP2.

Returns:The current sensor value.
Return type:float
set_log_interval_ms(log_interval_ms)[source]

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()[source]

Start recording multiple values in a log.

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

Returns:
Return type:None
stop_log()[source]

Stop recording multiple values in a log.

Simply write to the MMIO to stop the log.

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_adc Module

class pynq.lib.pmod.pmod_grove_adc.Grove_ADC(mb_info, gr_pin)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_running

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

Type:int
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged samples.

Returns:List of valid voltage samples (floats) from the ADC sensor.
Return type:list
get_log_raw()[source]

Return list of logged raw samples.

Returns:List of valid raw samples from the ADC sensor.
Return type:list
read()[source]

Read the ADC voltage from the Grove ADC peripheral.

Returns:The float value after translation.
Return type:float
read_raw()[source]

Read the ADC raw value from the Grove ADC peripheral.

Returns:The raw value from the sensor.
Return type:int
reset()[source]

Resets/initializes the ADC.

Returns:
Return type:None
set_log_interval_ms(log_interval_ms)[source]

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()[source]

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

This method will first call set_log_interval_ms() before sending the command.

Returns:
Return type:None
start_log_raw()[source]

Start recording raw data in a log.

This method will first call set_log_interval_ms() before sending the command.

Returns:
Return type:None
stop_log()[source]

Stop recording the voltage values in the log.

Simply send the command 0xC to stop the log.

Returns:
Return type:None
stop_log_raw()[source]

Stop recording the raw values in the log.

Simply send the command 0xC to stop the log.

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_buzzer Module

class pynq.lib.pmod.pmod_grove_buzzer.Grove_Buzzer(mb_info, gr_pin)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
play_melody()[source]

Play a melody.

Returns:
Return type:None
play_tone(tone_period, num_cycles)[source]

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.lib.pmod.pmod_grove_dlight Module

class pynq.lib.pmod.pmod_grove_dlight.Grove_Dlight(mb_info, gr_pin)[source]

Bases: object

This class controls the Grove IIC color sensor.

Grove Color sensor based on the TCS3414CS. Hardware version: v1.3.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
read_lux()[source]

Read the computed lux value of the sensor.

Returns:The lux value from the sensor
Return type:int
read_raw_light()[source]

Read the visible and IR channel values.

Read the values from the grove digital light peripheral.

Returns:A tuple containing 2 integer values ch0 (visible) and ch1 (IR).
Return type:tuple

pynq.lib.pmod.pmod_grove_ear_hr Module

class pynq.lib.pmod.pmod_grove_ear_hr.Grove_EarHR(mb_info, gr_pin)[source]

Bases: object

This class controls the Grove ear clip heart rate sensor.

Sensor model: MED03212P.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
read()[source]

Read the heart rate from the sensor.

Returns:The heart rate as beats per minute
Return type:float
read_raw()[source]

Read the number of heart beats.

Read the number of beats since the sensor initialization; also read the time elapsed in ms between the latest two heart beats.

Returns:Number of heart beats and the time elapsed between 2 latest beats.
Return type:tuple

pynq.lib.pmod.pmod_grove_finger_hr Module

class pynq.lib.pmod.pmod_grove_finger_hr.Grove_FingerHR(mb_info, gr_pin)[source]

Bases: object

This class controls the Grove finger clip heart rate sensor.

Grove Finger sensor based on the TCS3414CS. Hardware version: v1.3.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_running

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

Type:int
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged samples.

Returns:List of integers containing the heart rate.
Return type:list
read()[source]

Read the heart rate value from the Grove Finger HR peripheral.

Returns:An integer representing the heart rate frequency.
Return type:int
start_log(log_interval_ms=100)[source]

Start recording multiple heart rate values in a log.

This method will first call set the log interval before writing to the MMIO.

Parameters:log_interval_ms (int) – The time between two samples in milliseconds.
Returns:
Return type:None
stop_log()[source]

Stop recording the values in the log.

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

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_haptic_motor Module

class pynq.lib.pmod.pmod_grove_haptic_motor.Grove_HapticMotor(mb_info, gr_pin)[source]

Bases: object

This class controls the Grove Haptic Motor based on the DRV2605L. Hardware version v0.9.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
is_playing()[source]

Check if a vibration effect is running on the motor.

Returns:True if a vibration effect is playing, false otherwise
Return type:bool
play(effect)[source]

Play a vibration effect on the Grove Haptic Motor peripheral.

Valid effect identifiers are in the range [1, 127].

Parameters:effect (int) – An integer that specifies the effect.
Returns:
Return type:None
play_sequence(sequence)[source]

Play a sequence of effects possibly separated by pauses.

At most 8 effects or pauses can be specified at a time. Pauses are defined using negative integer values in the range [-1, -127] that correspond to a pause length in the range [10, 1270] ms

Valid effect identifiers are in the range [1, 127]

As an example, in the following sequence example: [4,-20,5] effect 4 is played and after a pause of 200 ms effect 5 is played

Parameters:sequence (list) – At most 8 values specifying effects and pauses.
Returns:
Return type:None
stop()[source]

Stop an effect or a sequence on the motor peripheral.

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_imu Module

class pynq.lib.pmod.pmod_grove_imu.Grove_IMU(mb_info, gr_pin)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
get_accl()[source]

Get the data from the accelerometer.

Returns:A list of the acceleration data along X-axis, Y-axis, and Z-axis.
Return type:list
get_altitude()[source]

Get the current altitude.

Returns:The altitude value.
Return type:float
get_atm()[source]

Get the current pressure in relative atmosphere.

Returns:The related atmosphere.
Return type:float
get_compass()[source]

Get the data from the magnetometer.

Returns:A list of the compass data along X-axis, Y-axis, and Z-axis.
Return type:list
get_gyro()[source]

Get the data from the gyroscope.

Returns:A list of the gyro data along X-axis, Y-axis, and Z-axis.
Return type:list
get_heading()[source]

Get the value of the heading.

Returns:The angle deviated from the X-axis, toward the positive Y-axis.
Return type:float
get_pressure()[source]

Get the current pressure in Pa.

Returns:The pressure value.
Return type:float
get_temperature()[source]

Get the current temperature in degree C.

Returns:The temperature value.
Return type:float
get_tilt_heading()[source]

Get the value of the tilt heading.

Returns:The tilt heading value.
Return type:float
reset()[source]

Reset all the sensors on the grove IMU.

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_ledbar Module

class pynq.lib.pmod.pmod_grove_ledbar.Grove_LEDbar(mb_info, gr_pin)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
read()[source]

Reads the current status of LEDbar.

Reads the current status of LED bar and returns 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.

Returns:String of 10 binary bits.
Return type:str
reset()[source]

Resets the LEDbar.

Clears the LED bar, sets all LEDs to OFF state.

Returns:
Return type:None
write_binary(data_in)[source]

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])[source]

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 element controls a single LED.
Returns:

Return type:

None

write_level(level, bright_level, green_to_red)[source]

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.lib.pmod.pmod_grove_light Module

class pynq.lib.pmod.pmod_grove_light.Grove_Light(mb_info, gr_pin)[source]

Bases: pynq.lib.pmod.pmod_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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_running

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

Type:int
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged light sensor resistances.

Returns:List of valid light sensor resistances.
Return type:list
read()[source]

Read the light sensor resistance in from the light sensor.

This method overrides the definition in grove ADC.

Returns:The light reading in terms of the sensor resistance.
Return type:float
start_log()[source]

Start recording the light sensor resistance in a log.

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

Returns:
Return type:None
stop_log()[source]

Stop recording light values in a log.

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

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_oled Module

class pynq.lib.pmod.pmod_grove_oled.Grove_OLED(mb_info, gr_pin)[source]

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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
clear()[source]

Clear the OLED screen.

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

Returns:
Return type:None
set_contrast(brightness)[source]

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()[source]

Set the display mode to horizontal.

Returns:
Return type:None
set_inverse_mode()[source]

Set the display mode to inverse.

Returns:
Return type:None
set_normal_mode()[source]

Set the display mode to normal.

Returns:
Return type:None
set_page_mode()[source]

Set the display mode to paged.

Returns:
Return type:None
set_position(row, column)[source]

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)[source]

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.lib.pmod.pmod_grove_pir Module

class pynq.lib.pmod.pmod_grove_pir.Grove_PIR(mb_info, gr_pin)[source]

Bases: pynq.lib.pmod.pmod_io.Pmod_IO

This class controls the PIR motion sensor.

Hardware version: v1.2.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
index

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

Type:int
direction

Can only be ‘in’ for PIR sensor.

Type:str
read()[source]

Receive the value from the PIR sensor.

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

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

pynq.lib.pmod.pmod_grove_th02 Module

class pynq.lib.pmod.pmod_grove_th02.Grove_TH02(mb_info, gr_pin)[source]

Bases: object

This class controls the Grove I2C Temperature and Humidity sensor.

Temperature & humidity sensor (high-accuracy & mini). Hardware version: v1.0.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_running

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

Type:int
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
get_log()[source]

Return list of logged samples.

Returns:List of tuples containing (temperature, humidity)
Return type:list
read()[source]

Read the temperature and humidity values from the TH02 peripheral.

Returns:Tuple containing (temperature, humidity)
Return type:tuple
start_log(log_interval_ms=100)[source]

Start recording multiple heart rate values in a log.

This method will first call set the log interval before sending the command.

Parameters:log_interval_ms (int) – The time between two samples in milliseconds.
Returns:
Return type:None
stop_log()[source]

Stop recording the values in the log.

Simply send the command 0xC to stop the log.

Returns:
Return type:None

pynq.lib.pmod.pmod_grove_tmp Module

class pynq.lib.pmod.pmod_grove_tmp.Grove_TMP(mb_info, gr_pin, version='v1.2')[source]

Bases: pynq.lib.pmod.pmod_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.

microblaze

Microblaze processor instance used by this module.

Type:Pmod
log_running

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

Type:int
log_interval_ms

Time in milliseconds between sampled reads.

Type:int
bValue

The thermistor constant.

Type:int
get_log()[source]

Return list of logged temperature samples.

Returns:List of valid temperature readings from the temperature sensor.
Return type:list
read()[source]

Read temperature values in Celsius from temperature sensor.

This method overrides the definition in Grove_ADC.

Returns:The temperature reading in Celsius.
Return type:float
start_log()[source]

Start recording temperature in a log.

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

stop_log()[source]

Stop recording temperature in a log.

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

Returns:
Return type:None