> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/autorope/donkeycar/llms.txt
> Use this file to discover all available pages before exploring further.

# Hardware Setup

> Assemble your Donkeycar with the right components and build a functional autonomous RC vehicle

## Overview

Building a Donkeycar requires assembling hardware components on an RC car chassis. This guide covers the recommended components and assembly process.

## Recommended Hardware Components

### Computing Platform

**Raspberry Pi (Recommended)**

* Raspberry Pi 4 (2GB+ RAM recommended)
* Raspberry Pi 3 B+ (minimum)
* Compatible with RaspberryPi OS
* Powers the car's AI and control systems

<Tip>
  The Raspberry Pi is the preferred on-board computer for Donkeycar. If you're new to Raspberry Pi, set it up using [Raspberry Pi Imager](https://www.raspberrypi.com/software/) and familiarize yourself with [raspi-config](https://www.raspberrypi.com/documentation/computers/configuration.html) before building your car.
</Tip>

### Camera Options

Donkeycar supports multiple camera types:

**Raspberry Pi Camera (PICAM)**

* CSI interface camera
* Low latency, reliable
* Most common choice
* Set `CAMERA_TYPE = "PICAM"` in config

**USB Webcam**

* Standard USB camera
* Easy to connect
* Set `CAMERA_TYPE = "WEBCAM"` in config

**Advanced Options**

* **CSIC**: High-speed CSI camera (e.g., Arducam)
* **D435**: Intel RealSense D435 with depth sensing
* **OAKD**: Luxonis OAK-D with depth and IMU
* **CVCAM**: OpenCV-compatible camera

### Motor Controllers

**PCA9685 PWM Driver (Most Common)**

* 16-channel PWM controller
* I2C interface (address typically `0x40`)
* Controls both steering servo and ESC (Electronic Speed Controller)
* Requires calibration of PWM pulse values

**Alternative Controllers**

* **RoboHat MM1**: Integrated controller for Raspberry Pi
* **Direct PWM Pins**: Using Raspberry Pi GPIO
* **PiGPIO**: Hardware PWM using pigpio daemon

### Drive Train Types

Your configuration depends on your chassis:

**Standard RC Car (`PWM_STEERING_THROTTLE`)**

* Steering servo + ESC
* Most common setup
* Typical PWM range: 200-500 (12-bit values)

```python theme={null}
DRIVE_TRAIN_TYPE = "PWM_STEERING_THROTTLE"
```

**Differential Drive (`DC_TWO_WHEEL`)**

* Tank-style steering
* Two motors (left/right)
* Uses H-Bridge motor driver (L298N)

**Other Options**

* `DC_STEER_THROTTLE`: DC motor for steering
* `SERVO_HBRIDGE_2PIN`: Servo + 2-pin H-Bridge
* `SERVO_HBRIDGE_3PIN`: Servo + 3-pin H-Bridge
* `VESC`: VESC motor controller

### Chassis

Recommended RC car platforms:

* **Exceed Desert Monster**: Popular choice
* **Magnet 1/16 Scale Rally Car**: Affordable option
* **Traxxas**: Higher-end, durable
* **Custom 3D-printed chassis**: For advanced users

<Warning>
  Make sure your chassis has enough space for the Raspberry Pi, motor controller, and battery. A 1/10 or 1/16 scale RC car is ideal.
</Warning>

### Additional Components

**Required**

* Power supply (5V for Pi, battery for motors)
* MicroSD card (16GB+ for Pi)
* Jumper wires and connectors

**Optional Sensors**

* **IMU (Inertial Measurement Unit)**: MPU6050 or MPU9250
* **LIDAR**: RP or YD LIDAR for obstacle detection
* **GPS**: For path following
* **Encoders**: For odometry and speed measurement

## Assembly Steps

<Steps>
  ### Prepare the Chassis

  Start with a working RC car:

  1. Test the car with its original radio controller
  2. Remove the receiver (keep the ESC and servo)
  3. Ensure the ESC and servo are working properly

  ### Mount the Raspberry Pi

  1. Use standoffs or 3D-printed mounts
  2. Position for easy access to ports
  3. Ensure camera has clear forward view
  4. Protect from vibration and impacts

  ### Connect the Motor Controller

  **For PCA9685 Setup:**

  1. **Connect I2C to Raspberry Pi**
     * VCC → 5V (Pin 2 or 4)
     * GND → Ground (Pin 6, 9, 14, 20, 25, 30, 34, or 39)
     * SDA → GPIO 2 (Pin 3)
     * SCL → GPIO 3 (Pin 5)

  2. **Connect to Servo/ESC**
     * Channel 0: Typically for throttle (ESC)
     * Channel 1: Typically for steering (servo)

  3. **Provide power to PCA9685**
     * Connect 5-6V to V+ terminal for servo/ESC power
     * Do NOT connect Pi 5V to V+ (they should have separate supplies)

  ### Install the Camera

  **For Raspberry Pi Camera (CSI):**

  1. Connect the ribbon cable to the CSI port on Pi
  2. Mount camera with forward-facing view
  3. Typical mounting height: 10-15cm above ground
  4. Angle slightly downward (about 10-15 degrees)

  ### Wire the Power System

  1. **Raspberry Pi**: Use a stable 5V power supply (recommended: USB-C power bank or DC-DC converter)
  2. **Motors**: Use the RC car's battery (typically 7.4V LiPo)
  3. **PCA9685**: Can be powered from V+ terminal (5-6V)

  <Warning>
    Never connect the motor battery directly to the Raspberry Pi. Use a voltage regulator or separate 5V supply.
  </Warning>

  ### Test Connections

  1. Power on the Raspberry Pi
  2. Verify I2C connection: `i2cdetect -y 1`
  3. Should see PCA9685 at address 0x40
  4. Test camera: `raspistill -o test.jpg`
</Steps>

## Configuration Pin Mappings

### Standard PWM\_STEERING\_THROTTLE Setup

```python theme={null}
PWM_STEERING_THROTTLE = {
    "PWM_STEERING_PIN": "PCA9685.1:40.1",   # Channel 1
    "PWM_STEERING_SCALE": 1.0,
    "PWM_STEERING_INVERTED": False,
    "PWM_THROTTLE_PIN": "PCA9685.1:40.0",   # Channel 0
    "PWM_THROTTLE_SCALE": 1.0,
    "PWM_THROTTLE_INVERTED": False,
    # Values below are set during calibration
    "STEERING_LEFT_PWM": 460,
    "STEERING_RIGHT_PWM": 290,
    "THROTTLE_FORWARD_PWM": 500,
    "THROTTLE_STOPPED_PWM": 370,
    "THROTTLE_REVERSE_PWM": 220,
}
```

### Pin Format Explained

The pin format `"PCA9685.1:40.0"` means:

* `PCA9685`: Controller type
* `1`: I2C bus number
* `40`: I2C address (0x40 in hex)
* `0`: Channel number (0-15)

## Camera Configuration

```python theme={null}
# Camera selection
CAMERA_TYPE = "PICAM"

# Image resolution (affects processing speed)
IMAGE_W = 160
IMAGE_H = 120
IMAGE_DEPTH = 3  # RGB

# Camera orientation
CAMERA_VFLIP = False  # Vertical flip
CAMERA_HFLIP = False  # Horizontal flip

# Frame rate (should match DRIVE_LOOP_HZ)
CAMERA_FRAMERATE = 20
```

## Verifying Your Setup

<Steps>
  ### Check I2C Devices

  ```bash theme={null}
  sudo i2cdetect -y 1
  ```

  Should show the PCA9685 at address 0x40.

  ### Test Camera

  ```bash theme={null}
  # For Pi Camera
  raspistill -o test.jpg

  # For USB camera
  fswebcam test.jpg
  ```

  ### Test Motor Controller

  After creating your car application, test with the calibration tool:

  ```bash theme={null}
  donkey calibrate --channel=0 --bus=1
  ```
</Steps>

## Troubleshooting

**Camera not detected**

* Verify cable connection to CSI port
* Enable camera in `raspi-config`
* Check: `vcgencmd get_camera`

**I2C device not found**

* Enable I2C in `raspi-config`
* Check wiring connections
* Verify 5V power to PCA9685

**Motors not responding**

* Check battery charge
* Verify ESC/servo connections to PCA9685
* Ensure V+ on PCA9685 is powered (5-6V)
* Test with original RC receiver first

**Servo jitters or behaves erratically**

* Add capacitor across PCA9685 power supply
* Check for loose connections
* Verify PWM frequency (typically 60Hz)

## Next Steps

Once your hardware is assembled:

1. [Create your car application](/guides/creating-application) with `donkey createcar`
2. [Calibrate steering and throttle](/guides/calibration)
3. [Start driving and collecting data](/guides/driving)

## Additional Resources

* [Raspberry Pi Documentation](https://www.raspberrypi.com/documentation/)
* [PCA9685 Datasheet](https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf)
* [Donkeycar Discord Community](https://discord.gg/PN6kFeA)
