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

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


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.

You will learn how to use Python  get remote data (UDP packet) from mobile APP.

If you are interested in C++ programming, this project has a C++ version in following link:
https://osoyoo.com/2020/11/08/osoyoo-pie-v2-0-car-lesson-4-use-mobile-app-to-control-car-with-udpc-language/



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 20Pin jumper wire female to female 20cm some
7 Philips screwdriver 1 Click here to buy


Step 1: Install the smart car basic frame work as per lesson 3. If you don’t install tracking sensor module, please completed installation in Lesson 2.



Osoyoo Wifi Robot APP search “Osoyoo Wifi UDP Robot APP” in
Google Play or Apple Store

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:

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/picar/picar-udp-control.py


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

python picar-udp-control.py

or if you want to use Python3, typing:

python3 picar-udp-control.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 3

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

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

FAQ about the Wifi UDP APP and sketch Code:

Q1)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 = 4000  # Max pulse length out of 4096
mid_speed = 2000  # Max pulse length out of 4096
low_speed = 1000  # 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

Q3)How does Raspberry Pi python program handle the UDP command?
Line 290 to 318 while loop receives UDP data from APP and give it to viable cur_status, ticker function in line 266 – 280 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.