Site icon Renzo Mischianti

Building and programming PiCar-X: getting started with your robot car

Spread the love

The PiCar-X is a self-driving robot car designed specifically for the Raspberry Pi platform. It’s a versatile robot car that comes with a 2-axis camera module, ultrasonic module, and line tracking modules, providing a wide range of functions such as color/face/traffic-signs detection, automatic obstacle avoidance, and automatic line tracking. The PiCar-X supports two programming languages – Blockly and Python – catering to beginners and advanced programmers alike.

In this in-depth review, we will discuss the key features of the PiCar-X, its programming capabilities, and the educational content provided in its documentation.

Here is the SunFounder PiCar-X page with the link to buy, or you can choose Aliexpress, Amazon Italy, Amazon Germany, Amazon France, Amazon USA store

Key Features

  1. Programming Languages: The PiCar-X supports both Blockly and Python programming languages, catering to users with varying programming skills. Blockly is an excellent choice for beginners, younger users, or those who want to test the PiCar-X quickly, while Python offers more advanced control and flexibility for experienced programmers.
  2. Camera Module: The 2-axis camera module allows the PiCar-X to perform a wide range of computer vision tasks, including color detection, face detection, and traffic sign detection. This feature enables users to explore and experiment with various computer vision algorithms and applications.
  3. Ultrasonic and Line Tracking Modules: The ultrasonic module equips the PiCar-X with automatic obstacle avoidance capabilities, while the line tracking module allows for automatic line tracking. These features enable users to learn about robotics and real-world applications of autonomous navigation.
  4. Mobile App Control: The SunFounder Controller app provides a convenient way for users to remotely control the PiCar-X on their mobile devices. This feature adds to the accessibility and user-friendliness of the PiCar-X.
  5. Educational Content: The PiCar-X documentation offers a wealth of educational content, covering topics such as the history of self-driving cars, deep learning, neural networks, component assembly, and more. This makes the PiCar-X an excellent learning resource for users interested in robotics, programming, and AI.
  6. Multilingual Support: The PiCar-X documentation is available in English, with the company working on adding support for other languages. This demonstrates the company’s commitment to making the PiCar-X accessible to a global audience.

Assembly

SunFounder PiCar-X

SunFounder provides a comprehensive sheet with all the information about assembly instruction.

Remember, the Raspberry Pi isn’t included, It’s work with version 3b+ e 4. And you need 2*18650 lithium battery.

Here the batteries&nbps;AliExpress 18650 3.7v 3400mah

Requirements:

  1. PiCar-X kit
  2. Raspberry Pi (Preferably 3B+/4B)
  3. MicroSD card (16GB or higher, Class 10 or higher)
  4. Power supply for Raspberry Pi (5V/3A for Pi 4 or 5V/2.5A for Pi 3)
  5. Internet connection
  6. Laptop/PC with Windows, macOS, or Linux

Here is the box and my Raspberry Pi 3B+.

The box

As you can see that they are all well-packed, and I’m very surprised that all the body parts are metal.

Starting

All the steps are very easy.

Bottom

Also, the Raspberry Pi with HAT fit perfectly.

The HAT

Here is a better view of the HAT.

The HAT

The head of the car with the camera is very small.

The head

It is mounted over two servo motors that allow the camera to move independently in all directions.

The head assembled

Here is a detail of the wheel studs.

The bottom

Finally, the car with all elements is very beautiful.

Finally…

Setting up the Raspberry Pi for EzBlock

Now we have our PiCar-X ready, but we must add the software. There is a dedicated page for the firmware.

Download firmware
  1. Download the Raspberry Pi OS with EzBlock firmware preinstalled from here.
  2. Use an image writing tool like Raspberry Pi Imager to write the downloaded image to your microSD card.
  3. Insert the microSD card into the Raspberry Pi, connect the power supply, and power it up.

Connecting Ezblock Studio to PiCar-X

The first time I encourage you to use a mobile device with the EzBlock studio app, because we can use Bluetooth to set the IP address.

  1. Open the app and select the device.
  2. Press connect via Bluetooth device are immediately recognized. Click on It.
Bluetooth
  1. Now we can go to configure the wifi connection.
Insert IP
  1. So we can get the IP.
Connected

You can start the calibration via the app, but I prefer doing it on my PC.

  1. Launch the Ezblock Studio on your computer.
  2. Click on the icon up left and select your device
  3. On the icon up left and click “Connect.”
  4. Insert the IP address.
  5. Once connected, the status should change to “Connected” in the Devices tab.

Start programming with EzBlock

What is EzBlock?

EzBlock is a graphical programming language designed specifically for the PiCar-X. It is an intuitive and easy-to-use programming environment that allows users to create complex programs using drag-and-drop blocks. This means that users do not need to learn a complicated programming language or syntax to create functional programs for the PiCar-X. Instead, they can use a visual interface to design and code their programs.

How does EzBlock work?

EzBlock is based on the Blockly visual programming language. Blockly is an open-source project developed by Google that allows users to create programs using blocks that represent code. These blocks can be dragged and dropped onto a canvas, and they can be connected to form a program. EzBlock takes the Blockly concept and adds PiCar-X specific blocks to create a user-friendly programming environment for the PiCar-X.

PiCar-X block

EzBlock allows users to control the PiCar-X’s motors, sensors, and other components by dragging and dropping blocks onto a canvas. For example, to make the PiCar-X move forward, users can drag a “set motor speed” block onto the canvas and set the speed value to a positive number. Similarly, to turn the PiCar-X left or right, users can drag a “set motor speed” block onto the canvas and set the speed values for each motor accordingly.

PiCar-X block

EzBlock also includes blocks for controlling the PiCar-X’s sensors. For example, to use the PiCar-X’s ultrasonic sensor, users can drag a “read ultrasonic sensor” block onto the canvas and specify which sensor port to use. The sensor value can then be used in conditional statements or other blocks to create more complex programs.

PiCar-X block

The EzBlock programming IDE includes an instrument section that provides users with various tools to control and interact with their PiCar-X. The instrument section can be found on the right-hand side of the IDE and includes several components, such as the joystick, slider, video, and more.

The joystick component allows users to control the movement of the PiCar-X using a virtual joystick. This joystick can be dragged around the screen to control the direction of the PiCar-X, and users can adjust the sensitivity of the joystick to fine-tune their control.

The slider component provides users with a way to adjust the speed of the PiCar-X. This slider can be dragged left or right to adjust the speed of the PiCar-X, and users can set the maximum and minimum speed values for their specific needs.

The video component displays live video feed from the PiCar-X’s camera. This allows users to see what the PiCar-X sees and can be used for remote control and autonomous driving.

Overall, the instrument section of the EzBlock programming IDE provides users with a variety of tools to control and interact with their PiCar-X. These components make it easy for users to program and control the PiCar-X without having to write complex code or use external hardware.

Why use EzBlock for programming the PiCar-X?

There are several reasons why EzBlock is a great option for programming the PiCar-X:

Easy to use

EzBlock’s drag-and-drop interface makes it easy for users to create functional programs for the PiCar-X without having to learn a complex programming language or syntax.

PiCar-X specific blocks

EzBlock includes PiCar-X specific blocks that allow users to control the PiCar-X’s motors, sensors, and other components without having to write low-level code.

Raspberry Pi HAT

Now we are going to do a simple example. First of all I’d like to show the HAT and Its specs.

The HAT

Left/Right Motor Port

I2C Pin

PWM Pin

ADC Pin

Digital Pin

Battery Indicator

USR LED

RST Button

USR Button

Power Switch

Power Port

Simple example

I’d like to add two led to have light when I want, so we will “upgrade” the PiCar-X. We use the PWM pins so we can manage the light intensity.

3D printed led adapter

I created a simple adapter to add two led in the head of PiCar-X.

PiCar-X LEDs head 

Code

Here is a simple Blink sketch with two LEDs connected to P11 (anode on yellow and cathode on black) and P10.

Blink program

The result is this.

Blink LEDs

Control camera and light

Now we are going to use the virtual control tools given by the platform.

I create a simple program that allows us to turn on or off the less and view the camera on the screen.

Control the LEDs

Here is the tab that allows you to add controls to create the user interface.

Graphical tools

The result with LEDs off.

Led off

And with LEDs on.

Led on

Thanks

The PiCar-X is a highly versatile, AI-driven self-driving robot car that caters to users of all ages and programming experience levels. Its extensive documentation, support for multiple programming languages, and a wide range of features make it an excellent educational tool and an engaging way to learn about robotics, computer vision, and programming.

Whether you’re a beginner interested in exploring the world of programming and robotics or an advanced programmer looking for a platform to experiment with AI and computer vision, the PiCar-X offers something for everyone. With its diverse range of features and applications, the PiCar-X can be a valuable addition to any robotics enthusiast’s toolkit.


Spread the love
Exit mobile version