What Do I Build Next? Part 4 of 4. Electronics and software installation on my 12 wheeled platform from Banggood. The following examples, links, software were used in Part 3 of 4 as well.
Usually I would leave DEMO Video until bottom of project, but this time I'll lead with it. A few lessons after viewing and driving... I'll need to investigate further why the turning/steering is much slower than I had envisioned. Possibly need to run the four motors/ two pairs on separate L298N controllers with separate batteries?
Below is a setup/drive/control guide:
1. Use SSH and Putty to remote into the Tank Vehicle, open two terminal sessions to launch each control app.
2. Start WebIOPi (in 1st Terminal window, once logged into the Robot, in my case using the "Up arrow" on keyboard returned last command entered
sudo webiopi -d -c /etc/webiopi/config
3. Start MpegStreamer (in 2nd Terminal window, once logged into the Robot type)
4. Open "Chrome" Browser to Web Control App and enjoy (in may case, http://10.0.0.156:8000)
Guide(s) and Weblinks:
Giving acknowledgments to Kookye and Osoyoo for their well documented guides that allowed me to adapt my existing hardware to the code examples.
All these links and examples have been used by myself to build Projects/Robot Cars based upon the Arduino and Raspberry Pi controllers that I have purchased and have used to expand my knowledge and apply to other form factors.
You should also.
****As of 4/20/19, I am still waiting for a right angle Micro USB connector that I can use on the Raspberry Pi power connection for the 5Vdc 2A USB battery pack and also the HC-SR04 Ultrasonic Sensor and mount. I am also debating the Pi Camera mount.... a Pan-n-tilt servo assembly... but that'll require extensive code revision... or just the fixed camera mount. I also haven't installed the LED headlights or the Battery Voltage display meter. The weather here has been raining for almost two weeks off and on and always when I have the time to bring my tank outside for some "off-road" testing... that'll be fun.
1. Gather Hardware and Electronics
2. Build Robot chassis
3. Interconnect Control Electronic modules
4. Install Raspbian Image on SD card
5. Build/Configure Raspberry Pi
6. RPi localization, WIFI, updates, upgrade
7. Connect PiCamera
8. Connect Electronic Parts- PCA9685 to L298N and to RPi
9. Connect Robot chassis motors to L298N motor controller
10. Install Software for Motor Control
11. Install WebIOPI
12. Install WebStreamer
13. Modify/Customize WebInterface
14. Test and have FUN
15. Future MOD-Create a Local AP following Adafruit's Guide
Smart Robot Tank Car Chassis
Rasberry Pi Tank Robot Car Starter Kit Lesson 4:Installation of Electronic Parts
Following Osoyoo and Kookye's guides, You will be able to install the most important framework in either version of the smart car/tank and make your vehicle to do some simple movements as per Osoyoo/Kookye python sample code. If your vehicle have passed the test movements of this lesson, that means ALL electronics (Arduino, voltage meter, motor drive module(Model-PI), motors, batteries, chassis) or (Raspberry Pi, Pi Camera, L298N, PCA9685, motors, chassis) and wire connections between these parts are all functioning well.
Installation of the WebStreamer and WebIOPI software are both based on frame work of the Osoyoo/Kookye python sample code, it is very important to test the installation and sample code in this Lesson properly.
I. Hardware Installation
STEP1: Install raspberry pi board, model pi driver board and 16 Channel 12-bit PWM compatible module as follows.
STEP2:Install the Raspberry Pi Camera or Webcam (Only follow Pi camera steps)
STEP3:Connect the electronic parts as follows:
(1)Connect right and left motor pairs to K1 and K3 sockets in model pi driver board.
(2)Connect two seperate battery boxes, one (6v-12vdc) for L298N motor controller and the 2nd (5vdc 2A) to model pi driver board as follows.(Only Battery packs)
(3)Connect 16 Channel 12-bit PWM compatible module to model pi driver board as follows.
(4)Connect raspberry pi board to 16 Channel 12-bit PWM compatible module as follows.
Imager utility: Win32DiskImager utility or Balena.IO Etcher
OS: Raspbian (Use OS Raspbian 2018-04-18 in the subsequent tutorials)(I used latest Stretch Desktop)
Format Tool: SDFormatter (Optional) or BalenaEtcherIO
SSH Tool: PuTTY (for Windows users)
Step 1:Before connect to Raspberry Pi, you need to install Raspbian Operation System(OS) onto SD card.You can select the latest version of RASPBIAN system on the official website: https://downloads.raspberrypi.org/raspbian/images/. Write the image via Win32DiskImager utility into your microSD/TF card(minimum 16G), then plug the card into the slot on your Raspberry Pi.
Step 1: Connect Wifi
Firstly, Connect Raspberry Pi to your HDMI monitor or TV. Put a keyboard and mouse into Raspberry Pi USB ports. Insert SD card into the slot on your Raspberry Pi. Connect 5vdc 2A power adapter. Allow to boot to desktop. Recent builds will automatically resize image to fill SD card, allow this to happen. Next, the setup script will guide you through required "localization tasks" inorder to get WIFI/network connections established. Click on the wireless icon top right on desktop, should give a list of access points, select your wifi ssid and connect it. Once your Pi is connect to Wifi, you can hover your mouse to the wifi icon to see the your IP address.
Or your can type sudo ifconfig wlan0 command in terminal. Your local ip address will show in wlan0 block(right side of the word inet addr:). It will look like 192.168……
Please remember above IP address, it will be used in our next steps.
Step 2: Open SSH connection
SSH enable user to type shell command remotely from internet so that we can control the car through wifi.In order to enable SSH function, we need type following command from terminal:
Then select Interfacing Options->SSH (I also select PiCamera, I2C, VNC, SPI)->Yes->Ok->Finish
step2-1-advanced_option (I also selected I2C, CAMERA, SPI, VNC as well as did my localizations for country and timezone, then reboot)
(In Network settings you can change your hostname from default "raspberrypi" to something else....)
Reboot your Raspberry Pi
Step 3:Use SSH to connect Raspberry Pi terminal remotely
In order to make the car moving freely, we need disconnect Raspberry Pi from monitor, keyboard/mouse and use SSH to send command to Raspberry Pi terminal remotely.
If you are using Windows to send ssh command. you need download a free software called PuTTy to connect the Raspberry Pi local IP(you got from STEP 1).
If you are using MacBook or other linux computer, please type: ssh email@example.com
*your_raspberry_pi_local_ip_address means the wifi IP address you got from STEP 1
When connecting ssh, you need use default user name pi and default password raspberry to login to Raspberry Pi.
Step 4: Open I2C function
I2C is a protocol which will be used to exchange data with I2C device. In our project, I2C device is PCA9685 module.In order to use I2C function, we need type following command from terminal:
Then select Interfacing Options->I2C->Yes->Ok->Finish ****(I enabled Camera, SSH, I2C, SPI, VNC as well)
Step 5: Install GPIO Library
•(1)Update Rasbian Repository by typing following terminal commands :
sudo apt-get update
sudo apt-get upgrade
•(2)Install python-pip, python-sumbus and github
sudo apt-get install build-essential python-pip python-dev python-smbus git
•(3)Install GPIO Library by typing following terminal commands :
sudo python setup.py install
•(4)Typing following terminal command to remove installation files and save disk space *****(I left the installation files just in case)
sudo rm -fr Adafruit_Python_GPIO
Testing Previous Installation
•(5)Download testing python code by typing following commands :
mkdir -p osoyoo-robot/
tar -zxvf motor-test-tank.tar.gz
Step 6: Run Testing Python code
After running above python sample code, your car should move forward for 2 seconds, then move backward for 2 seconds, then turn left for 2 seconds and finally turn right for 2 seconds.
If your car does not move as per above scenario, the installation should have some problem. You need double check the wire connection and software installation as per our previous steps.
Verify input battery power (6v-12Vdc) connections to L298N Motor Controller and (5V dc) to PCA9685 16 Channel 12-bit PWM compatible module.
Rasberry Pi Tank Robot Car Starter Kit Lesson 6: Web Control Camera
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 :
sudo apt-get install rpi.gpio -y
mkdir -p osoyoo-robot/cam-robot
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
(2)Install WebIOPi patch
patch -p1 -i webiopi-pi2bplus.patch
(4).You need verify the installation by typing following command
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]
- 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
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 commands :
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) Next step is to 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 what you “see” video from camera and control Robot Car with browser, you need change some of the default settings of WebIOPi and MJPG-streamer. To do so, you need to edit their config file by typing following command and modify these files as listed in cases: Modification A, Modification B, Modification C:
sudo nano /etc/webiopi/config
replace webiopi default script python file which allow you to send control signal to your Pi Platform from any Browser, please add the following pink line into
# 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
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: *****(Make sure that you have connected and tested the PCA9685 I2C module first)
Add PCA9685 address into config by addling following pink line
# 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
#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.
My 12WD Demo (I am still waiting for Pi Camera mounting hardware and Micro-USB power cable for separate battery connection for the Pi).
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 http://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 raspberry pi ip Port: 8000
User Name: webiopi
As of April 20, 2019, I am waiting for a right angled Micro-USB power connector for the Raspberry Pi to Battery connection. I am also waiting for a HC-SR04 sensor mount to use a my PI CAMERA mount. I haven't decided on the pan-n-tilt mechanism yet.
The weather here for the past two weeks has been rainy, preventing any outside filming and testing, that I know I want to show you all. Actually, to determine which battery pack, 12vDC or 6vDC battery supplies for motors.
Oh, By the Way... there is a Part 5 of 4 in progress. Since I have the Kookye Arduino Robot Tank Kit electronics kit, I have started to put it together and will retrofit those electronics to one of my current builds.