Video Streaming Car Robot using Raspberry Pi & Camera
Video Streaming Car Robot using Raspberry Pi 4 with Python & OpenCV Code to view footage taken by the camera module in Raspberry Pi Desktop
- Suitable forB.Tech/Diploma Raspberry Pi students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview
In this guide, you will learn how to build your own Raspberry Pi Video Streaming Robot Car and create a First Person View (FPV) driving experience. For this, we will use a Robotic Car Kit called Picar-X Robot from Sunfounder.
The first step is to configure video streaming on the Raspberry Pi using the HAT & Raspberry Pi camera. The Robot is capable of Video Streaming with a Raspberry Pi Camera using OpenCV. The Robot can also control camera servos as Pan and Tilt functions as its head is movable. Apart from this you can connect everything together & drive the car in any direction.
The
PiCar-X
is an
AI self-driving robot
car that uses
Raspberry Pi
as its control center. The Robotic Kit is designed by
SunFounder
. The Kit comes with a
Robot HAT
for Raspberry Pi. The HAT integrates the
motor driving, servo driving
, and preset ADC, PWM, and digital pins to extend the functionality. The PiCar-X’s has a
2-axis camera
module,
ultrasonic module
, and
line tracking modules
that can provide the functions of
color/face/traffic signs detection, automatic obstacle avoidance, automatic line tracking
, etc.
This project can be advanced to AI-based autonomous-driving cars and fully autonomous cars. The remote control enables valuable operational data to be obtained, thus laying the groundwork for gradually increasing autonomous driving performance in the future. Moreover, human assistance through remote driving can offer more flexibility and intelligence than a single artificial intelligence.
Bill of Materials
We need the following components along with the
SunFounder Robot Car Kit
to make a Video Streaming Car Robot using Raspberry Pi Camera. You can purchase all these components from Amazon links:
S.N.
Components
Quantity
Purchase Links
Raspberry Pi Ai Car Kit PiCar-X
Amazon
SunFounder
Raspberry Pi 4
Amazon
SunFounder
Samsung 18650 Battery
AliExpress
SD Card 16/32 GB
Amazon
SunFounder
SD Card Adapter
Amazon
AliExpress
18650 Battery Charger
Amazon
AliExpress
Robot HAT cannot charge the battery, so you need to buy a battery charger at the same time.
Robot Assembly
The
Sunfounder Picar-X Robot Kit
comes with all the necessary components required for the Robot which include the following components. You need to buy a Raspberry Pi 4 Board and a pair of
Samsung 18650 Batteries
separately.
The most important part of this Kit is Robot HAT. With the Robot HAT board, the PiCar-X integrates left/right driving motors, servo motors for steering, and the camera’s pan/tilt functions, and pre-sets the Robot HAT’s ADC, PWM, and Digital I2C pins to allow for extensions to the standard functionality of the Raspberry Pi.
Both a
speaker
and a
Bluetooth
chip have been engineered into the Robot HAT for remote control of Text-to-Speech, sound effects, or even background music functionality.
To assemble the components together and make a perfect Robotic Car you can follow the
Assembly Guide
. The PDF Document has all the images and a pictorial view for easy help with assembly.
The
Robotic Kit
Part details,
Assembly
guide, HAT parts & functionality,
calibration
process, Robot
Testing
and Setting Up Rasbian OS has been explained in
PiCar-X Getting Started
guide.
Read the tutorial thoroughly to understand the
Hardware & Software Setup
Part.
Installing Python Modules & Libraries
The
OS installation
part and setup part can be followed on
Raspberry Pi OS Setup
. But for this robotic project part, it is recommended to install
Raspberry Pi OS(Legacy)
You can either use the
HDMI Screen
or enable
SSH
and connect the Raspberry Pi to
VNC Viewer
using the local IP Address, username, and password. It is best to connect the Robot Wirelessly via a
Remote Desktop
as we need a remote control for it.
The
Picar-X Robot
should be turned ON and Raspberry Pi should be connected to the network. Now let’s install all the Python Modules and libraries.
Let’s first update the system using the following commands.
sudo
apt
update
sudo
apt
upgrade
Then install the Python3-related packages.
sudo
apt
install
git
python3
pip
python3
setuptools
python3
smbus
Download & install the libraries for
Robot-Hat
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/robot-hat.git
cd
robot
hat
sudo
python3
setup
py
install
Running ‘
setup.py
‘ will download some necessary components. Your download may have failed due to network issues. You may need to download it again at this point. See the following interface, type ‘
Y
‘, and press Enter.
Now, download and install the ;
vilib
‘ module.
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/vilib.git
cd
vilib
sudo
python3
install
py
Similarly download and install the ‘
picar-x
‘ module.
cd
/
/
pi
/
git
clone
b
v2
https
:
//github.com/sunfounder/picar-x.git
cd
picar
sudo
python3
setup
py
install
This will download a large number of files, therefore it will take time.
Once the download is complete, run the ‘
i2samp.sh
‘ script to install the components required by the i2s amplifier, otherwise the picar-x will have no sound.
cd
/
/
pi
/
picar
sudo
bash
i2samp
sh
Type ‘
y
‘ and press enter to continue running the script.
Type ‘
y
‘ and press enter to run ‘
/dev/zero
‘ in the background.
Type y and press enter to restart the Picar-X.
After restarting, the Raspberry Pi will connect to the Network and will play a sound.
If there is no sound after restarting, you may need to run the ‘
i2samp.sh
‘ script several times.
All the installation and setup part is complete here.
Python Code for Video Streaming Car Robot
Here is a complete Python Code for Video Streaming Car Robot using Raspberry Pi & Camera. But before that we need to fulfill some requirements for the fully functionality of this Robot:
This project requires access to the Raspberry Pi desktop to view the footage taken by the camera module.
You can connect a screen to the PiCar-X or refer to the tutorial
Remote Desktop
to access it with VNC or XRDP.
Once inside the Raspberry Pi desktop, open Terminal and type the following command to run it, or just open and run it with a Python editor.
cd
/
/
pi
/
picar
/
example
sudo
python3
video_car
py
The code is also located in the source code path ‘
picar-x/example/video_car.py
‘. You can directly open the code from this location. You can Modify/Reset/Copy/Run/Stop the code below.
# #!/usr/bin/env python3
(
'Please run under desktop environment (eg: vnc) to display the image window'
)
from
utils
import
reset_mcu
reset_mcu
(
)
from
picarx
import
Picarx
from
vilib
import
Vilib
from
time
import
sleep
time
strftime
localtime
import
readchar
manual
=
''
'
Press key to call the function(non-case sensitive):
O: speed up
P: speed down
W: forward
S: backward
A: turn left
D:turn right
F: stop
T: take photo
ESC / Ctrl+C: quit
'
''
px
=
Picarx
(
)
def
take_photo
(
)
:
_time
=
strftime
(
'%Y-%m-%d-%H-%M-%S'
localtime
(
time
(
)
)
)
=
'photo_%s'
%
_time
path
=
"/home/pi/Pictures/picar-x/"
Vilib
take_photo
(
path
)
(
'\nphoto save as %s%s.jpg'
%
(
path
)
)
def
move
(
operate
:
str
speed
)
:
if
operate
==
'stop'
:
px
stop
(
)
else
:
if
operate
==
'forward'
:
px
set_dir_servo_angle
(
)
px
forward
(
speed
)
elif
operate
==
'backward'
:
px
set_dir_servo_angle
(
)
px
backward
(
speed
)
elif
operate
==
'turn left'
:
px
set_dir_servo_angle
(
)
px
forward
(
speed
)
elif
operate
==
'turn right'
:
px
set_dir_servo_angle
(
)
px
forward
(
speed
)
def
main
(
In this guide, you will learn how to build your own Raspberry Pi Video Streaming Robot Car and create a First Person View (FPV) driving experience. For this, we will use a Robotic Car Kit called Picar-X Robot from Sunfounder.
The first step is to configure video streaming on the Raspberry Pi using the HAT & Raspberry Pi camera. The Robot is capable of Video Streaming with a Raspberry Pi Camera using OpenCV. The Robot can also control camera servos as Pan and Tilt functions as its head is movable. Apart from this you can connect everything together & drive the car in any direction.
The
PiCar-X
is an
AI self-driving robot
car that uses
Raspberry Pi
as its control center. The Robotic Kit is designed by
SunFounder
. The Kit comes with a
Robot HAT
for Raspberry Pi. The HAT integrates the
motor driving, servo driving
, and preset ADC, PWM, and digital pins to extend the functionality. The PiCar-X’s has a
2-axis camera
module,
ultrasonic module
, and
line tracking modules
that can provide the functions of
color/face/traffic signs detection, automatic obstacle avoidance, automatic line tracking
, etc.
This project can be advanced to AI-based autonomous-driving cars and fully autonomous cars. The remote control enables valuable operational data to be obtained, thus laying the groundwork for gradually increasing autonomous driving performance in the future. Moreover, human assistance through remote driving can offer more flexibility and intelligence than a single artificial intelligence.
Bill of Materials
We need the following components along with the
SunFounder Robot Car Kit
to make a Video Streaming Car Robot using Raspberry Pi Camera. You can purchase all these components from Amazon links:
S.N.
Components
Quantity
Purchase Links
Raspberry Pi Ai Car Kit PiCar-X
Amazon
SunFounder
Raspberry Pi 4
Amazon
SunFounder
Samsung 18650 Battery
AliExpress
SD Card 16/32 GB
Amazon
SunFounder
SD Card Adapter
Amazon
AliExpress
18650 Battery Charger
Amazon
AliExpress
Robot HAT cannot charge the battery, so you need to buy a battery charger at the same time.
Robot Assembly
The
Sunfounder Picar-X Robot Kit
comes with all the necessary components required for the Robot which include the following components. You need to buy a Raspberry Pi 4 Board and a pair of
Samsung 18650 Batteries
separately.
The most important part of this Kit is Robot HAT. With the Robot HAT board, the PiCar-X integrates left/right driving motors, servo motors for steering, and the camera’s pan/tilt functions, and pre-sets the Robot HAT’s ADC, PWM, and Digital I2C pins to allow for extensions to the standard functionality of the Raspberry Pi.
Both a
speaker
and a
Bluetooth
chip have been engineered into the Robot HAT for remote control of Text-to-Speech, sound effects, or even background music functionality.
To assemble the components together and make a perfect Robotic Car you can follow the
Assembly Guide
. The PDF Document has all the images and a pictorial view for easy help with assembly.
The
Robotic Kit
Part details,
Assembly
guide, HAT parts & functionality,
calibration
process, Robot
Testing
and Setting Up Rasbian OS has been explained in
PiCar-X Getting Started
guide.
Read the tutorial thoroughly to understand the
Hardware & Software Setup
Part.
Installing Python Modules & Libraries
The
OS installation
part and setup part can be followed on
Raspberry Pi OS Setup
. But for this robotic project part, it is recommended to install
Raspberry Pi OS(Legacy)
You can either use the
HDMI Screen
or enable
SSH
and connect the Raspberry Pi to
VNC Viewer
using the local IP Address, username, and password. It is best to connect the Robot Wirelessly via a
Remote Desktop
as we need a remote control for it.
The
Picar-X Robot
should be turned ON and Raspberry Pi should be connected to the network. Now let’s install all the Python Modules and libraries.
Let’s first update the system using the following commands.
sudo
apt
update
sudo
apt
upgrade
Then install the Python3-related packages.
sudo
apt
install
git
python3
pip
python3
setuptools
python3
smbus
Download & install the libraries for
Robot-Hat
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/robot-hat.git
cd
robot
hat
sudo
python3
setup
py
install
Running ‘
setup.py
‘ will download some necessary components. Your download may have failed due to network issues. You may need to download it again at this point. See the following interface, type ‘
Y
‘, and press Enter.
Now, download and install the ;
vilib
‘ module.
cd
/
/
pi
/
git
clone
https
:
//github.com/sunfounder/vilib.git
cd
vilib
sudo
python3
install
py
Similarly download and install the ‘
picar-x
‘ module.
cd
/
/
pi
/
git
clone
b
v2
https
:
//github.com/sunfounder/picar-x.git
cd
picar
sudo
python3
setup
py
install
This will download a large number of files, therefore it will take time.
Once the download is complete, run the ‘
i2samp.sh
‘ script to install the components required by the i2s amplifier, otherwise the picar-x will have no sound.
cd
/
/
pi
/
picar
sudo
bash
i2samp
sh
Type ‘
y
‘ and press enter to continue running the script.
Type ‘
y
‘ and press enter to run ‘
/dev/zero
‘ in the background.
Type y and press enter to restart the Picar-X.
After restarting, the Raspberry Pi will connect to the Network and will play a sound.
If there is no sound after restarting, you may need to run the ‘
i2samp.sh
‘ script several times.
All the installation and setup part is complete here.
Python Code for Video Streaming Car Robot
Here is a complete Python Code for Video Streaming Car Robot using Raspberry Pi & Camera. But before that we need to fulfill some requirements for the fully functionality of this Robot:
This project requires access to the Raspberry Pi desktop to view the footage taken by the camera module.
You can connect a screen to the PiCar-X or refer to the tutorial
Remote Desktop
to access it with VNC or XRDP.
Once inside the Raspberry Pi desktop, open Terminal and type the following command to run it, or just open and run it with a Python editor.
cd
/
/
pi
/
picar
/
example
sudo
python3
video_car
py
The code is also located in the source code path ‘
picar-x/example/video_car.py
‘. You can directly open the code from this location. You can Modify/Reset/Copy/Run/Stop the code below.
# #!/usr/bin/env python3
(
'Please run under desktop environment (eg: vnc) to display the image window'
)
from
utils
import
reset_mcu
reset_mcu
(
)
from
picarx
import
Picarx
from
vilib
import
Vilib
from
time
import
sleep
time
strftime
localtime
import
readchar
manual
=
''
'
Press key to call the function(non-case sensitive):
O: speed up
P: speed down
W: forward
S: backward
A: turn left
D:turn right
F: stop
T: take photo
ESC / Ctrl+C: quit
'
''
px
=
Picarx
(
)
def
take_photo
(
)
:
_time
=
strftime
(
'%Y-%m-%d-%H-%M-%S'
localtime
(
time
(
)
)
)
=
'photo_%s'
%
_time
path
=
"/home/pi/Pictures/picar-x/"
Vilib
take_photo
(
path
)
(
'\nphoto save as %s%s.jpg'
%
(
path
)
)
def
move
(
operate
:
str
speed
)
:
if
operate
==
'stop'
:
px
stop
(
)
else
:
if
operate
==
'forward'
:
px
set_dir_servo_angle
(
)
px
forward
(
speed
)
elif
operate
==
'backward'
:
px
set_dir_servo_angle
(
)
px
backward
(
speed
)
elif
operate
==
'turn left'
:
px
set_dir_servo_angle
(
)
px
forward
(
speed
)
elif
operate
==
'turn right'
:
px
set_dir_servo_angle
(
)
px
forward
(
speed
)
def
main
(
Technologies used
Hardware components
- Raspberry Pi
- Servo
- SD Card
- Servo Motor
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.