|Buy from US||Buy from UK||Buy from DE||Buy from IT||Buy from FR||Buy from ES|
In this lesson, we will learn how to let the robot car has vision to see front environment and how to control the robot car through web browser or mobile APP.
To complete this task, we need install a web server software called “mjpg-streamer” in Raspberry Pi, this software will catch video from Robot Car camera and send the video to a web page.
We also need to install another web server software called “WebIOPi” in Raspberry Pi. This software will allow user to use browser to remotely control Raspberry Pi GPIO input/output and therefore control the movement of our robot motor.
Before type the following commands, you need to open the I2C and know your raspberry pi IP address.
(1)If you don’t know your raspberry pi IP address, type following command in your terminal,Your raspberry Pi IP address is in the right side of the word inet addr.
(2)Open I2C function
In order to use I2C function, we need type following command from terminal:
Then select Interfacing Options->I2C->Yes->Ok->Finish
If you know IP address and open I2C function, please skip the above steps.
STEP 1: Download and upzip software package by running following terminal commands
cd ~ sudo apt-get install rpi.gpio -y mkdir -p osoyoo-robot/cam-robot cd osoyoo-robot/cam-robot wget http://osoyoo.com/driver/WebIOPi-0.7.1.tar.gz wget http://osoyoo.com/driver/mjpg-streamer.tar.gz wget http://osoyoo.com/driver/robot-tank.tar.gz tar -xzvf WebIOPi-0.7.1.tar.gz tar -xzvf mjpg-streamer.tar.gz tar -xzvf robot-tank.tar.gz
STEP 2:WebIOPI server Installation
(1)Download WebIOPi patch
cd ~/osoyoo-robot/cam-robot/WebIOPi-0.7.1/ wget http://osoyoo.com/driver/webiopi-pi2bplus.patch(2)Install WebIOPi patch patch -p1 -i webiopi-pi2bplus.patch (3).Compile webiopi sudo ./setup.sh (4).You need verify the installation by typing following command webiopi -h If WebIOPi is installed successfully, you will see following message in terminal, otherwise you might need redo the download and installation.
sudo webiopi [-h] [-c config] [-l log] [-s script] [-d] [port] Options: -h, --help Display this help -c, --config file Load config from file -l, --log file Log to file -s, --script file Load script from file -d, --debug Enable DEBUG Arguments: port Port to bind the HTTP Server
(5)Run webiopi by typing following command
sudo webiopi -d -c /etc/webiopi/config
Use a browser in another computer (your computer/PAD/Phone in same LAN of your Pi) to visit your Pi’s IP address with port “8000” ( i.e http://192.168.50.7:8000, please replace 192.168.50.7 with your Pi’s local IP address), your browser will show WebIOPi login page. You need use default WebIOPi user name “webiopi” and default password “raspberry” to login to the server. Once you are logged into WebIOPi page, you will see WebIOPI Main Menu as following. If you can not see this page , you need to reinstall the WebIOPI software.
Please press “Ctrl” + “C” then “Ctrl” + “Z” in your terminal to end WebIOPi running.
STEP3: Installation mjpg-streamer server
If you are using CSI camera , please take following action as per step A and B . If you are using USB camera which comes with the car, please skip these two step
(A)Enable camera in Raspberry Pi
(B) Edit “/etc/modules” file by typing following command(otherwise /dev has no camera device node)
sudo nano /etc/modules
Please add the following line in the bottom of the “/etc/modules” file, and then press “ctrl” + “x” and then “y” to save the file and press “enter” exist nano editor
bcm2835-v4l2 (l is lowercase letters l，not digital 1)
Step 4:download and install mjpg-streamer support library by typing following command
sudo apt-get update
sudo apt-get install libv4l-dev libjpeg8-dev -y
sudo apt-get install subversion -y
Step 5: Compile mjpg-streamer
(1) edit the configuration file “input_uvc.c” by typing following command
sudo nano input_uvc.c (if vim installed, you can type： sudo vim input_uvc.c)
Find following line(you can use “ctrl” + “W” to search the line when you enter nano editor)
int width=640, height=480, fps=5, format=V4L2_PIX_FMT_MJPEG
Replace the string V4L2_PIX_FMT_MJPEG with new string V4L2_PIX_FMT_YUYV
Then press “ctrl” + “x” and then “y” to save the file and press “enter” exist nano editor
(2) we need compile the source code with following commands:
(3) test camera installation: Plug your camera into Raspberry Pi, then type following command:
You should see following result in your terminal, “/dev/video0” is the camera installed in Pi
(4) Run mjpg-streamer Server by typing following command in terminal:
Now use browser in another computer to access your Raspberry Pi IP address with port 8899 (i.e, if your Pi IP address is 192.168.50.7, visit http://192.168.50.7:8899 in your browser), you will see following image. Click Stream button in left menu, you will see the real time video captched by the camera in your Raspberry Pi
You can use Ctrl C command in terminal to end the mjpg-streamer server
Step 6: To combine webiopi and mjpg-streamer into same webpage which allows we “see” video from camera and control Robot Car with brower, we need change some default setting of WebIOPi and MJPG-streamer. To do so, we need to edit config file by typing following command and modify this file as Modification A, Modification B, Modification C:
sudo nano /etc/webiopi/config
Modification A: replace webiopi default script python file which allow us to send control signal to Pi from Browser, please add following pink line into “/etc/webiopi/config” file
[SCRIPTS] # Load custom scripts syntax : # name = sourcefile #each sourcefile may have setup, loop and destroy functions and macros
#myscript = /home/pi/WebIOPi-0.7.1/examples/scripts/macros/script.py
myscript = /home/pi/osoyoo-robot/cam-robot/robot/script.py
Modification B. change webiopi default html file path by adding following pink line:
# Use doc-root to change default HTML and resource files location #doc-root = /home/pi/WebIOPi-0.7.1/examples/servo-control
doc-root = /home/pi/osoyoo-robot/cam-robot/robot
Modification C. Add PCA9685 address into config by addling following pink line
[DEVICES] # Device configuration syntax: # name = device [args...] # name : used in the URL mapping #device : device name #args : (optional) see device driver doc #If enabled, devices configured here are mapped on REST API /device/name #Devices are also accessible in custom scripts using deviceInstance(name) #See device driver doc for methods and URI scheme available # Raspberry native UART on GPIO, uncomment to enable # Don't forget to remove console on ttyAMA0 in /boot/cmdline.txt # And also disable getty on ttyAMA0 in /etc/inittab #serial0 = Serial device:ttyAMA0 baudrate:9600 # USB serial adapters #usb0 = Serial device:ttyUSB0 baudrate:9600 #usb1 = Serial device:ttyACM0 baudrate:9600 #temp0 = TMP102 #temp1 = TMP102 slave:0x49 #temp2 = DS18B20 #temp3 = DS18B20 slave:28-0000049bc218 #bmp = BMP085 #gpio0 = PCF8574 #gpio1 = PCF8574 slave:0x21 #light0 = TSL2561T #light1 = TSL2561T slave:0b0101001 #gpio0 = MCP23017 #gpio1 = MCP23017 slave:0x21 #gpio2 = MCP23017 slave:0x22
pwm0 = PCA9685 slave:0x40
#PWM1 =PCA9685 #pwm1 = PCA9685 slave:0x41 #adc0 = MCP3008 #adc1 = MCP3008 chip:1 vref:5 #dac1 = MCP4922 chip:1
Finally, press “ctrl” + “x” and then “y” to save the file and press “enter” exist nano editor
Now you can put your car on the ground and turn on the power-switch in battery box. We need to use SSH to control the car. So you must enable SSH with raspi-config command before testing. If you are using windows, please use download Putty to ssh your Pi, if you are using MacBook, please directly use ssh command in terminal.
(1) To start mjpg-streamer, in ssh terminal, please type followinig command:
(2) To start webiopi, please open another ssh window and type following command:
sudo webiopi -d -c /etc/webiopi/config
Now you can use your browse to acess Raspberry IP with port 8000(i.e, if your Pi IP address is 192.168.0.115, please visit http://192.168.50.7:8000, you will see following picture in your browser, click arrow buttons, you can make car moving to your desired directions.
You can also use our free Android App or Apple App instead of browser to control the car.
Download the Apple app from Apple APP store.
Download the Android app from google play or https://osoyoo.com/driver/osoyoo-robot.apk
Run the App, click set up and enter config page set the fields as following:
IP Address: 192.168.50.7
Your raspberrr pi ip Port: 8000
User Name: webiopi
Click Save button and exit config page
Now you can use the arrow buttons in App to control the car
DownLoad Url osoyoo.com