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

In this lesson, we will teach you how to use mobile APP to control Robot car through UDP protocol. The Raspberry Pi will run a Python program to get UDP packet from APP.

No. Picture Device Qty. Accessories Link
1 Ultrosonic Sensor 1 M1.4*8 Screw x 4
M1.4 Nut 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 Ultrasonic Sensor 1 M1.4*8 Screw x 4
M1.4 Nut x 4
M2*4 Self Tapping Screw x 1
Click here to buy
4 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
5 7pin 25cm Female to Female Cable 1 Click here to buy
6 10Pin jumper wire female to female 20cm some
7 Philips screwdriver 1 Click here to buy

Must Install  Lesson 3 (Line Tracking ) and Lesson 4 (Obstacle Avoidance) First.

Remember : Keeping all existing wires installed in Lesson 1 -lesson4.

Osoyoo WIFI Robot APP search “Osoyoo WIFI UDP Robot APP” in
Google Play or Apple Store
(
If you can not find this APP in Google Play,
you can directly download the APP from following link:
https://osoyoo.com/driver/udp-app.apk )

Step 1) Download OSOYOO WIFI UDP Robot Car control APP

In Google Play or Apple Store, please search key words “OSOYOO WIFI UDP Robot Car”, you will find an orange icon APP as following (Note: If you can not find this APP in Google Play, you can directly download the APP from following link: https://osoyoo.com/driver/udp-app.apk) :

Step 2) Make sure you have installed rpi.gpio and adafruit-pca9685 library in lesson 1 .

Step 3) Type following command to download the sample code:

wget http://osoyoo.com/driver/servo-steer-car/picar-udp.py

Step 4)Type following command to run the sample code:

python picar-udp.py

or if you want to use Python3, typing:

python3 picar-udp.py

After above python is running, your car is waiting for command from  your cell phone.

Step 5) Connect your phone with the same router wifi SSID your raspberry pi use. Open the APP, click Settings, enter your Raspberry Pi IP address and Port to 8888 in settings:

Now your  can click the < > ^ v direction keys to make the car move. Use || pause key to stop the car movement.

If you click Obstacle key, the car will do obstacle avoidance auto driving similar to Lesson 4

If you click Tracking key, the car will do link tracking auto driving similar to lesson 3

Note: F1~F6 are further development functions in the future.

FAQ about the WIFI UDP APP and sketch Code:

Q 1)How to tune the robot car speed?
A: If you want change the speed performance of the robot car, please change values following parameters in line 19-21 in picar-udp-control.py file :

high_speed = 3500  # Max pulse length out of 4096
mid_speed = 1900  # Max pulse length out of 4096
low_speed = 1700  # Max pulse length out of 4096

Q 2)What happened when you press  buttons in OSOYOO WiFi UDP Robot Car APP ?
A: When you press a button of the APP, APP will send a single-letter message through UDP protocol to target device Raspberry Pi

Button UDP message
F1 F
F2 G
F3 H
F4 I
F5 J
F6 K
A
B
R
L
square E
obstacle O
tracking T

Q 3)How does Raspberry Pi python program handle the UDP command?
Line 319 to 347 while loop receives UDP data from APP and give it to viable cur_status, ticker function in line 292 – 307 handle the cur_status :

def ticker():	
    if cur_status=='R':
    	turnRight(high_speed,0)
    if cur_status=='L':
    	turnLeft(0,high_speed)
    if cur_status=='A':
    	forward(mid_speed,mid_speed)
    if cur_status=='B':
    	backward(mid_speed,mid_speed)
    if cur_status=='E':
    	stopcar()
    if cur_status=='T':
    	line_tracking()
    if cur_status=='O':
    	obstacle_avoid()

For example , when APP ▲ key is pressed , cur_status value is A , then ticker() function call forward(mid_speed,mid_speed) function to make car moving forward.