Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES ここでご購入を!


In this lesson, we will show you how to use Python3 Flask and M-Jpeg Streamer software to control a Raspberry Pi Robot Car through Internet. You will monitor the car’s real-time movement through its’ eye(front camera).

DSI Web camera for raspberry pi car kit

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: You must complete and test lesson 3 before you continue on with this lesson and remove the Ultrasonic sensor mount holder from servo motor and wires from Ultrasonic sensor.

Step 2: Choose slotted bracket in servo motor to cross Camera holder from top to bottom and fix blade with M1.5*6 Self Tapping Screws

Step 3: Install CSI camera to holder with 4pcs M2 push pin rivets

Step 4: Install Camera holder for ultrasonic sensor on servo motor with 1pc M2*4 Self Tapping Screws

Servo Must be installed and connected PCA9685 PWM 15 port and connect CSI camera to CSI Slot of Raspberry Pi with CSI ribbon cable (Please pay attention the connections of the cable before you install it.)

Step 1: Please enable Camera in Raspberry Pi by typing following command

sudo raspi-config

Then select ->5 Interfacing Options->P1 Camera->Yes->Ok->Finish (Please reboot the raspberry pi according to the notice.)

Step 2: Type following command to install mjpeg-streamer software :

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


and then type the following command:

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

and type the following command at last:

bash caminstall.sh

After running above commands, mjpeg-streamer software is installed in your raspberry pi. So Simple!

Step 3: Start  jpeg-streamer server in your Raspberry Pi
Run following command in your Pi terminal will start your mjpeg-streamer server

bash startcam.sh

These message means your video server is running at port 8899 in your Pi.

Step 4: Now we can use your browser to test the surveillance video. Now please visit http://your_raspberry_pi_ip:8899 (in my case http://192.168.1.245:8899),

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

Step 5: 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/osoyoowebcar.sh


and then type the following command:

bash osoyoowebcar.sh

Step 6: type following command to enter the folder webcar

cd osoyoowebcar

Step 7: Then type the following command to edit the file webcar.py

nano webcar.py

Replace ip address 192.168.1.245 in line 15 to your raspberry pi IP address, and cick “Ctrl”+”X” then “Y” to save the file and then click “enter” to exit

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

nano templates/index.html

Please change 192.168.1.245 in line 34 to your pi’s ip address, and cick “Ctrl”+”X” then “Y” to save the file and then click “enter” to exit

Step 9:
Run the project by typing following command


sudo python3 ~/osoyoowebcar/webcar.py

Step 10: In your PC or cell phone which is the same wifi network of your Raspberry Pi, open the browser and visit http://your_RaspberryPi_ip_address, you will see following UI

The arrows buttons are direction control keys, 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.

Questions & Answers:
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 following command to start bot web camera and robot control program at the same time.

bash startwebcar.sh

Q2: How to autorun the web camera control project when Raspberry Pi starts up?
Step 1)Download a bash file by   the commands as following:

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

Step 2)Run the bash file by following command:

bash autorunsetup.sh

now your Pi will autorun webcar.py service automatically after starting up.
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 use Ctrl X to save the file.
Now restart your Raspberry Pi. Your web camera control robot car program will start automatically. You can use the browser or mobile APP to control your car and see the camera video.

Reference:
Marcelo Rovai : Python WebServer With Flask and Raspberry Pi
https://towardsdatascience.com/python-webserver-with-flask-and-raspberry-pi-398423cc6f5d