I. Objective
II. Parts and Devices
III. Hardware Installation
IV. Software Installation

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 a mobile APP to control a Robot car through UDP protocol. The Raspberry Pi will run a Python program to get a UDP packet from APP.

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

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

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

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

Step 2) Turn on the robot car and type the following command to download the sample code:

wget http://osoyoo.com/driver/picar/picar-udp-control.py

Step 3) Type the following command to run the sample code (ATTENTION: please select a correct command according to your Pi board):

If you are using Python 2 in Raspberry Pi 3, type:

python picar-udp-control.py

or if you are using Python 3 in Pi 4/3A+, type:

python3 picar-udp-control.py

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

Step 4) Download OSOYOO Wi-Fi UDP Robot Car control APP
In Google Play or Apple Store, please search keywords “OSOYOO IoT UDP Robot APP”, you will find a red 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 5) Connect your phone with the same router Wi-Fi SSID of Raspberry Pi use. Open the APP, click “settings icon(1)” to enter setting UI, enter your Raspberry Pi IP address and Port to 8888, click Save, then click back icon(5) to back control UI as following:

Step 6)

Now, put the car on the ground, and you can click the < > ^ v direction keys to make the car move. Use || pause key to stop the car movement.

If you click Obstacle key(F8), the car will do obstacle avoidance auto driving similar to Lesson 3

If you click Tracking key (F7), 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 IoT UDP APP and sketch Code:

Q1)How to tune the robot car speed?
A: If you want to 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 IoT UDP Robot APP ?
A: When you press a button of the APP, the APP will send a single-letter message through UDP protocol to target device Raspberry Pi

Button UDP message
F1 /
F2 /
F3 /
F4 /
F5 /
F6 /
square Stop
F7 Tracking
F8 obstacle

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':
    if cur_status=='L':
    if cur_status=='A':
    if cur_status=='B':
    if cur_status=='E':
    if cur_status=='T':
    if cur_status=='O':

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.