PYNQ Input/Output (I/O)
The PYNQ board has a number of sensors (buttons, switches) and actuators (LEDs), as well as a number of general-purpose input/output (I/O) (GPIO) pins.
The hardware I/O pins include the Rasberry PI and Arduino headers.
- The 4 green LEDs (LD0..LED3) and 2 color LEDs (LD4-5R/G/B) are output pins.
- The buttons (BTN0..BTN3) and switches (SW0..SW1) are input pins.
- The Arduino header contains 14 digital I/O pins (AR0..AR13) that can be individually set to input or output, as well as 6 analog input pins (A0..A5). Two I/O pins (AR_SCL and AR_SDA) are pins for the I2C (Inter-Integrated Circuit) protocol.
- The Raspberry PI header contains 26 I/O pins that can be individually set to input or output. (Some of the pins are hardwired to ground or are not connected, and cannot be routed to/from the switchbox.)
Arduino header
For the purposes of this course only the arduino header will be used in the format displayed bellow:
See pinmap.h
in the libpynq documentation for the Arduino pins (IO_A*
and IO_AR*
).
See Section 17 in the pynq user documentation for more information.
Switchbox
The 5EID0 SD-card image contains a switchbox (see the image at the top of the page) that can be programmed to connect components on the PYNQ board to the hardware input/output pins on the PYNQ board.
pinmap.h
in the libpynq documentation describes which I/O pins are available as input or output to the switchbox.
switchbox.h
in the libpynq documentation describes which hardware modules are available as input or output to the switchbox.
The switchbox can be programmed to set the status of I/O pins to input or output, and to connect the devices to I/O pins. For example, to connect the UART0 RX pin to AR0:
After programming the switchbox, the various sensors, actuators, and communication modules (described next) can be used.
Connectivity board
The connection through WiFi to the MQTT server is provided by the ESP32C3 board shown bellow:
The Status LEDs show whether a WiFi connection has been established and if messages are being transmitted or received.
- If the WiFi led flashes slowly it is connecting to the WiFi.
- If User led is on and the WiFi led flashes quickly it is connecting to MQTT.
- If both the user led and the WiFi LED are solid on, the board is connected to the WiFi and the MQTT server.
- The Tx/Rx LED flashes when a messages is received/transmitted.
This setup is designed to handle complex data processing and communication tasks. The MQTT protocol serves as the foundation of the robots' communication network, ensuring continuous and secure data exchange between ESP and the server. In addition, another type of communication is necessary between the main PYNQ and ESP32C3. In this case, UART protocol is used in the inter-board network. Please refer to the illustration below to understand the overall topology of the system:
ℹ️ Information Each robot has an account on the MQTT server and each team will receive an account for computer connection to the MQTT server.
The uart communication between the PYNQ, the ESP32C3 and back is structured as follow:
- A 32bit unsigned integer that contains the size (in bytes) of the message
- The message with the length specified.
┌──────────┬───────────────────┐
size: │32bit │ (msg size)*8 │
content: │msg size │ Message │
└──────────┴───────────────────┘
The ESP32C3 is connected via to the UART via pin AR0 and AR1. To connect these to the UART use:
Pin AR2,AR3 are also connected to the ESP32C3, they indicate if it ready to accept data (AR3) or if it is transmitting data (AR2).
UART (Universal Asynchronous Receiver-Transmitter) protocol
The ESP boards have already been flashed with the necessary firmware for handling UART input and communicating with the server. As described in the UART library documentation in the libpynq documentation you can send and receive bytes with high-level UART functions.
I2C or IIC (Inter-Integrated Circuit) protocol
IIC is supported on libpynq. As described in the IIC library documentation in the libpynq documentation you can send and receive bytes with high-level IIC functions. The IIC must first be connected to the appropriate I/O pins.
PWM (Pulse-Width Modulation)
As described in the PWM library documentation in the libpynq documentation you can set and get (read) period, duty cycle, and steps for each PWM. The PWM must first be connected to the appropriate LEDs or I/O pins and initialised.
GPIO and Parallel Communication
IO pins can be set to be input or output, and an output pin on one PYNQ board can be directly connected to an input pin on another PYNQ board. (The boards must always be grounded.) See the GPIO library documentation in the libpynq documentation.