22. Using OpenClaw to Control PiCar-X

What is OpenClaw?

Think of it as an upgraded version of ChatGPT. While traditional chatbots can only talk (generate text), OpenClaw can take action. It understands your natural language instructions and can actually perform operations on your computer, such as running commands, managing files, and calling various tools.

Here are some fantastic application scenarios:

  • Personal All-around Assistant: Let it help you manage your schedule, set reminders, and track tasks. You just need to tell it in a chat app (like Telegram, WhatsApp), and it will remember and execute.

  • Automation “Glue”: It can act as a binder for your various services. For example, you can have it monitor a website for price changes. Once a price drop is detected, it can automatically trigger an n8n automation workflow to send you an email notification.

  • Dedicated Development Assistant: Have it help you manage servers, run scripts, and check logs. You can simply say, “Check the system load for me,” and it can SSH into your server, execute the command, and return the results.

  • Hardware “Playmate”: This is a very interesting use case. You can have OpenClaw control hardware connected to a Raspberry Pi. For example, a developer used it to control a robotic vacuum cleaner with a mechanical arm, or even had it help analyze racing simulator data and display it on an LED screen. The official Raspberry Pi team even used it to build an automatic photo booth for a wedding, just through conversation, without writing a single line of code!

Important

The Raspberry Pi Zero 2W has only 512MB of RAM, while OpenClaw requires a minimum of 1GB. Therefore, it cannot run properly. A Raspberry Pi 4/5 or higher is recommended.

Quick Start OpenClaw

If you want to experience the power of OpenClaw as quickly as possible, use this method. It will automatically install and launch an interactive setup wizard.

  1. Open the terminal on your Raspberry Pi and run the following command directly. This command downloads the installation script from the official website and executes it:

    curl -fsSL https://openclaw.ai/install.sh | bash
    

    Note

    Because new versions are updated rapidly, it’s normal if your installation steps differ slightly.

  2. The script will automatically download and install OpenClaw.

    _images/install_open_claw.png
  3. You will then see a security prompt asking if you trust OpenClaw. Once you are sure it is safe and reliable, use the arrow keys to navigate to “Yes” and press Enter.

    _images/security_open_claw.png
  4. Select Quick Start, and then press Enter.

    _images/quickstart_open_claw.png
  5. Select your Model, and then press Enter. Here we use OpenAI as an example.

    _images/model_provider_open_claw.png
  6. Select OpenAI API Key.

    _images/api_key_open_claw.png
  7. Paste API key now.

    _images/paste_api_key_open_claw.png
  1. Go to OpenAI Platform and log in. On the API keys page, click Create new secret key.

    _images/llm_openai_create1.png
  2. Fill in the details (Owner, Name, Project, and permissions if needed), then click Create secret key.

    _images/llm_openai_create_confirm1.png
  3. Once the key is created, copy it right away — you won’t be able to see it again. If you lose it, you’ll need to generate a new one.

    _images/llm_openai_copy1.png
  4. Paste the key into the OpenClaw configuration.

    _images/paste_api_key_enter_open_claw.png
  5. Select the Model you want to use. In this example, we will use Keep current.

    _images/model_config_open_claw.png
  6. Next is the channel selection. Channels refer to the communication services supported by OpenClaw, such as Telegram, WhatsApp, Discord, and more. Use the down arrow key to select the “Skip for now” option, then press Enter.

    _images/channel_open_claw.png
  7. Next, you will be prompted to configure skills immediately. Select “Yes” and press Enter.

    _images/config_skill_open_claw.png
  8. Install the skills you need. In the following example, we select the “Skip for now” option (press the spacebar to select), then press Enter.

    _images/install_skill_open_claw.png
  9. Next are Hooks; we will check “command-logger” and “session-memory”.

    _images/hooks2_open_claw.png
  10. The installation is now complete. You can start OpenClaw by Selecting “Hatch in TUI” and pressing Enter.

_images/hatch_open_claw.png

Note

You can start OpenClaw by entering the following command:

openclaw tui

And You can press ctrl+c twice to exit the tui interface.


Making OpenClaw Operate the PiCar-X

What is PiCar-X Skill?

PiCar-X Skill is an extension for OpenClaw that allows you to control your SunFounder PiCar-X robot car through natural language. Instead of writing Python scripts or remembering servo angles, you can simply tell OpenClaw what you want PiCar-X to do — like “drive forward”, “check what’s ahead”, or “turn left” — and OpenClaw will execute the appropriate Python code automatically.

Here are some things you can do with PiCar-X Skill:

  • Driving: Drive forward, backward, turn left/right with steering servo control

  • Camera Gimbal: Pan left/right, tilt up/down via the 2-axis camera gimbal

  • Sensors: Read ultrasonic distance, grayscale sensor data for line tracking and cliff detection

  • Sound: Play sound effects and music through the car’s speaker

  • Camera Vision: Take photos, detect faces, track colors, recognize QR codes, gestures, and traffic signs


Prerequisites

Before you can use PiCar-X Skill with OpenClaw, make sure you have:

  1. PiCar-X properly assembled and connected to your Raspberry Pi

  2. OpenClaw installed and running

  3. The following Python libraries installed:

    • picarx

    • robot_hat

    • vilib

You can verify the installation by running:

python3 -c "import picarx"

If this command runs without errors, you’re ready to proceed.


Installing PiCar-X Skill

Follow these steps to install the PiCar-X Skill for OpenClaw:

  1. Copy the PiCar-X skill files to the OpenClaw skills directory:

    cp -r ~/picar-x/picarx-control ~/.openclaw/workspace/skills/
    
  2. Verify the installation by checking the skill files:

    ls ~/.openclaw/workspace/skills/picarx-control/
    

    You should see SKILL.md, install.sh, scripts/, and references/ in the output.

The skill’s SKILL.md file contains all the instructions OpenClaw needs — safety rules, code templates for each capability, and a mapping from natural language requests to Python code. OpenClaw reads this file and uses it to decide what code to execute on your PiCar-X.


Testing PiCar-X Skill from the CLI

Before using the skill with OpenClaw, you may want to test basic functionality directly from the terminal using the included CLI tool.

Check ultrasonic distance:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py sensor distance

Drive forward:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py move forward --speed 60

Drive backward:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py move backward --speed 60

Turn left:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py turn left --angle 30

Turn right:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py turn right --angle 30

Set camera pan angle:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py cam pan --angle 30

Set camera tilt angle:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py cam tilt --angle 20

Play a sound effect:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py sound play /path/to/sound.wav --volume 80

Read grayscale sensor data (line tracking):

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py sensor grayscale

Run servo calibration:

python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py calibrate

Using PiCar-X Skill in OpenClaw

Once you’ve verified that PiCar-X Skill works from the command line, you can start using it within OpenClaw.

  1. Launch OpenClaw TUI:

    openclaw tui
    
  2. Send natural language commands to control PiCar-X. Here are some examples:

    • “Drive forward”

    • “Go backward”

    • “Turn left”

    • “Turn right”

    • “Check if there’s something ahead”

    • “Look to the left”

    • “Look up”

    • “Look down”

    • “Take a photo”

    • “Detect faces”

    • “Find the color red”

    • “Follow the line”

    • “Check if there’s a cliff ahead”

  3. OpenClaw will automatically translate your request into the appropriate Python code and execute it on PiCar-X.


Available Actions and Commands

Here is the complete list of capabilities supported by PiCar-X Skill:

Driving (pc.py move)

Action

Description

forward

Drive forward

backward

Drive backward

Turning (pc.py turn)

Action

Description

left

Turn left by adjusting steering angle

right

Turn right by adjusting steering angle

Camera Gimbal (pc.py cam)

Capability

Description

Pan camera

Rotate camera horizontally (-90° to 90°)

Tilt camera

Tilt camera vertically (-35° to 65°)

Sensors

Command

Description

sensor distance

Read ultrasonic distance sensor (returns cm)

sensor grayscale

Read 3-channel grayscale module values (for line tracking & cliff detection)

Sound (pc.py sound)

Command

Description

sound play <file>

Play a sound effect file

sound music <file>

Play background music

sound volume <0-100>

Set speaker volume

sound stop

Stop playback

Note

The sound files can be any .wav format audio file accessible on your Raspberry Pi. You can also use sound music to play background music files.

Camera & Vision (via natural language / exec)

Capability

Description

Take photo

Capture and save a photo to ~/Pictures/

Face detection

Detect human faces and report position

Color detection

Locate objects by color (red, blue, green, etc.)

Gesture recognition

Recognize rock/paper/scissor gestures

Traffic sign detection

Recognize stop/left/right/forward signs

QR code scanning

Read QR code data and position

Line Tracking & Cliff Detection

Capability

Description

Line tracking

Follow a black line on a light surface using 3-channel grayscale

Cliff detection

Detect edges/drops using grayscale threshold values


Troubleshooting

OpenClaw Issues

  1. During installation, I get the error Error: systemctl is-enabled unavailable: Command failed: systemctl --user is-enabled openclaw-gateway.service. What should I do?

    You can ignore this for now, but you might encounter issues in the next steps. Please refer to them one by one at that time.

  1. When I run openclaw tui, I get the error -bash: openclaw: command not found. What should I do?

    Execute the following command:

    echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
    source ~/.bashrc
    

    You should now be able to start the tui interface with openclaw tui.

  1. In openclaw tui, I encounter not connected to gateway message not sent or the message gateway disconnected: closed.

    This is because your OpenClaw Gateway service is not started. Open another terminal and execute the following command to start the OpenClaw Gateway:

    openclaw gateway
    

    Then restart openclaw tui, and you can use it directly.

  1. I want to set the OpenClaw Gateway service to run in the background / start automatically on boot. How do I do that?

    Normally, your OpenClaw Gateway service should start automatically on boot. If it doesn’t, you can manually start it with the following command.

    1. Create the ~/.config/systemd/user directory:

    mkdir -p ~/.config/systemd/user
    
    1. Create the openclaw-gateway.service file:

    cat > ~/.config/systemd/user/openclaw-gateway.service << EOF
    [Unit]
    Description=OpenClaw Gateway
    After=network.target
    
    [Service]
    Type=simple
    ExecStart=$HOME/.npm-global/bin/openclaw gateway run
    Restart=on-failure
    RestartSec=10
    Environment="PATH=$HOME/.npm-global/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin"
    Environment="NODE_ENV=production"
    
    [Install]
    WantedBy=default.target
    EOF
    
    1. Then reload the systemd configuration:

    systemctl --user daemon-reload
    
    1. Start the service:

    systemctl --user start openclaw-gateway
    

    At this point, restart openclaw tui, and you can use it directly.

    1. Enable it to start on boot:

    systemctl --user enable openclaw-gateway
    
  1. My OpenClaw can not operate the system, what should I do?

    A newly installed OpenClaw may not have permission to operate your Raspberry Pi system by default; it can only chat. We need to manually configure the permissions.

    1. Open the OpenClaw configuration file:

    nano ~/.openclaw/openclaw.json
    
    1. Find the tools option and change the profile and exec as shown.

    "tools": {
        "profile": "coding",
        "exec": {
            "secrity": "full"
        }
    },
    
    1. Save and exit.

    2. Enter the following command in the terminal to restart the OpenClaw Gateway:

    openclaw gateway restart
    

    Now, OpenClaw should have read and write permissions and be able to operate your Raspberry Pi system.

PiCar-X Issues

  1. PiCar-X doesn’t respond to commands. What should I do?

    First, verify that PiCar-X is properly connected and powered on. Then test basic functionality:

    python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py sensor distance
    

    If this fails, ensure the required Python libraries are installed:

    python3 -c "import picarx; import robot_hat; import vilib"
    
  1. The import picarx test fails.

    This means the PiCar-X Python library is not properly installed. Please refer to the PiCar-X official installation guide to install the necessary libraries. You can also run the included install script:

    bash ~/.openclaw/workspace/skills/picarx-control/install.sh
    
  1. OpenClaw doesn’t recognize the PiCar-X skill.

    Remind OpenClaw to sync the skills by saying in the TUI: “Please rsync my skills” or restart OpenClaw gateway:

    openclaw gateway restart
    
  1. PiCar-X movements seem jerky or the steering is off-center.

    This is usually caused by servo calibration values being incorrect. Run the calibration script to adjust the steering servo and camera gimbal:

    python3 ~/.openclaw/workspace/skills/picarx-control/scripts/pc.py calibrate
    

    You can also adjust the speed parameter (e.g., use --speed 40) for smoother movement, or add short delays between consecutive commands.

  1. The grayscale or line tracking doesn’t work properly.

    Make sure the grayscale module is properly calibrated for your surface. You can set the line reference values using the configuration. Refer to the main PiCar-X documentation for grayscale calibration procedures.