Raspberry Pi 5 CAN Bus Examples
Complete Raspberry Pi 5 code examples for UIROBOT products — CAN bus control via UIM2523 gateway using Visual Studio + Visual GDB cross-compilation.
This page provides **Raspberry Pi 5** example projects for controlling UIROBOT motors via CAN bus using the **UIM2523** Ethernet-to-CAN gateway and **Visual Studio + Visual GDB** cross-compilation environment.
> **Note**: For Raspberry Pi 4 examples, see the [Raspberry Pi 4 CAN Bus Examples](/docs/raspberry-pi-examples) page.
---
## Quick Selection
| Connection Method | Compatible Products | Docs |
|-----------------|-------------------|------|
| **UIM2523 Ethernet → CAN Bus** | UIM342 (32-bit, dual motors) | [AN250814] |
| **UIM2523 Ethernet → CAN Bus** | UIM342 (64-bit, dual motors) | [AN250813] |
---
## Background
This document describes the installation and configuration of the development environment using **Visual Studio** and the **Visual GDB** plug-in for cross-compiling C++ code on a Windows PC and deploying it to a Raspberry Pi 5.
The Raspberry Pi 5, Windows computer, and UIM2523 gateway must be on the same network segment and connected via a network switch.
### Key Network Configuration
| Device | IP Address | Notes |
|--------|-----------|-------|
| UIM2523 Gateway | 192.168.1.254 | Default IP |
| Raspberry Pi 5 | 192.168.1.16 | Wired Ethernet port |
| Windows PC | 192.168.1.xxx | Same subnet |
| UIM342 Motor 1 | Node ID: 11 | Configured in code |
| UIM342 Motor 2 | Node ID: 12 | Configured in code |
---
## Required Hardware
| Item | Qty | Description |
|------|:---:|-------------|
| Raspberry Pi 5 | 1 | Single-board computer |
| UIM2523 | 1 | Ethernet-to-CAN gateway (IP: 192.168.1.254) |
| UIM342 Series Motor | 2 | CAN bus smart motor (Node IDs: 11, 12) |
| 24V DC Power Supply | 1 | For motors and gateway |
| Network Switch | 1 | Industrial Ethernet switch |
| Ethernet Cables | 3 | For connecting all devices |
| Windows PC | 1 | For development (Visual Studio) |
---
## Wiring
```
Windows PC Network Switch Raspberry Pi 5
+--------------+ +-----------+ +----------------+
| Visual Studio|-------| |-------| SSH / Remote |
| + Visual GDB | | Ethernet | | (192.168.1.16) |
+--------------+ | Switch | +----------------+
| |
+-----+-----+
|
+--------+--------+
| |
+------v------+ +------v------+
| UIM2523 | | UIM2523 |
| (optional 2)| | (1 unit) |
| | |192.168.1.254|
+------+------+ +------+------+
| |
| CAN Bus (twisted pair)
| |
| +-----+-----+
| | 120 Ohm |
| | Terminator|
| +-----+-----+
| |
| +----v----+ +----v----+
| |UIM342 | |UIM342 |
| |Node ID:11| |Node ID:12|
| +---------+ +---------+
| | |
| 24V DC Power Supply |
+--------------------------------+
```
---
## Software Installation
### Step 1 — Install Visual Studio
1. Visit: [visualstudio.microsoft.com](https://visualstudio.microsoft.com/)
2. Download and install **Visual Studio** (Community edition is free)
3. During installation, select **Desktop development with C++**
### Step 2 — Install Visual GDB
Visual GDB is a Visual Studio extension for cross-platform and embedded development. It supports Linux platform development and provides cross-compilers and debugging tools.
1. Visit: [visualgdb.com](https://visualgdb.com/)
2. Download and install the package **(Visual Studio must be installed first)**
3. Trial period: 30 days (purchase license for continued use)
### Step 3 — Install MobaXterm (Optional)
MobaXterm is a remote computing toolbox for Windows, useful for SSH access to the Raspberry Pi.
1. Visit: [mobaxterm.mobatek.net](https://mobaxterm.mobatek.net/)
2. Download and install
---
## Sample Code
### Download Links
| Application Note | Description | Download |
|-----------------|-------------|----------|
| AN250814 | UIM342 console control — 32-bit | [Download](https://www.uirobot.com/uploads/files/RasPI5_X32_Cpp_UIM342_Console_AN250814.zip) |
| AN250813 | UIM342 console control — 64-bit | [Download](https://www.uirobot.com/uploads/files/RasPI5_X64_Cpp_UIM342_Console_AN250813.zip) |
> **Note**: The actual sample code is provided in the ZIP files above. The code snippet illustrates the general structure using UDP communication with the UIM2523 gateway.
---
## Step-by-Step Setup
### Step 1 — Connect Hardware
1. Connect all devices to the network switch via Ethernet cables
2. Wire CANH/CANL between UIM2523 and UIM342 motors
3. Connect 24V DC power supply
4. **Double-check all wiring before powering on**
### Step 2 — Configure Network
Ensure all devices are on the same subnet (192.168.1.xxx):
- UIM2523: **192.168.1.254** (default)
- Raspberry Pi 5: **192.168.1.16** (wired Ethernet)
- Windows PC: **192.168.1.xxx**
### Step 3 — Unzip Sample Code
Unzip the downloaded demo file. You will find both 32-bit and 64-bit Visual Studio project folders:
```
Example_Raspi5/
├── RasPI5_X32_Cpp_UIM342_Console_AN250814/ # 32-bit version
│ └── RasPI5_X32_UIM342_Console.sln
└── RasPI5_X64_Cpp_UIM342_Console_AN250813/ # 64-bit version
└── RasPI5_X64_UIM342_Console.sln
```
### Step 4 — Open the Project in Visual Studio
1. Launch Visual Studio
2. Open the solution file (`.sln`) matching your architecture:
- 32-bit: `RasPI5_X32_UIM342_Console.sln`
- 64-bit: `RasPI5_X64_UIM342_Console.sln`
3. The Visual GDB project will automatically load
### Step 5 — Configure Visual GDB Connection
1. In Visual Studio, open **Visual GDB → Project Properties**
2. Configure the connection to your Raspberry Pi 5:
- Host: **192.168.1.16**
- Username: **root** (default)
- Password: **root** (default)
3. Ensure the Raspberry Pi is powered on and connected to the network
4. Click **Test Connection** to verify
:::tip
The username and password can be customized. It is recommended to change the username and password to match your local Raspberry Pi configuration and use root privileges.
:::
### Step 6 — Compile the Code
1. In Visual Studio, select the appropriate build configuration (Release/Debug)
2. Click **Build → Build Solution** (or press F7)
3. Visual GDB will cross-compile the code and deploy it to the Raspberry Pi
4. Verify no compilation errors
### Step 7 — Run the Code
1. In Visual Studio, press **F5** to start debugging, or **Ctrl+F5** to run without debugging
2. The console output will display in the Visual Studio output window
3. The UIM342 motors should begin moving according to the programmed commands
---
## Additional Tips
- **Node ID Management**: Ensure each motor has a unique Node ID. Configure Motor 1 as ID 11 and Motor 2 as ID 12.
- **Network**: All devices must be on the same subnet (192.168.1.xxx).
- **Raspberry Pi Login**: The default credentials are root/root. Change these for security in production environments.
- **Visual GDB License**: The software can be used for 30 days on a trial basis, after which a license purchase is required.
---
## Download All Sample Codes
| Application Note | Description | Download Link |
|-----------------|-------------|---------------|
| AN250814 | UIM342 console — 32-bit (Raspberry Pi 5) | [Download ZIP](https://www.uirobot.com/uploads/files/RasPI5_X32_Cpp_UIM342_Console_AN250814.zip) |
| AN250813 | UIM342 console — 64-bit (Raspberry Pi 5) | [Download ZIP](https://www.uirobot.com/uploads/files/RasPI5_X64_Cpp_UIM342_Console_AN250813.zip) |
---
## Related Documents
- [UIROBOT Code Examples Overview](/docs/code-examples-overview)
- [Raspberry Pi 4 CAN Bus Examples](/docs/raspberry-pi-examples)
- [UIM342 CAN Bus Motor Controller](/docs/uim342)
- [UIM2523 Ethernet to CAN Gateway](/docs/uim2523)
- [Quick Start Guide](/docs/quick-start)
---
*Last updated: 2026-06-25 | Based on Application Notes AN250813, AN250814*