SunFounder PiCar-X 2.0 review – A Raspberry Pi 4 AI robot car programmable with Blockly or Python

SunFounder PiCar-X 2.0 is an AI-powered self-driving robot car using the Raspberry Pi 3/4 as the main processing board. It is equipped with a camera module that can be moved by a 2-axis servo motor, allowing the camera to pan or tilt, an ultrasonic module for detecting distant objects, and a line detection module. The PiCar-X robot can also perform computer vision tasks such as color detection, face detection, traffic signs detection, automatic obstacle avoidance, and automatic line tracking.

The PiCar-X can be programmed with two computer languages: Blockly-based Ezblock Studio drag-and-drop program and Python, and the robot works with OpenCV computer vision library and TensorFlow for AI workloads. Finally, you can also control the robot through the SunFounder controller application on your mobile phone. The company sent us a sample of the Picar-X 2.0 for review, so let’s get started.

SunFounder PICAR-X Robot review

SunFounder PiCar-X 2.0 robot overview

SunFounder PICAR-X V2.0 Part Kit

The PiCar-X robot kit comes with several parts: a structural unit, DC electric motors, robot wheels, a RoboHat expansion board, an ultrasonic sensor, a line sensor, a servo motor, a battery, and a set of nuts and screws used for assembly.  Since it comes as a kit, the students will have to assemble it themselves and as a result, learn about assembling robots and how to connect the wires of this robot set. Additional details and assembly instructions can be found in the documentation. Our kit also came with a Raspberry Pi 4 with 4GB RAM.

SunFounder PiCar-X Robot HAT

PICAR-X Robot Hat

SunFounder PiCar-X Robot HAT expansion board features an on-off switch, two motor drive ports to connect left and right motors and twelve servo motor drive ports that can be used to steer the wheels of the car and control the pan-tilt of the camera. Furthermore, the Robot HAT expansion board also includes a speaker to play sound effects, language feedback, or MP3 music. Expansion ports for ADC, PWM, and I2C are available for expansion, and a 7-12 volt battery can be connected for power and charged through a USB-C port with an LED indicating the battery charging status.

Robot Hat Description

 

PiCar-X Robot HAT specifications:

  • Motor port left/right – 2-channel XH2.54 ports, one for the left motors connected to GPIO 4 and the other for the right motors connected to GPIO 5.
  • 2x I2C pin from Raspberry Pi
  • PWM – 12x PWM (P0-P11)
  • 4x ADC pins (A0-A3)
  • 4x digital pins (D0-D3)
  • Battery status indicators
    •  LED 2 lights up when the voltage is more than 7.8 volts
    •  LED 1 lights up when the voltage is between 6.7 – 7.8 volts
    • Both LEDs turn off when the voltage is lower than 6.7 volts
  • Supply Voltage – 7 – 12V DC via a 2-pin PH2.0 connector that can be used to power the Raspberry Pi at the same time

Installing a (custom) Raspberry Pi OS

The OS for the PiCar-X 2.0 robot can be installed on a microSD card using the Raspberry Pi Imager program.

Two operating system images are available

  • For Python programming simply use Raspberry Pi OS (Legacy)
  • For the Ezblock Studio visual programming IDE, download RaspiOS-xxx_EzBlockOS-xxx.img that’s basically the original Raspberry Pi OS image with Ezblock Studio pre-installed. You can then click on the CHOOSE OS button and then Use Custom to select the file you’ve just downloaded. Then select the storage device, click on WRITE, and wait until the process is complete.

Booting Raspberry Pi OS on SunFounder PiCar-X 2.0

Now take the microSD card from your computer and insert it into your Raspberry Pi board. Then plug in the battery holder cable and slide the Power switch on the Robot HAT to turn on the robot.

 

SunFounder PICAR-X slide to power

Raspberry Pi OS should now boot, and you can verify the installation by connecting a mouse, a keyboard, and an HDMI monitor to check everything is working as expected as if you simply used the Raspberry Pi as a standalone single board computer.

Raspberry Pi OS Desktop

Getting started with EzBlock Studio for the PiCar-X 2.0 robot

EzBlock Studio is a visual programming platform developed by SunFounder for beginners in order to easily get started with programming the Raspberry Pi. It supports two programming languages, Blockly for visual programming with various blocks and the the code is then converted into a Python program which can be uploaded to the Raspberry Pi through Bluetooth or Wi-Fi.

You can either download the app on your mobile phone from the App Store (iOS) or the Google Play Store (Android) by searching for “Ezblock Studio”, or go to http://ezblock.cc/ezblock-studio to start programming from your web browser. Note: The page says EzBlock Studio V3.2 will switch to offline mode on February 28. That does not mean the website will be closed at that time, but simply that you won’t be able to save the project to the cloud, and only locally to your computer going forward.

Let’s create a new project by clicking on the New Project area.

EzBlock Studio

Select the PiCar-X product:

EzBlock Studio Choose Device

Click on the Connect button.

EzBlock Picar-X

The program will display the IP address of the robot, simply click on the Confirm button.

EzBlock Setup IP Address

Once the connection is successful, you’ll see various information about the robot such as battery charge level, voltage, and version.

EzBlock PiCar-X Connected Robot

Installing Python libraries and modules

Start a terminal window in Raspberry Pi OS to upgrade the operating system to the latest version:


Install the SunFounder PICAR-X Robot Hat library as follows:


Then download and install the Vilb module:


and do the same for the Picar-X module:


Now run the i2samp.sh script  to install the driver for the I2S speaker amplifier:


Type “y” to go forward with the installation:

SunFounder PICAR-X I2S

And again to activate /dev/zero playback in the background…

SunFounder PICAR-X I2S Confirm

And reboot the system once asked.

SunFounder PICAR-X I2S Reboot

 

Enable the I2C interface

Type the following command to enter the Raspberry Pi OS settings:


Select Interface Options…

raspi-config Interface Options

…then I2C

raspi-config Enable I2C

…and confirm by selecting “Yes“.

SunFounder PICAR-X Confirm I2C Enable

You’ll then be asked to reboot the system and do so to complete the installation.

Setting the Servo Motor to 0° degrees for easier assembly

 

SunFounder PICAR-X Servo Arm

The PiCar-X robot kit’s servo angle range is -90° to 90°, but that angle is not set at the factory and will be random, maybe 0° or maybe 45°. If we assemble it at a random angle that is not zero, it may damage the servo during use. Therefore, it is necessary to first set the angle of all servos to 0° before installing them on the robot. To keep the servo centered no matter what direction it is rotated, run the command


Then plug the servo cable into port P11 and you will see the servo arm rotate to position (This is the 0° position). Next, insert the servo arm as explained in the assembly manual.

 

SunFounder PICAR-X P11 Connect

 

Calibration of the PiCar-X 2.0 robot (Python)

Some servo angles may be slightly tilted due to possible deviations during the PiCar-X installation or servo limitations. To fix this issue, run the calibration.py program:


This will start the Pica-X Calibration Helper with a menu as shown below.

PICAR-X Calibration

The R key is used to test whether the servo that controls the direction of the front wheels can work normally and is not damaged. Press 1 to select the front wheel servo, then press the W/S keys to keep the front wheels looking as forward as possible without tilting left or right.

Calibration Direction Servo

Now press 2 to select camera servo 1 (for panning), then the W/S keys to make the pan/tilt platform look straight ahead, and not left or right.

Calibrate Camera Servo1

Do the same for the camera servo 2 (tilting) by selecting 3, and pressing the W/S keys to keep the pan/tilt platform looking straight ahead and not tilting up or down.

SunFounder PICAR-X Calibrate Camera Servo

Because the motor wiring may be reversed during installation, you can press E to test whether the vehicle can move forward normally. If not then press 4 or 5 to select the left and right motors. Once done we can calibrate the rotation direction by pressing Q.

PICAR-X Calibrate Direction Motor

When the calibration is complete, press the Spacebar to save the calibration parameters. You will be prompted to enter “y” to confirm, then press ESC or Ctrl+C to exit the program.

SunFounder PICAR-X Calibration Confirm

Calibration of the PiCar-X 2.0 robot (EzBlock Studio)

If you’d rather not use Python and the command line, it’s also possible to calibrate the PiCar-X 2.0 robot in the EzBlock Studio web interface. Click on the Settings button after the connection is successful.

 

EzBlock Studio Robot Setting

Now click on Calibrate.

EzBlock Studio Robot Calibrate

 

The Calibration window will pop up where you can select servo motors for calibration either for the Pan-and-Tilt camera or the steering wheels.

EzBlock Studio Calibrate

Let’s start with the PiCar-X Pan-Tilt servo motors’ calibration. Two sets of buttons allow the user to adjust the camera up or down (tilt) and left and right (pan). Once the camera looks to be adjusted straight,, click on Confirm to complete the calibration.

 

EzBlock Studio PiCar-X Calibrate Pan Tilt

Let’s now do the same for the steering wheels which we can adjust to the left or the right. Once the wheels are straight click on Confirm to complete the calibration.

EzBlock Studio PiCAR-X Calibrate Steering

Testing the movement of the PiCar-X 2.0 robot

We’ll now make the PiCar-X robot move forward drawing an S-shape and stop it. You can check out the program in Python:


… and EzBlock Studio.

EzBlock Studio Robot Move Code

Obstacle avoidance test

The PiCar-X 2.0 robot features an HC-SR04 ultrasonic sensor to detect objects with a distance of 0 to 400 cm. The demo program will let the servo turn the robot’s wheels by -35 degrees if an object is within the 25 cm range, and otherwise drive straight with the angle set to 0 degrees. We tested it successfully with both Python and EzBlock Studio.

HC-SR04 ultrasonic sensor

Python:


EzBlock Studio:

EzBlock Studio Obstacle Avoidance Code

PiCar-X 2.0 robot’s line following test program

The PiCar-X 2.0 robot relies on the “SunFounder 3-ch Gray Scale Sensor” to detect lines by giving each output a separate analog value. The programming test creates three conditions for line detection:

  1. Run forward at 10% speed by default with the servo’s angle set to 0 degrees.
  2. If the left sensor detects a black line, set the wheel control servo’s angle to 12 degrees.
  3. If the right sensor detects a black line, set the wheel control servo’s angle to -12 degrees.
  4. If conditions 2 and 3 above are not met, set the servo’s angle back to 0 degrees.

SunFounder 3-ch Gray Scale Sensor

Python program for the line following demo:


Equivalent visual programming demo design in EzBlock Studio.

EzBlock Studio Line Follower Code

Text-to-speed with the built-in speaker

We’ll now make the PiCar-X robot say “Hello!” through its speaker using Text-to-Speech(TTS). We’ve already installed the driver with i2samp.sh, so we can write a Python program as follows:


A similar example below was written in the EzBlock Studio, but it uses face detection through the built-in camera because saying “Hello, nice to meet you!”

EzBlock Studio Say Hello Code

Computer vision with the Raspberry Pi 4

Face detection is just one of the computer vision workloads that can be handled by the Raspberry Pi 4 through the 5MP SunFounder camera based on an OV5647 Full HD sensor. So let’s try a few more machine vision examples.

SunFounder Camera

Color detection

We will use colored circles for the test. You can download this PDF file to print your own.

SunFounder PICAR-X Color Cards

The test program will detect the color of a circular sign, draw a green rectangle around it, and write the name on the color on the top left side.

EzBlock Studio Color Detect Sign

Python code for color detection:


It’s much simpler in EzBlock Studio with just two blocks needed

EzBlock Studio Color Detection Code

Face detection function

We’ve already quickly tested face detection in the speaker test, but let’s have a closer look. The implementation relies on object detection using Haar Cascade Classifiers. It’s a powerful object detection method developed by Paul Viola and Michael Jones and documented in their research paper entitled “Rapid Object Detection using a Boosted Cascade of Simple Features”, published in 2001, and still popular today.

We will test this by analyzing camera images using Model Haar Cascade Classifiers, first by converting the image to grayscale, then drawing a rectangle around a human face if detected on the grayscale image, and finally on the original image.

EzBlock Studio Face Detection

Python code:


Equivalent EzBlock Studio example.

EzBlock Studio Face Detection Code

PiCar-X 2.0 video review

Conclusion

SunFounder PiCar-X 2.0 is a self-driving robot car powered by AI that is suitable for those interested in learning about the Raspberry Pi board, computer vision, and robotics. The robot can be programmed to avoid obstacles, follow lines, or even drive autonomously through computer vision with features like face detection or color detection.

This robot kit is suitable for schools, other educational institutions, and those interested in robots and technology in general. We haven’t covered all the features and tutorials for this robot in this review, and you’ll find more in the documentation such as QR code detection, face tracking, “Bull Fight” where the robot “chases” after red-colored items, among other demos.

We would like to thank SunFounder for sending me the PiCar-x 2.0 robot kit for now. The PiCar-X 2.0 robot kit with battery and charger is sold for $81.99 (or $154.99 with a Raspberry Pi 4 with 4GB RAM on the company’s online store, and you’ll also find these for respectively $74.99 and $145.10 on Amazon after clicking on the $15 discount code checkmark.

CNXSoft: This review is a translation of the original post on CNX Software Thailand by Kajornsak Janjam and edited by Suthinee Kerdkaew.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK Pi 4C Plus
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
0 Comments
Khadas VIM4 SBC