Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Establish UART Communication Between Raspberry Pi 4 and HiFive1 Boards

In this lab you’ll set up reliable UART links between a Raspberry Pi 4 and a HiFive1, program the HiFive1 to echo received data, and create a Python script on the Pi to forward steering angles to the board.

Part 0: Enabling UART on the Raspberry Pi 4

The Pi 4 ships with four UART controllers. For this exercise we’ll use uart2 and uart3. Add the following line to /boot/config.txt and reboot:

dtoverlay=uart2,115200 dtoverlay=uart3,115200

After rebooting, the device nodes /dev/ttyAMA1 (uart2) and /dev/ttyAMA2 (uart3) will be available.

Connect the boards as follows:

From the Pi you can access these channels via /dev/ttyAMA1 (send to HiFive1) and /dev/ttyAMA2 (receive HiFive1 console).

Part 1: Programming the HiFive1

On your PC (not the Pi), download the skeleton project:

$ cd ~/Documents/PlatformIO
$ wget https://ittc.ku.edu/~heechul/courses/eecs388/l10-comm.tar.gz
$ tar zxvf l10-comm.tar.gz

Add the l10-interrupt folder to your VSCode workspace. The goal is to read data from UART1, echo it on UART0, and print the result to the console.

Here’s a concise algorithm:

while (1) {
    if (ser_isready(1)) {
        char data = ser_read(1);
        ser_write(0, data);
        ser_printline(0, "Received: "); /* adjust formatting as needed */
    }
}

The serial API is defined in eecs388_lib.h/c:

void ser_setup(int devid);
int  ser_isready(int devid);
void ser_write(int devid, char c);
void ser_printline(int devid, char *str);
char ser_read(int devid);
int  ser_readline(int devid, int n, char *str);

Remember that devid = 0 selects UART0 and devid = 1 selects UART1. The ser_isready function checks the UART IP register for pending data:

int ser_isready(int devid) {
    uint32_t regval = *(volatile uint32_t *)(UART_ADDR(devid) + UART_IP);
    return regval;
}

After compiling and flashing, switch to the Pi and open two terminals:

Type any string in the sender terminal; the same string should appear in the debug terminal, confirming correct operation.

Part 2: Python Script on the Raspberry Pi 4

Instead of manual terminals, write a Python program that:

Example skeleton using pySerial:

import serial
import time
import cv2  # or your camera interface

# Open serial ports
ser1 = serial.Serial('/dev/ttyAMA1', 115200, timeout=1)
ser2 = serial.Serial('/dev/ttyAMA2', 115200, timeout=1)

while True:
    # Capture frame
    frame = cv2.imread('frame.jpg')  # replace with actual camera read

    # Run DNN inference
    angle = dnn_inference(frame)  # float32

    # Convert float to 4-byte representation
    angle_bytes = angle.to_bytes(4, byteorder='little', signed=True)
    ser1.write(angle_bytes)

    # Optional: read debug output
    debug = ser2.readline().decode().strip()
    if debug:
        print('HiFive1:', debug)

    # Timing control (e.g., 30 fps)
    time.sleep(1/30)

# Clean up
ser1.close()
ser2.close()

Note: Convert the float to bytes before sending, and use the same byte order on the HiFive1 when interpreting the value.

Appendix: Raspberry Pi 4 GPIO and Peripheral Overview

The Pi 4 offers expanded I²C, SPI, and UART interfaces beyond the original Pi models. Use the pinout command to view all pins:

pinout

Key peripherals:

For detailed configuration, consult the official Raspberry Pi documentation: Config‑txt Guide.

Manufacturing process

  1. Understanding Data Flow: From Simplex to Full‑Duplex Communication
  2. Mastering Wireless Communication Range: How Power, Data Rate, and Interference Shape Connectivity
  3. Mastering UART: The Universal Asynchronous Receiver/Transmitter Explained
  4. Seamless MQTT Integration: NodeMCU DHT22 Sensors with Raspberry Pi 3 B+ as Broker
  5. Facilitating Deaf-Blind Communication Using 1Sheeld and Arduino
  6. Python 3 to Arduino UNO: Easy Command Control and LED Demo
  7. Build a Morse Code Transmitter with Arduino – Easy DIY Guide
  8. Master Serial Communication with Arduino – Step-by-Step Video Guide
  9. Enhancing Smart Home Connectivity: Building Truly Intelligent and Autonomous Devices
  10. Arduino Serial Communication: Mastering UART Basics and Troubleshooting