Skip to content

Commit 4d704b7

Browse files
committed
Technical review of RPi5 smart home LP
1 parent 0dc2d86 commit 4d704b7

File tree

18 files changed

+364
-450
lines changed

18 files changed

+364
-450
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
title: Overview
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Overview
10+
11+
This Learning Path walks you through deploying an efficient large language model (LLM) locally on the Raspberry Pi 5, powered by an Arm Cortex-A76 CPU. This will allow you to control your smart home using natural language, without relying on cloud services. With rapid advances in Generative AI and the power of Arm Cortex-A processors, you can now run advanced language models directly in your home on the Raspberry Pi 5.
12+
13+
You will create a fully local, privacy-first smart home system that leverages the strengths of Arm Cortex-A architecture. The system can achieve 15+ tokens per second inference speeds using optimized models like TinyLlama and Qwen, while maintaining the energy efficiency that makes Arm processors a good fit for always-on applications.
14+
15+
## Why Arm Cortex-A for Edge AI?
16+
17+
The Raspberry Pi 5's Arm Cortex-A76 processor can manage high-performance computing tasks like AI inference. Key architectural features include:
18+
19+
- The **superscalar architecture** allows the processor to execute multiple instructions in parallel, improving throughput for compute-heavy tasks.
20+
- **128-bit NEON SIMD support** accelerates matrix and vector operations, which are common in the inner loops of language model inference.
21+
- The **multi-level cache hierarchy** helps reduce memory latency and improves data access efficiency during runtime.
22+
- The **thermal efficiency** enables sustained performance without active cooling, making it ideal for compact or always-on smart home setups.
23+
24+
These characteristics make the Raspberry Pi 5 well-suited for workloads like smart home assistants, where responsiveness, efficiency, and local processing are important. Running LLMs locally on Arm-based devices brings several practical benefits. Privacy is preserved, since conversations and routines never leave the device. With optimized inference, the system can offer responsiveness under 100 ms, even on resource-constrained hardware. It remains fully functional in offline scenarios, continuing to operate when internet access is unavailable. Developers also gain flexibility to customize models and automations. Additionally, software updates and an active ecosystem continue to improve performance over time.
25+
26+
## Arm Ecosystem Advantages
27+
28+
For the stack in this setup, Raspberry Pi 5 benefits from the extensive developer ecosystem:
29+
30+
- Optimized compilers including GCC and Clang with Arm-specific enhancements
31+
- Native libraries such as gpiozero and lgpio are optimized for Raspberry Pi
32+
- Community support from open-source projects where developers are contributing Arm-optimized code
33+
- Arm maintains a strong focus on backward compatibility, which reduces friction when updating kernels or deploying across multiple Arm platforms
34+
- The same architecture powers smartphones, embedded controllers, edge devices, and cloud infrastructure—enabling consistent development practices across domains
35+
36+
## Performance Benchmarks on Raspberry Pi 5
37+
38+
The table below shows inference performance for several quantized models running on a Raspberry Pi 5. Measurements reflect single-threaded CPU inference with typical prompt lengths and temperature settings suitable for command-based interaction.
39+
40+
| Model | Tokens/Sec | Avg Latency (ms) |
41+
| ------------------- | ---------- | ---------------- |
42+
| qwen:0.5b | 17.0 | 8,217 |
43+
| tinyllama:1.1b | 12.3 | 9,429 |
44+
| deepseek-coder:1.3b | 7.3 | 22,503 |
45+
| gemma2:2b | 4.1 | 23,758 |
46+
| deepseek-r1:7b | 1.6 | 64,797 |
47+
48+
49+
What does this table tell us? Here are some performance insights:
50+
51+
- Qwen 0.5B and TinyLlama 1.1B deliver fast token generation and low average latency, making them suitable for real-time interactions like voice-controlled smart home commands.
52+
- DeepSeek-Coder 1.3B and Gemma 2B trade off some speed for improved language understanding, which can be useful for more complex task execution or context-aware prompts.
53+
- DeepSeek-R1 7B offers advanced reasoning capabilities with acceptable latency, which may be viable for offline summarization, planning, or low-frequency tasks.
54+
55+
## Supported Arm-Powered Devices
56+
57+
This Learning Path focuses on the Raspberry Pi 5, but you can adapt the concepts and code to other Arm-powered devices:
58+
59+
### Recommended Platforms
60+
61+
| Platform | CPU | RAM | GPIO Support | Model Size Suitability |
62+
|------------------|----------------------------------|----------------|-------------------------------|-----------------------------|
63+
| **Raspberry Pi 5** | Arm Cortex-A76 quad-core @ 2.4GHz | Up to 16GB | Native `lgpio` (high-performance) | Large models (8–16GB) |
64+
| **Raspberry Pi 4** | Arm Cortex-A72 quad-core @ 1.8GHz | Up to 8GB | Compatible with `gpiozero` | Small to mid-size models |
65+
| **Other Arm Devices** | Arm Cortex-A | 4GB min (8GB+ recommended) | Requires physical GPIO pins | Varies by RAM |
66+
67+
Additionally, the platform must:
68+
69+
- GPIO pins available for hardware control
70+
- Use Python 3.8 or newer
71+
- Ability to run [Ollama](https://ollama.com/)
72+
73+
Continue to the next section to start building a smart home system that highlights how Arm-based processors can enable efficient, responsive, and private AI applications at the edge.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Set up software dependencies
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
{{% notice Note %}}
10+
This guide assumes you have set up your Raspberry Pi with Raspberry Pi OS and network connectivity. For Raspberry Pi 5 setup help, see: [Raspberry Pi Getting Started](https://www.raspberrypi.com/documentation/)
11+
{{% /notice %}}
12+
13+
## Connect to Your Raspberry Pi 5
14+
15+
### Option 1: Using a display
16+
17+
The easiest way to work on your Raspberry Pi is connecting it to an external display through one of the micro HDMI ports. This setup also requires a keyboard and mouse to navigate.
18+
19+
### Option 2: Using SSH
20+
21+
You can also use SSH to access the terminal. To use this approach you need to know the IP address of your device. Ensure your Raspberry Pi 5 connects to the same network as your host computer. Access your device remotely via SSH using the terminal or any SSH client.
22+
23+
Replace `<user>` with your Pi's username (typically `pi`), and `<pi-ip>` with your Raspberry Pi 5's IP address.
24+
25+
```bash
26+
ssh <user>@<pi-ip>
27+
```
28+
29+
## Set up the dependencies
30+
31+
Create a directory called `smart-home` in your home directory and navigate into it:
32+
33+
```bash
34+
mkdir $HOME/smart-home
35+
cd $HOME/smart-home
36+
```
37+
38+
The Raspberry Pi 5 includes Python 3 pre-installed, but you need additional packages:
39+
40+
```bash
41+
sudo apt update && sudo apt upgrade
42+
sudo apt install python3 python3-pip python3-venv git curl build-essential gcc python3-lgpio
43+
```
44+
45+
### Configure the virtual environment
46+
47+
The next step is to create and activate a Python virtual environment. This approach keeps project dependencies isolated and prevents conflicts with system-wide packages:
48+
49+
```bash
50+
python3 -m venv venv
51+
source venv/bin/activate
52+
```
53+
54+
Install all required libraries and dependencies:
55+
56+
```bash
57+
pip install ollama gpiozero lgpio psutil httpx orjson numpy fastapi uvicorn uvloop numpy
58+
```
59+
60+
### Install Ollama
61+
62+
Install Ollama using the official installation script for Linux:
63+
64+
```bash
65+
curl -fsSL https://ollama.com/install.sh | sh
66+
```
67+
68+
Verify the installation:
69+
70+
```bash
71+
ollama --version
72+
```
73+
If installation was successful, the output from the command should match that below.
74+
```output
75+
ollama version is 0.11.4
76+
```
77+
78+
## Download and Test a Language Model
79+
80+
Ollama supports various models. This guide uses deepseek-r1:7b as an example, but you can also use `tinyllama:1.1b`, `qwen:0.5b`, `gemma2:2b`, or `deepseek-coder:1.3b`.
81+
82+
The `run` command will set up the model automatically. You will see download progress in the terminal, followed by the interactive prompt when ready.
83+
84+
```bash
85+
ollama run deepseek-r1:7b
86+
```
87+
88+
{{% notice Troubleshooting %}}
89+
If you run into issues with the model download, here are some things to check:
90+
91+
- Confirm internet access and sufficient storage space on your microSD card
92+
- Try downloading smaller models like `qwen:0.5b` or `tinyllama:1.1b` if you encounter memory issues. 16 GB of RAM is sufficient for running smaller to medium-sized language models. Very large models may require more memory or run slower.
93+
- Clear storage or connect to a more stable network if errors occur
94+
{{% /notice %}}
95+
96+
With the model set up through `ollama`, move on to the next section to start configuring the hardware.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Test GPIO pins
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
The next step is to test the GPIO functionality. In this section, you will configure a LED light to simulate a smart-home device.
10+
11+
## Verify GPIO Functionality
12+
13+
Bring out your electronics components. Connect the anode (long leg) of an LED in series with a 220Ω resistor to GPIO 17 (physical pin 11). Connect the cathode (short leg) to a ground (GND) pin. See image below for the full setup:
14+
15+
![Raspberry Pi connected to a breadboard with a green LED and jumper wires](pin_layout.jpg "Raspberry Pi connected to a breadboard with a green LED and jumper wires")
16+
17+
Create a Python script named `testgpio.py`:
18+
19+
```bash
20+
cd $HOME/smart-home
21+
vim testgpio.py
22+
```
23+
24+
Copy this code into the file:
25+
26+
```python
27+
#!/usr/bin/env python3
28+
import time
29+
from gpiozero import Device, LED
30+
from gpiozero.pins.lgpio import LGPIOFactory
31+
32+
# Set lgpio backend for Raspberry Pi 5
33+
Device.pin_factory = LGPIOFactory()
34+
35+
# Setup GPIO pin 17
36+
pin1 = LED(17)
37+
38+
try:
39+
while True:
40+
pin1.toggle() # Switch pin 17 state
41+
time.sleep(2) # Wait 2 seconds
42+
except KeyboardInterrupt: # Ctrl+C pressed
43+
pin1.close() # Clean up pin 17
44+
```
45+
46+
Run the script:
47+
48+
```bash
49+
python testgpio.py
50+
```
51+
52+
The LED should blink every two seconds. If you observe this behavior, your GPIO setup works correctly.
53+
54+
{{% notice Troubleshooting %}}
55+
If you run into issues with the hardware setup, here are some things to check:
56+
- Try fixing missing dependencies by running the following command:
57+
```bash
58+
sudo apt-get install -f
59+
```
60+
- If you're running into GPIO permission issues, run Python scripts with `sudo` or add your user to the `gpio` group. Don't forget to log out for the changes to take effect.
61+
```bash
62+
sudo usermod -a -G gpio $USER
63+
```
64+
- Double-check wiring and pin numbers using the Raspberry Pi 5 pinout diagram
65+
- Ensure proper LED and resistor connections
66+
- Verify GPIO enablement in `raspi-config` if needed
67+
- Use a high-quality power supply
68+
{{% /notice %}}
69+
70+
With a way to control devices using GPIO pins, you can move on to the next section to interact with them using language models and the user interface.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: Smart Home Assistant
3+
weight: 5
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
## About the assistant
9+
10+
In this section, you will run the assistant through the `smart_home_assistant.py` script. It initializes all configured smart devices on specific GPIO pins and starts a local web server for interacting with the assistant. The script processes user commands using a local language model (via Ollama), parses the model’s JSON output, and executes actions such as toggling lights or locking doors. It supports both terminal and web-based control.
11+
12+
The assistant is available on GitHub. Clone the code and navigate to the project directory:
13+
14+
```bash
15+
git clone https://github.com/fidel-makatia/EdgeAI_Raspi5.git
16+
cd EdgeAI_Raspi5
17+
```
18+
19+
## Connect further hardware
20+
21+
In the previous section, you configured a LED on GPIO pin 17. The smart home assistant is by default associating this with a `living_room_light` device. The single LED setup is enough to run through this Learning Path. If you'd like to connect actual devices, or play with more mock sensors, the default configuration looks like the table below. You can repeat the steps on the previous page to verify the hardware setup on the different GPIO pins. See the image below for an example.
22+
23+
| Device Name | GPIO Pin | Type | Room |
24+
| ----------------- | -------- | --------- | ----------- |
25+
| living_room_light | 17 | LIGHT | living_room |
26+
| living_room_fan | 27 | FAN | living_room |
27+
| smart_tv | 22 | SMART_TV | living_room |
28+
| bedroom_light | 23 | LIGHT | bedroom |
29+
| bedroom_ac | 24 | AC | bedroom |
30+
| kitchen_light | 5 | LIGHT | kitchen |
31+
| front_door_lock | 26 | DOOR_LOCK | entrance |
32+
| garden_light | 16 | LIGHT | outdoor |
33+
34+
{{% notice Note %}}
35+
The code uses gpiozero with lgpio backend for Raspberry Pi 5 compatibility. You can use compatible output devices such as LEDs, relays, or small loads connected to these GPIO pins to represent actual smart home devices. All pin assignments are optimized for the Raspberry Pi 5's GPIO layout.
36+
{{% /notice %}}
37+
38+
![Raspberry Pi connected to breadboard with LEDs, buttons, and a sensor module](hardware.jpeg "Setup that includes a blue LED (mapped to Living Room Light on GPIO 17), a red LED, push button, and a sensor module. This setup illustrates a simulated smart home with controllable devices.")
39+
40+
41+
## Run the Smart Home Assistant
42+
43+
Run the assistant in different modes depending on your use case. The default model is `deepseek-coder:1.3b`:
44+
45+
{{< tabpane code=true >}}
46+
{{< tab header="Default (Web API + CLI)" language="bash">}}
47+
python3 smart_home_assistant.py
48+
{{< /tab >}}
49+
{{< tab header="Specify model" language="bash">}}
50+
python3 smart_home_assistant.py --model qwen:0.5b
51+
{{< /tab >}}
52+
{{< tab header="Custom web port" language="bash">}}
53+
python3 smart_home_assistant.py --port 8080
54+
{{< /tab >}}
55+
{{< tab header="CLI only" language="bash">}}
56+
python3 smart_home_assistant.py --no-api
57+
{{< /tab >}}
58+
{{< /tabpane >}}
59+
60+
### Command Options
61+
62+
| Option | Description | Example |
63+
|------------------|---------------------------------------------------------------------------------------------------|--------------------------------------------|
64+
| `--model` | Specify the model to use with Ollama | `--model tinyllama:1.1b` |
65+
| `--port` | Run the web server on a custom port (default: `8000`) | `--port 8080` |
66+
| `--no-api` | Disable the web API and run in CLI-only mode
67+
68+
If everything is set up correctly, you should see the following output on running the default command:
69+
70+
![Running in Default Mode](cmd.png "Running the code in default mode")
71+
72+
## Interact With Your Assistant
73+
74+
Try asking the assistant to `turn on living room light`. If you've connected additional devices, come up with prompts to test the setup.
75+
76+
### Web interface
77+
78+
Open your browser and navigate to `http://0.0.0.0:8000`, or as printed in the terminal output.
79+
80+
![Web Interface Interaction](UI3.png "Interacting with the LLM through the web interface")
81+
82+
83+
### Command line interface
84+
85+
Type commands directly in the terminal.
86+
87+
Sample commands:
88+
89+
```bash
90+
turn on living room light
91+
I want to watch my favorite show
92+
its getting late, secure the house
93+
```
94+
95+
![DeepSeek-Coder Interaction](gemma2.png "Interacting with deepseek-coder:1.3b")
96+
97+
{{% notice Troubleshooting %}}
98+
If you're running into issues with the assistant, here are some things to check:
99+
- Make sure your virtual environment is activated and that you installed all the packages from previous sections
100+
- For model loading problems, check if Ollama is running and list available models:
101+
```bash
102+
ollama list
103+
ollama serve
104+
```
105+
- If port 8000 is unavailable, run the assistant with a different port using the `--port` flag.
106+
{{% /notice %}}
107+
108+
## Wrapping up
109+
110+
From here, you can modify the `smart_home_assistant.py` and extend the system by adding more devices, experimenting with conversational commands, or integrating sensors and automation logic into your smart home setup.
111+
112+
You should now know more about setting up a Raspberry Pi 5 to control real-world devices using GPIO pins, and running a smart home assistant powered by local language models through Ollama. You’ve learned how to wire basic circuits with LEDs and resistors to simulate smart devices, and how to launch and interact with the assistant through both the command-line interface and a web dashboard. Along the way, you also explored common troubleshooting steps for GPIO access, missing dependencies, and model loading issues.
113+

0 commit comments

Comments
 (0)