element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog PYNQ-Z2 Dev Kit - External Peripherals
  • Blog
  • RoadTest Forum
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RoadTests & Reviews to participate - click to join for free!
  • Share
  • More
  • Cancel
  • Author Author: ralphjy
  • Date Created: 12 Jul 2019 12:24 AM Date Created
  • Views 2152 views
  • Likes 3 likes
  • Comments 1 comment
Related
Recommended
  • RoadTest
  • pynq-z2

PYNQ-Z2 Dev Kit - External Peripherals

ralphjy
ralphjy
12 Jul 2019

I'm continuing my exploration of the base overlay to control the external peripheral interfaces on the PYNQ-Z2.  The 3 interfaces are the Pmod, Arduino, and Raspberry Pi which are each controlled through a separate soft-core Microblaze processor.  The MicroBlaze instances are referred to as IO Processors (IOP) and there are actually 4 IOPs in the base overlay as there are 2 PMODs (A/B), the Arduino IO, and the Raspberry Pi IO.  PmodA  shares its 8 data pins with the RPi interface.  The IOPs interface in the Programmable Logic (PL) with the Processor System (PS) through dual-ported instruction and data block RAMs.  Each IOP is configured to implement the specific peripheral interface functions as illustrated below.

image

image

image

image

 

For my experimenting, I am using some of the components from the Xilinx PYNQ_Workshop:

  1. Pmod 128x32 monochrome OLED
  2. Grove LEDbar
  3. Grove Temperature Sensor used with the Grove ADC

 

I had originally intended to use only the two Pmod IOPs.  PmodA would be used for the OLED and the PmodB would be used for the Pmod Grove interface board which has 4 Grove connectors ( 2 I2C and 2 GPIO).  The LEDbar uses GPIO and the ADC uses I2C (the Temperature sensor connects to the ADC).  However, when I executed the code I got an interface busy error on the PmodB IOP.  It turns out that the pre-compiled "drivers" (MicroBlaze applications) only support a single peripheral, so I couldn't run the LEDbar and the ADC on the same Pmod IOP.  Of course, this is just an FPGA programming issue.  I could write my own MicroBlaze application and compile it or I could also write some C code in the Jupyter notebook and implement multiple peripherals per IOP that way.  But, that is further down on my list of things to learn.  Luckily, I had also purchased an Arduino Grove shield so I just moved the LEDbar to it since it uses a different IOP.

 

I created a new Jupyter notebook (external_peripherals.ipynb) as a simple demo of functionality.   Here is the code that I used.  I'm using 2 libraries from the base overlay - pynq.lib.arduino and pynq.lib.pmod.  And I'm using the corresponding classes for the peripherals (Grove_LEDbar, Grove_TMP, Pmod_OLED) and the IOP connections.

 

Import the base overlay and the libraries and instantiate the peripherals:

 

from pynq.overlays.base import BaseOverlay
base = BaseOverlay("base.bit")

from time import sleep

from pynq.lib.arduino import Grove_LEDbar
from pynq.lib.arduino import ARDUINO_GROVE_G4 # Import constants
# Instantiate Grove LED Bar on ArduinoGrove G4
# PMODA = 1, PMODB = 2, Arduino = 3
# Pynq Grove Adapter; G1 = [0,4], G2 = [1,5], G3 = [7,3], G4 = [6,2]
# The LED bar can be connected to G1-7 on the Pynq Arduino Shield:
# G1 = [2,3], G2 = [3,4], G3 = [4,5], G4 = [6,7], G5 = [8,9], G6 = [10,11], G7 = [12,13]
ledbar = Grove_LEDbar(base.ARDUINO,ARDUINO_GROVE_G4)
ledbar.reset()

from pynq.lib.pmod import Pmod_OLED
# Connect to PMODA
pmod_oled = Pmod_OLED(base.PMODA)

from pynq.lib.pmod import Grove_TMP
from pynq.lib.pmod import PMOD_GROVE_G4 # import constants
# Instantiate Grove temperature sensor on PMODB Grove G4
tmp = Grove_TMP(base.PMODB, PMOD_GROVE_G4)

 

Sweep the LEDs on the LEDbar:

 

# turn on lEDs in sequence from green to red
# equalize brightness
# Brightness 0-255
HIGH = 0xFF
MED  = 0xAA
LOW  = 0x01
OFF  = 0X00
GREEN = 0x1C
RED = 0x02
ORANGE = 0x03

brightness = [GREEN, GREEN, GREEN, GREEN, GREEN, GREEN, GREEN, GREEN, ORANGE, RED]

ledbar.write_brightness(0b1111111111,brightness)

for x in range (11):
    if x in (0,):
        ledbar.write_brightness(0b0000000000,brightness)
        sleep(0.3)
    elif x in (1,):
        ledbar.write_brightness(0b1000000000,brightness)
        sleep(0.3)
    elif x in (2,):
        ledbar.write_brightness(0b1100000000,brightness)
        sleep(0.3)
    elif x in (3,):
        ledbar.write_brightness(0b1110000000,brightness)
        sleep(0.3)
    elif x in (4,):
        ledbar.write_brightness(0b1111000000,brightness)
        sleep(0.3)
    elif x in (5,):
        ledbar.write_brightness(0b1111100000,brightness)
        sleep(0.3)
    elif x in (6,):
        ledbar.write_brightness(0b1111110000,brightness)
        sleep(0.3)
    elif x in (7,):
        ledbar.write_brightness(0b1111111000,brightness)
        sleep(0.3)
    elif x in (8,):
        ledbar.write_brightness(0b1111111100,brightness)
        sleep(0.3)
    elif x in (9,):
        ledbar.write_brightness(0b1111111110,brightness)
        sleep(0.3)
    else:
        ledbar.write_brightness(0b1111111111,brightness)
        sleep(0.3)

 

Write message to OLED:

 

pmod_oled.clear()
pmod_oled.write('\n\nPYNQ-Z2 Roadtest')

 

Read Temperature and write to OLED:

 

temperature = tmp.read() - 4.0  # tweak value to reflect actual ambient temp
print(float("{0:.2f}".format(temperature)),'degree Celsius')


pmod_oled.clear()
pmod_oled.write("\n\n Temp: " + str(temperature) + "C")

 

Reset peripherals:

 

ledbar.reset()
pmod_oled.clear()

 

 

A short video showing the notebook operation.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

I haven't quite figured out how to get the correct exposure on my webcam or how to eliminate the OLED flicker, so I captured a few stills that show the results better.

image

image

image

  • Sign in to reply
  • DAB
    DAB over 6 years ago

    Nice update.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube