Edge computing changes how we run AI models by moving the processing closer to where the data is created. This helps cut down on delays (latency) and keeps more data private.

Google's Coral Edge TPU (Tensor Processing Unit) is a small, specialized chip made to speed up AI tasks on edge devices. It's designed to run TensorFlow Lite models very efficiently, performing up to 4 trillion operations per second (4 TOPS) while using only about 2 watts of power. That makes it ideal for devices that need to run AI models in real time without draining too much energy.

In this codelab, you'll learn how to set up and use the Coral Edge TPU with Viam to perform real-time computer vision inference. By the end, you'll have a working system that can classify objects using a webcam - all running efficiently at the edge!

computer vision service showing classification

What You'll Build

technical diagram with components and data flow

Prerequisites

What You'll Learn

What You'll Need

The Raspberry Pi boots from a microSD card. You need to install Raspberry Pi OS on the microSD card that you will use with your Pi. For more details about alternative methods of setting up your Raspberry Pi, refer to the Viam docs.

Install Raspberry Pi OS

  1. Connect the microSD card to your computer.
  2. Download the Raspberry Pi Imager and launch it. raspberry pi imager
  3. Click CHOOSE DEVICE. Select your model of Pi, which is Raspberry Pi 4.
  4. Click CHOOSE OS. Select Raspberry Pi OS (64-bit) from the menu.
  5. Click CHOOSE STORAGE. From the list of devices, select the microSD card you intend to use in your Raspberry Pi. raspberry pi image with OS selected
  6. Configure your Raspberry Pi for remote access. Click Next. When prompted to apply OS customization settings, select EDIT SETTINGS.
  7. Check Set hostname and enter the name you would like to access the Pi by in that field, for example, coral-pi.
  8. Select the checkbox for Set username and password and set a username (for example, your first name) that you will use to log into the Pi. If you skip this step, the default username will be pi (not recommended for security reasons). And specify a password.
  9. Connect your Pi to Wi-Fi so that you can run viam-server wirelessly. Check Configure wireless LAN and enter your wireless network credentials. SSID (short for Service Set Identifier) is your Wi-Fi network name, and password is the network password. Change the section Wireless LAN country to where your router is currently being operated. raspberry pi imager standard settings
  10. Select the SERVICES tab, check Enable SSH, and select Use password authentication. raspberry pi imager ssh settings
  11. Save your updates, and confirm YES to apply OS customization settings. Confirm YES to erase data on your microSD card. You may also be prompted by your operating system to enter an administrator password. After granting permissions to the Imager, it will begin writing and then verifying the Linux installation to your microSD card.
  12. Remove the microSD card from your computer when the installation is complete.

Connect with SSH

  1. Place the microSD card into your Raspberry Pi and boot the Pi by plugging it in to an outlet. A red LED will turn on to indicate that the Pi is connected to power.
  2. Once the Pi is started, connect to it with SSH. From a command line terminal window, enter the following command. The text in <> should be replaced (including the < and > symbols themselves) with the user and hostname you configured when you set up your Pi.
    ssh <USERNAME>@<HOSTNAME>.local
    
  3. If you are prompted "Are you sure you want to continue connecting?", type "yes" and hit enter. Then, enter the password for your username. You should be greeted by a login message and a command prompt. ssh session output in a terminal
  4. Update your Raspberry Pi to ensure all the latest packages are installed
    sudo apt update
    sudo apt upgrade -y
    

Configure your machine in Viam

  1. In the Viam app under the LOCATIONS tab, create a machine by typing in a name like "coral-edge" and clicking Add machine. create new machine in Viam app
  2. Click View setup instructions. new, unprovisioned machine in Viam app
  3. To install viam-server on the Raspberry Pi device that you want to use, select the Linux / Aarch64 platform for the Raspberry Pi, and leave your installation method as viam-agent. machine setup instructions in Viam app
  4. Use the viam-agent to download and install viam-server on your Raspberry Pi. Follow the instructions to run the command provided in the setup instructions from the SSH prompt of your Raspberry Pi. viam agent setup script in SSH session
  5. The setup page will indicate when the machine is successfully connected. machine connected successfully

Connect your webcam

  1. Connect the webcam to any USB port on your Raspberry Pi.

Configure your webcam

  1. In the Viam app under the CONFIGURE tab, click the + icon in the left-hand menu and select Component or service. select component or service
  2. Select camera, and find the webcam module. This adds the module for working with a USB webcam. Leave the default name camera-1 for now. add camera component
  3. Notice adding this component adds the webcam hardware component called camera-1. new camera component in configuration
  4. From the Configure section of the panel, switch to the JSON configuration mode using the {} icon in the top-right: switch configuration mode
  5. In this mode, configure your component with the following JSON in the CONFIGURE field. This will tell the component to look for the default camera connected to the device, which will be the USB webcam.
    {
      "video_path": ""
    }
    
    set the blank video path
  6. Click Save in the top right. This may take a moment to apply your configuration changes.
  7. At the bottom of the camera-1 panel, expand the TEST section to ensure you have configured the camera properly and see a video feed. Test camera feed

Now, let's add the Coral ML model service to our machine. This will let us run optimized neural networks using the Edge TPU.

Add the ML model service

  1. In the Viam app under the CONFIGURE tab, click the + icon in the left-hand menu and select Component or service.
  2. Select ML Model, and find the joyce:mlmodel:coral module. This adds the module for running optimized neural networks with the Coral Edge TPU. Leave the default name mlmodel-1 for now. find coral ML model serviceadd coral ML model service
  3. Notice adding this service adds the ML model service called mlmodel-1. new ML model service
  4. In the new mlmodel-1 panel, configure your service with the following JSON in the JSON configuration section:
    {
      "model_name": "mobilenet_v1_1.0_224",
      "task_type": "classification"
    }
    
    This tells the ML model service to use the pre-trained MobileNet V2 model optimized for the Edge TPU for classification.
  5. Click Save in the top right to save and apply your configuration changes. This may take a few minutes to set up the required dependencies. If you want to follow along with the progress, look under the LOGS tab.
  6. Once the robot has successfully reconfigured, expand the TEST panel of mlmodel-1 to review information about the ML model serrvice. test ML model service

Now, let's add a vision service that will use our ML model to perform object classification on images from the webcam.

Add the vision service

  1. In the Viam app under the CONFIGURE tab, click the + icon in the left-hand menu and select Component or service.
  2. Select vision, and find the ML Model module. This adds a vision service that uses ML models. Leave the default name vision-1 for now. Add vision serviceAdd vision service that uses ml models
  3. Notice adding this service adds the vision service called vision-1. new vision service
  4. In the ML Model section of the panel, select your ML model service (mlmodel-1).
  5. In the Default Camera section of the panel, select your camera (camera-1).
  6. Set the confidence level to 0.5 to reduce the amount of false positive detections. configure vision service
  7. Click Save in the top right to save and apply your configuration changes.
  8. At the bottom of the vision-1 panel, expand the TEST section.
  9. You should see the video feed from your camera with a list of detected objects on the right-side of the panel. The model will detect what it sees in the camera's field of view, showing confidence scores for object classification. Test vision service
  10. Try holding different objects in front of the camera to see how well the model identifies them!

Congratulations! 🎉 You've successfully built an edge AI system that runs optimized computer vision models on a Google Coral Edge TPU. This setup allows you to perform real-time object classification with minimal latency and power consumption - all without requiring cloud connectivity or powerful hardware.

What You Learned

technical diagram with components and data flow

Why edge AI matters

Edge AI is transforming how we build intelligent systems by:

Next steps

Here are some ways to extend your project:

Exploring other edge AI options

The Coral TPU excels at efficient inference for supported model architectures. Depending on your specific requirements, you might also consider:

Each option has different performance characteristics, model support, and integration requirements.

Related resources