Configure Raspberry Pi 5 with Coral TPU and POE HAT

alt text

Date: May 2024 - June 1st

Overview

This guide will help you set up a Raspberry Pi 5 with a Google Coral TPU and a POE HAT for Power over Ethernet (PoE) functionality.

Hardware Requirements

Raspberry Pi 5

Coral TPU

Additional Hardware

Review

Hardware

alt text alt text alt text

Raspberry Pi 5

alt text

POE HAT

alt text

Coral TPU HAT

Prerequisites

Configuration Steps

  1. Configure Hardware Settings:
    
    sudo nano /boot/firmware/config.txt
    
    [all]
    # Enable the PCIe External connector.
    dtparam=pciex1
    kernel=kernel8.img
    # Enable Pineboards Hat Ai
    dtoverlay=pineboards-hat-ai
    
    sudo reboot
          
  2. Update Raspberry Pi Kernel and Install Kernel Headers:
    
    sudo apt update
    sudo apt full-upgrade
    
    sudo apt install rpi-update
    
    sudo rpi-update
    sudo reboot
    
    sudo apt install git bc bison flex libssl-dev make libncurses5-dev
    sudo wget https://raw.githubusercontent.com/jgartrel/rpi-source/master/rpi-source -O /usr/bin/rpi-source
    sudo chmod +x /usr/bin/rpi-source
    rpi-source --tag-update
    
    rpi-source --default-config
    uname -a
          
    Expected output:
    
    Linux coralpi 6.6.30-v8+ #1761 SMP PREEMPT Thu May  2 16:54:52 BST 2024 aarch64 GNU/Linux
          
  3. Install PCIe Driver and Edge TPU Runtime:
    
    sudo apt update
    echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
    curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    sudo apt-get update
    curl -sS https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/google.gpg
    echo "deb [signed-by=/usr/share/keyrings/google.gpg] https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
    sudo apt-get update
    sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms
          
  4. Install Gasket Driver:
    
    git clone https://github.com/google/gasket-driver.git
    cd gasket-driver
    sudo debuild -us -uc -tc -b
    cd ..
    sudo dpkg -i gasket-dkms_1.0-18_all.deb
          
  5. Set Up udev Rule:
    
    sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
    sudo groupadd apex
    sudo adduser $USER apex
    sudo reboot
          
  6. Verify Driver and Device:
    
    sudo lspci -v
    ls /dev/apex_0
          
  7. Install Docker:
    
    sudo apt install ca-certificates curl gnupg
    sudo install -m 0755 -d /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    echo "deb [arch=\"\$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \$(. /etc/os-release && echo \"\$VERSION_CODENAME\") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt update
    sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
          
  8. Build a Docker Image for Coral Testing:
    
    Create a Dockerfile:
    FROM debian:10
    
    WORKDIR /home
    ENV HOME /home
    
    RUN cd ~ \
        && apt-get update \
        && apt-get install -y git nano python3-pip python-dev pkg-config wget usbutils curl \
        && echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | tee /etc/apt/sources.list.d/coral-edgetpu.list \
        && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - \
        && apt-get update \
        && apt-get install -y edgetpu-examples
    
    Build the Docker image:
    sudo docker build -t "coral" .
    
    Run the Docker image:
    sudo docker run -it --device /dev/apex_0:/dev/apex_0 coral /bin/bash
    
    In the container, run an Edge TPU example:
    python3 /usr/share/edgetpu/examples/classify_image.py --model /usr/share/edgetpu/examples/models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite --label /usr/share/edgetpu/examples/models/inat_bird_labels.txt --image /usr/share/edgetpu/examples/images/bird.bmp
    
    Expected output:
    Poecile atricapillus (Black-capped Chickadee)
    Score :  0.44140625
    
    Poecile carolinensis (Carolina Chickadee)
    Score :  0.29296875