I.Objective
II.Parts and Devices
III.Hardware Installation
IV.Circuit Connection
V.Software Installation
VI.How to play

Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP



There are many ways to control Raspberry Pi Robot Car over Internet.  In this project, we introduce a   popular method which is to install a Web Server on Raspberry Pi. In other words, we can turn our Pi board into a website and use browse or Cell phone APP  to exchange data with Raspberry Pi.

After completing this project, you can visit the Raspberry Pi IP address and see the online status of the  5 Tracking sensors installed in Lesson 2 in your browser window.



No. Picture Device Qty. Accessories Link
1 Tracking sensor module 1 M2.5 Plastic Screw x 2
M2.5 Plastic Nut x2
M2.5 Plastic Pillar x 2
Click here to buy
2 7pin 25cm Female to Female Cable 1 Click here to buy
3 Philips screwdriver 1 Click here to buy


Step 1: Install the smart car basic frame work as per Lesson 2.



Step 1) Download installation shell script file by typing following command:

wget http://osoyoo.com/driver/picar/pi-webserver.sh

and then type following command:

bash pi-webserver.sh

After running above commands, you will install python Flask library and then create a directory called picar-lesson3 and two sub-directories under picar-lesson3 which are static and templates, the structure is as follows:

The pi-webserver directory will store our python code file, static directory will store css file and templates folder will store html files. If you don’t know what is HTML, CSS file, it doesn’t matter.

Step 2) type the command “hostname -I” to get your Raspberry Pi’s IP, after running the command, you will see following result:

In above result, 192.168.0.107 is the IP address of my Raspberry Pi.

Step 3) We need to edit python code file and change the IP address in the file.

Type following commands to enter the pi-webserver folder:

cd pi-webserver


Please type the following command to edit the file pi-webserver.py

nano pi-webserver.py

Please replace “192.168.0.107”  with your Raspberry Pi IP address, and then click “ctrl” and “x” then click “Y” to save the file and then click “enter” to exit the file.

You will open pi-webserver.py in nano editor and see the python code as follows:

import RPi.GPIO as GPIO
from flask import Flask, render_template, request
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
pi_ip_address='10.0.0.89' # replace this ip value with your Raspberry Pi IP address, you can use ifconfig command to see the IP

#define actuators GPIOs
sensor1= 25 # No.1 sensor from right
sensor2= 9 # No.2 sensor from right
sensor3= 11 # middle sensor
sensor4= 8 # No.2 sensor from left
sensor5= 7 #No.1 sensor from left
#initialize GPIO status variables
Sts1 = 0
Sts2 = 0
Sts3 = 0
Sts4 = 0
Sts5 = 0

# Define sensor pins as output
GPIO.setup(sensor1, GPIO.IN)   
GPIO.setup(sensor2, GPIO.IN) 
GPIO.setup(sensor3, GPIO.IN) 
GPIO.setup(sensor4, GPIO.IN)   
GPIO.setup(sensor5, GPIO.IN) 

		
@app.route("/")
def index():
	# Read Sensors Status
	Sts1 = GPIO.input(sensor1)
	Sts2 = GPIO.input(sensor2)
	Sts3 = GPIO.input(sensor3)
	Sts4 = GPIO.input(sensor4)
	Sts5 = GPIO.input(sensor5)

	
	templateData = {
      'title' : 'IR tracking sensor Status!',
      'sensor_status_1'  : Sts1,
      'sensor_status_2'  : Sts2,
      'sensor_status_3'  : Sts3,
      'sensor_status_4'  : Sts4,
      'sensor_status_5'  : Sts5
      }
	return render_template('index.html', **templateData)

if __name__ == "__main__":
   app.run(host=pi_ip_address, port=80, debug=True)

 

Step 4) Run the code by typing following command:

sudo python pi-webserver.py

Step 5) Your python flask web server will start. Now in your PC or cell phone which is the same wifi network of your Raspberry Pi, open broswer and visit http://your_raspberry_pi_ip_address (in my case http://192.168.0.107) , you will see your 5 tracking sensors status in your browser:

the sensor status will be updated every 5 seconds, so if you put the black line under other sensors, the sensor value in above web page will change after 5 seconds.