In this lesson, we will show you how to use Internet to control a Raspberry Pi robot car. You can see use browser or APP to watch the video from car front camera and control the car movement.

No. Picture Device Qty. Accessories Link
1 CSI camera 1 M2 push pin rivets x 4 Click here to buy
2 Servo Motor 1 M2.2*8 Self Tapping Screw x 2
M2*4 Self Tapping Screw x 1
Click here to buy
3 Mount Holder for CSI camera 1 M2 push pin rivets x 4
M1.5*6 Self Tapping Screws x2
M2*4 Self Tapping Screw x 1
click here to buy
4 Philips screwdriver 1 Click here to buy


Step 1) Servo Must be installed and connected PWM 15 port

Step 2) Connect CSI camera to CSI Slot of Raspberry Pi with CSI ribbon cable (Please pay attention to the connections of the cable before you install it.)

Prerequisite Software Installation requirement

A)Make sure you have enabled I2C , if not, please run sudo raspbi-config and enable the I2C and Camera(for Bulleye OS)

B)Install Adafruit PCA9685 libraries, if you haven’t install PCA8685 libraries, please run following   commands:
If you are using Bulleye OS, please run following commands:

sudo pip install adafruit-circuitpython-pca9685
sudo pip install adafruit-circuitpython-servokit

If you are using Bookworm system in Raspberry Pi 5, please run following commands:

sudo pip install  --break-system-packages adafruit-circuitpython-pca9685
sudo pip install  --break-system-packages adafruit-circuitpython-servokit

Step 1:  Install Video Stream Software

 For Bulleye OS, please run
wget https://osoyoo.com/driver/picar/caminstall.sh

 wget https://osoyoo.com/driver/picar/startcam.sh

bash caminstall.sh

After running above commands, mjpeg-streamer software is installed in your Raspberry Pi.

To start jpeg-streamer server in your Raspberry Pi
Run following command in your Pi terminal will start your mjpeg-streamer server

bash startcam.sh

click stream link or direct visit http://your_raspberry_pi_ip:8899/?action=stream, you will see the video surveillance.

For Bookworm OS, Please run following commands to install  video streamer server:

wget https://osoyoo.com/driver/v5car/ut-bookworm.sh

bash ut-bookworm.sh

To start the streamer server, run following command:

bash utbegin.sh

Method 1: Use browser to control a Raspberry Pi Robot Car through the Internet

Step 1: Open a new terminal window and run the following code to install the OSOYOO web camera controlled robot car software

wget http://osoyoo.com/driver/picar/osoyoowebcar5.sh


Step 2: type the following command:

bash osoyoowebcar5.sh

After running above commands, you will automatically create a directory called osoyoowebcar, the structure is as follows:

Step 3: type the following command to enter the folder osoyoowebcar

cd osoyoowebcar

 

 

Step 4: Then type the following command to edit the file templates/index.html

nano templates/index.html

Step 5: Please change 192.168.0.107 in line 34 to your pi’s IP address, and click “Ctrl“+”X” then “Y” to save the file and then click “enter” to exit the file

Step 6: put the car on the ground and run the code by typing the following command (ATTENTION: please select a correct command according to your Pi board): :

sudo python3 ~/osoyoowebcar/webcar.py

Step 9: In your PC or cell phone which is the same Wi-Fi network of your Raspberry Pi, open the browser and visit http://your_RaspberryPi_ip_address.

The arrows buttons are direction control keys, the red circle button in the middle is the STOP key. There are four speed control buttons in the bottom:

In the top of the page, there is a Camera Direction Slider, you can move the slider in order to rotate the servo and change the camera orientation.

Method 2: Use APP to control a Raspberry Pi Robot Car through the Internet

Step 1: Open a new terminal window and run the following code to download the sample code for APP control

wget http://osoyoo.com/driver/picar/udp-camera-car.py

Step 2: Type the following command to run the sample code (ATTENTION: please select a correct command according to your Pi board):
If you are using Python 2 in Raspberry Pi 3, type:

python udp-camera-car.py

or if you are using Python 3 in Pi 4/3A+, type:

python3 udp-camera-car.py

Step 3) Download OSOYOO Wi-Fi UDP Robot Car control APP
In Google Play or Apple Store, please search keywords “OSOYOO IoT UDP Robot APP”, you will find a red icon APP as following (Note: If you can not find this APP in Google Play, you can directly download the APP from following link: https://osoyoo.com/driver/udp-app.apk):

Step 4) Connect your phone with the same router Wi-Fi SSID of Raspberry Pi use. Open the APP, click “setting icon(1)” to enter “setting UI”, enter IP address to your Raspberry Pi IP address and Port to 8888, enter http://your_raspberry_pi_ip:8899/?action=stream to video Target, then turn Video Target switch to green, then click save, then click “back icon(7)” to back control UI as following:

Step 5) Now, put the car on the ground, and you can click the < > ^ v direction keys to make the car move. Use || pause key to stop the car movement.

The Slider at the top of direction keys is a Camera Direction Slider, and you can move the slider in order to rotate the servo and change the camera orientation.

The slider at the left of direction keys is a speed slider, and you can move the slider up to speed up this robot.

Note: F1~F8, and the bottom and right slider are unavailable in this lesson.

FAQ

Q1: How to run the mjpeg-streamer server and webcar.py file with only one command?

Answer:
Step 1: Download new bash file by following commands:

cd ~
wget https://osoyoo.com/driver/picar/startwebcar.sh

After you have downloaded startwebcar.sh file, in future, you only need to run the following command to start bot web camera and robot control program at the same time.

bash startwebcar.sh

Q2: How to auto run the web camera control project when Raspberry Pi starts up?

Answer:
Step 1)Download a bash file by   the commands as following:

cd ~
wget https://osoyoo.com/driver/picar/autorunsetup.sh

Step 2)Run the bash file by following command:

bash autorunsetup.sh

Step 3)Edit /etc/rc.local file

sudo nano /etc/rc.local

In the nano edit window, insert the following line before exit 0

bash /home/pi/startcam.sh

Now your /etc/rc.local file last two lines will look as follows:

...
bash /home/pi/startcam.sh
exit 0

Please click Ctrl + X, then Y, then Enter to save the file.
Now restart your Raspberry Pi. Your web camera control robot car program will start automatically.