What Do I Build Next? Part 3 of 4. Electronics and software installation on my 16 wheeled platform from Banggood. The following examples, links, software were used in Part 4 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?
Most Maker's will put final build DEMO Video at end of project...I have but this time... I'll lead with it:
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)
cd ~/osoyoo-robot/cam-robot/mjpg-streamer
sudo./start.sh
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.
http://osoyoo.com/2017/08/osoyoo-robot-car-diy-introduction/
http://osoyoo.com/2017/10/09/raspberry-pi-starter-kit-v1-introduction/
http://osoyoo.com/2017/04/arduinosmartcarlesson1/
http://osoyoo.com/2016/06/13/internet-of-thingsiot-starter-kit-on-raspberry-pi/
http://osoyoo.com/2017/05/wifi-control-smart-car/
http://osoyoo.com/2017/05/tracking-smart-car/
http://osoyoo.com/2017/05/arduino_car_obstacle_avoidance/
http://osoyoo.com/2017/04/control-smart-car-with-ir/
http://kookye.com/2018/07/19/rasberry-pi-tank-robot-car-starter-kit-lesson-1package-list/
http://kookye.com/2018/07/19/rasberry-pi-tank-robot-car-starter-kit-lesson-2raspberry-pi-3b-board/
http://kookye.com/2018/07/20/rasberry-pi-tank-car-starter-kit-lesson-3-web-video-camera/
http://kookye.com/2018/07/19/rasberry-pi-tank-robot-car-starter-kit-lesson-3line-follow/
freespinwheel
wheel assembly
treadspin
demomotortest
demoswstreaming
demovideocontrol
1stDemoBuild
http://kookye.com/2018/07/24/raspberry-pi-robot-tank-car-starter-kit-tutorial-guide/#more-6887
http://kookye.com/2018/07/20/rasberry-pi-tank-car-starter-kit-lesson-3-web-video-camera/
****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.
Rasberry Pi Tank Robot Car Starter Kit
Lesson 4: Installation of Electronic Parts
Objective In this lesson, you will install the most important framework in the smart car and make car to do some simple movements as per our python sample code.
If you have passed the test movement of this lesson, that means Arduino, voltage meter, motor drive module(Model-PI), motors, batteries, chassis and wire connections between these parts are all functioning well.
As your experiments in future lessons are all based on frame work of Lesson One, it is very important to test the installation and sample code in this Lesson properly.
Hardware Installation Video in tutorial for Hardware Installation
STEP1. Install raspberry pi board, model pi driver board and 16 Channel 12-bit PWM compatible module as follows.
STEP2: Install the Voltage Meter, Webcam and 5 tracking sensors as follows. (My build did not include these at this time...your's can)
STEP3:Connect the electronic parts as follows:
(1)Connect right and left motors to K1 and K3 sockets in model pi driver board. ( I wired mine to the L298N Driver Board)
STEP3-1 (2)Connect 1st battery box (2 x 18650=8.4vdc) and 5vdc (USB 5v 2A external) battery box to the L298N as follows.
STEP3-2 (3)Connect 16 Channel 12-bit PWM compatible module to the L298N board as follows.(5vdc and gnd)
STEP3-3 (4)Connect right and left LED light to 16 Channel 12-bit PWM compatible module as follows.(did not connect LED's at this point)
STEP3-4 (5)Connect raspberry pi board to 16 Channel 12-bit PWM compatible module as follows.
STEP3-5 (6)Connect 5 tracking sensors to 16 Channel 12-bit PWM compatible module as follows.(did not install)
II.Software Installation
Software Preparation:
Imager utility: Win32DiskImager utility
OS: Raspbian (Use OS Raspbian 2018-04-18 in the subsequent tutorials)
Format Tool: SDFormatter (Optional) or Balenaio
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.write_raspbian
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.
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.x.x)……(in my case in was 10.0.x.x)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:
sudo raspi-config
Then select
Interfacing Options->SSH->Yes->Ok->Finish (I also enbled I2C, CAMERA, VNC, SPI as well)
step2-1-advanced_option
step2-2-SSH
step2-3-SSH_Yes
step2-4-SSH-Yes
step2-5-SSH_finish
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 pi@192.168.50.7(????????????)
ssh your_raspberry_pi_local_ip_address
*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.
( I also finished any localizations for my country and time zone)
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:
sudo raspi-config
Then select
Interfacing Options->I2C->Yes->Ok->Finish
Step 5: Install GPIO Library
(1)Update Rasbian Repository by typing following terminal command
cd ~
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 command
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
sudo python setup.py install
(4)Typing following terminal command to remove installation files and save disk space
cd ~
sudo rm -fr Adafruit_Python_GPIO
Testing Previous Installation•
(5)Download testing python code by typing following commands:
cd ~
mkdir -p osoyoo-robot/
cd osoyoo-robot/
wget http://osoyoo.com/driver/motor-test-tank.tar.gz
tar -zxvf motor-test-tank.tar.gz
cd motor-test
Testing
Step 6: Run Testing Python code
cd ~/osoyoo-robot/motor-test
python motor-test.py
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.___________________________________________
Rasberry Pi Tank Robot Car Starter Kit
Lesson 6: Web Control Camera
Objective
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.
Software Installation
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.
ifconfig wlan0 IP address
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
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 Pisudo raspi-config(B) Edit “/etc/modules” file by typing following command(otherwise /dev has no camera device node)sudo nano /etc/modulesPlease 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 editorbcm2835-v4l2 (l is lowercase letters l, not digital 1)
Step 4:download and install mjpg-streamer support library by typing following command
cd ~
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
cd ~/osoyoo-robot/cam-robot/mjpg-streamer
cd plugins/input_uvc
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”
exit nano editor
(2) we need compile the source code with following commands:
cd ~/osoyoo-robot/cam-robot/mjpg-streamer
make all
(3) test camera installation: Plug your camera into Raspberry Pi, then type following command:
ls /dev/video*
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:
sudo./start.sh
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 mjpg-streamer server
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.pymyscript = /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-controldoc-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:0x22pwm0 = 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”
exit nano editor
Testing
Step 7:Testing
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:
cd ~/osoyoo-robot/cam-robot/mjpg-streamer
sudo./start.sh
(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 Osoyoo or Kookye's 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
Password: raspberry
Video Port:8899
Click Save button and exit config page
Now you can use the arrow buttons in App to control the car
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.
Comments