# Raspberry Pi Setup Guide

> ⚠️ **Audience:** This guide is written for complete beginners. No prior experience with coding, electronics, or Raspberry Pi is required.

***

### Introduction

Welcome to the official SMD Red Robot Guide using Raspberry Pi. This document will walk you through every single step required to:

* Set up your computer environment
* Assemble your robot and connect Raspberry Pi and SMD Red hardware
* Program and test your robot using Python code and a web interface

By following this guide step by step, you'll successfully build a fully functional smart robot that can:

* Drive using DC motors
* Rotate pan/tilt servos
* Detect objects using sensors
* Be controlled via Wi-Fi through a mobile or web app

***

### 1. User PC Setup

Before configuring the robot itself, your computer must be ready to write, edit, and transfer code to the Raspberry Pi.

#### 1.1 Install Python

* Visit: [https://www.python.org](https://www.python.org/)
* Download the latest version compatible with your operating system.
* During installation, make sure to enable **“Add Python to PATH”**.
* After installation, verify Python works by opening a terminal/powershell and running:

```bash
python --version
```

Expected output: `Python 3.x.x`

#### 1.2 Install acrome-smd Library

This library allows you to write Python programs that talk to the SMD Red hardware.

```bash
pip install acrome-smd
```

> 💡 Run this on both your **PC** and **Raspberry Pi** later. This step ensures compatibility and development flexibility.

#### 1.3 (Optional) Install Visual Studio Code

Recommended if you want a user-friendly interface for writing Python code.

* Download from: [https://code.visualstudio.com](https://code.visualstudio.com/)

#### 1.4 Install Raspberry Pi Imager

This tool lets you install the operating system onto the Raspberry Pi’s SD card.

* Download from: <https://www.raspberrypi.com/software>
* We will use this in the next step to flash Raspberry Pi OS.

***

### 2. Robot Assembly + Raspberry Pi Setup

#### 2.1 Required Hardware

Here’s everything you’ll need physically:

* Raspberry Pi 3B+
* MicroSD card (16GB or larger)
* [USB Gateway Module ](https://docs.acrome.net/electronics/gateway-modules/usb-gateway-module)(USB-A on one end, RJ11 port on the other)
* 1–2x SMD Red Drivers
* 2x [DC motors](https://docs.acrome.net/electronics/electrical-motors/brushed-dc-motors-bdc) with wheels (for driving)
* 2x [Servo motors ](https://docs.acrome.net/electronics/add-on-modules/servo-module)(for pan/tilt)
* 1x[ Ultrasonic sensor](https://docs.acrome.net/electronics/add-on-modules/ultrasonic-distance-sensor-module) (distance measurement)
* RJ11 cables: To daisy-chain SMD Red modules and connect Gateway
* RJ45 cables: To connect modules (e.g., motors/servos) to SMD Red
* 12V power supply: Powers SMD Red and motor modules
* 5V USB-C: Powers the Raspberry Pi
* Screws, jumper wires, zip ties: For physical mounting and wiring

#### 2.2 Wiring Overview

* USB-A from USB Gateway → Raspberry Pi USB port
* RJ11 from USB Gateway → SMD Red 0 RJ11 IN
* RJ11 SMD Red 0 → SMD Red 1 → SMD Red 2 (daisy-chained)
* Power connectio&#x6E;**:** Each SMD Red unit requires a separate **power-to-power cable** connection for power supply.
* RJ45 from SMD Red to DC motor, servo, sensor modules

> 🧠 **RJ11 cables** carry communication between controller boards (SMD Reds), and between the Gateway and first SMD Red.\
> 🧠 **RJ45 cables** carry signals and power to individual hardware modules.

#### 2.3 Flash the OS and Configure Raspberry Pi

* Launch Raspberry Pi Imager
* Select: Raspberry Pi OS (Lite – 64-bit)
* Click the gear icon for Advanced Options:
  * Enable SSH (use password authentication)
  * Set Username: `pi`, Password: `raspberry`
  * Enter your Wi-Fi name and password
  * Set Hostname: `smd-robot`
* Choose SD card and click **Write**
* Safely eject and insert into your Raspberry Pi

#### 2.4 Access Raspberry Pi Terminal

To configure and program your Raspberry Pi, you need terminal access.

**🟢 Option 1: Headless (Preferred)**

No monitor/keyboard required. Access via Wi-Fi.

Steps:

* Power on Raspberry Pi
* From your computer:

```bash
ssh pi@smd-robot.local
```

> If that fails, get your Pi’s IP address from your router and run:

```bash
ssh pi@<your_ip_address>
```

**🔵 Option 2: HDMI + Keyboard**

Plug a monitor and keyboard directly to the Pi.

Steps:

* Power on
* Login with:
  * Username: `pi`
  * Password: `raspberry`
* Open terminal and run:

```bash
sudo raspi-config
```

Use this menu to configure Wi-Fi and hostname manually if needed.

***

### 3. Programming and Code Upload

Once your Pi is online and you have terminal access, you can upload your robot code.

#### 3.1 Update Raspberry Pi and Install Tools

Run these commands:

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install python3-pip hostapd dnsmasq network-manager -y
```

> These install Python tools and network support, required for running and debugging the robot, or enabling offline hotspot.

#### 3.2 Install SMD Red Python Library on Raspberry Pi

```bash
pip install acrome-smd
```

> Needed to communicate with the SMD Red hardware using Python.

#### 3.3 Send Your Python Code from PC to Pi

Use the following command on your computer:

```bash
scp python.py requirements.txt pi@smd-robot.local:/home/pi/
```

> This sends your project files securely to the Pi.

#### 3.4 Install Required Python Libraries

On Raspberry Pi:

```bash
pip install -r requirements.txt --break-system-packages
```

> This includes Flask (for web server), pyserial (for USB communication), and others.

#### 3.5 Set Up Autostart (Optional But Recommended)

If you want your robot to launch automatically on boot:

1. Create a systemd service file:

```bash
sudo nano /etc/systemd/system/run_script.service
```

2. Paste the following:

```ini
[Unit]
Description=SMD Robot Service
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/python.py
WorkingDirectory=/home/pi
User=pi
Group=pi
Restart=always

[Install]
WantedBy=multi-user.target
```

3. Activate the service:

```bash
sudo systemctl daemon-reload
sudo systemctl enable run_script.service
sudo systemctl start run_script.service
```

> Now your robot program will automatically start every time your Raspberry Pi is turned on!

***

### 4. Run and Test Your Robot

#### 4.1 Manual Test

Run your Python script:

```
python3 python.py
```

Expected output:

```
Connected to /dev/ttyUSB0
Flask server running at 0.0.0.0:5000
```

> If you see this, your Pi has found the USB Gateway and is running the robot web server.

#### 4.2 Open Web Control Interface

On your phone or computer browser (same Wi-Fi):

```
http://smd-robot.local:5000
```

You should see:

* 🟢 Buttons to move the robot forward/backward/turn
* 🎛 Sliders to control pan/tilt servos
* 📏 Sensor readout (ultrasonic distance)
* 🔘 Linear motor control (if connected)

***

### 5. Troubleshooting Table ([SMD Red Troubleshooting Guide](https://docs.acrome.net/electronics/smd-red/troubleshooting-guide))

| Problem               | Cause                          | Solution                          |
| --------------------- | ------------------------------ | --------------------------------- |
| USB Gateway not found | Faulty cable or power          | Try different port or cable       |
| No /dev/ttyUSB\*      | USB Gateway not recognized     | Reboot Pi, reinsert device        |
| SMDs unresponsive     | RJ11 cables disconnected       | Ensure cables are seated tightly  |
| Motors don’t move     | Modules not connected via RJ45 | Check RJ45 cables and IDs         |
| Script crash          | Python package missing         | Run pip install again             |
| Web not loading       | Flask not running              | Run script manually or check logs |

***

### 6. Final Checklist

Before moving forward:

* [x] Raspberry Pi configured and connected
* [x] USB Gateway properly plugged into Pi
* [x] RJ11 cables connecting all SMD Red modules
* [x] RJ45 cables linking modules to SMD Red
* [x] Python code copied to Pi and dependencies installed
* [x] Robot script starts manually or automatically
* [x] Web UI reachable via browser

🎉 **Congratulations! You now have a complete robot platform ready to expand and explore!**
