Buy from OSOYOO 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.

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.

Step 1) Download OSOYOO IoT 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 2) 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 3) Download The code to your raspberry Pi by typing following command:

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

Step 4) Open battery switch in robot car, put it in the ground, Run The python code in Raspberry Pi to make the car move:

python picar-udp.py

How to Control the Car:

Click ▲ Key, car will move forward
Click ▼ Key, car will move backward
Click ► Key, car will turn right
Click ◄ Key, car will turn left
Click [] Key, car will Stop

Another way to control Steering instead of ► ◄

You can move the top horizon slider to steer the car direction. When slider moves to right, car will steer to right. When slider to left, car will steer to left.
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 31,32 in picar-udp.py file :

high_speed =0xAFFF
mid_speed =0x8FFF

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, here are the messages sent by each key

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

Actually above key definitions are the default message. You can customize your own   message for each Key in the APP setting page.

Q 3)How does Raspberry Pi python program handle the UDP command?
Line 81 to 114 while loop receives UDP data from APP and give it to viable command,    then the car will do proper action as per the command  variable.
For example, when ▲ key in APP is pressed , based on Q2 table, we know that APP. will send a message “A” to robot car, so line 87 to 89(see following) will call forward() function and make car move forward.

if command =='A': 
   forward(mid_speed,mid_speed) 
   print("go forward")