I.Objective
II.Parts and Devices
III.Hardware Installation
IV.Software Installation
VI.How to play
Buy from US | Buy from UK | Besorgen DE | Acquistare IT | Acheter FR | Comprar ES | ここでご購入を! |
In this project, we will connect the Robot Car to Wi-Fi and Use an APP to control the car through Wi-Fi. This is a typical Internet of Things (IoT) Application.
Lesson 1, Lesson 2, Lesson 3 must be completed before doing this lesson.
OSOYOO Mecanum wheels robotic car chassis x1
OSOYOO Wheels and motors x4 (left-wheels x2/right-wheels x2)
OSOYOO Mega2560 board, fully compatible with Arduino UNO/Mega2560 x1
OSOYOO Uart Wi-Fi shield x1
OSOYOO Model Y driver board x1
OSOYOO Voltage meter x1
OSOYOO Battery box x1
OSOYOO 3pin female to female jumper wire x1
OSOYOO 6pin male to female jumper wire x2
OSOYOO 10pin male to female jumper wire x1
OSOYOO 2 pin XH.25 female to female x1
18650 Batteries(3.7V) x2
Battery charger x1
If you just finish all lesson 1-3 and lesson 5 (Bluetooth imitation driver), please keep all lesson connections same as is. Then unplug Bluetooth from Wi-Fi Shield.
Step 1. Remove the connection B_TX to D18 and B_RX to D19.
Step 2. Connect E_RX to D18(TX1) and E_TX to D19(RX1).
Only the B_ ends need to be unplugged. The TX and RX pin order is reversed from Bluetooth.
Open-source Arduino Software(IDE) |
Download Arduino IDE here: https://www.arduino.cc/en/Main/Software?setlang=en |
|
7 zip is a free zip utility that unzips zip files |
Download 7zip here for free https://www.7-zip.org/ |
Step 1: Install latest Arduino IDE (If you have Arduino IDE version after 1.1.16, please skip this step). Download Arduino IDE from https://www.arduino.cc/en/Main/Software?setlang=en, then install the software.
Step 2:Please download the library zip file from WiFiEsp-master.zip. Open Arduino IDE →click Sketch →Include Library →Add .ZIP library, then load above zip file into Arduino.
Step 3: Download https://osoyoo.com/driver/mecanum_acrylic_chassis_v2/mc-lesson6.zip, unzip the download zip file mc-lesson6.zip, you will see a folder called mc-lesson6.
Step 4: APP installation-you need to search “OSOYOO Wi-Fi UDP Robot Car Controller” in Google Play or Apple Store, and then install this APP.
Step 5:Arduino Sketch code Installation:
Unzip the downloaded file, enter the mc-lesson6 folder, you will see two sub-folder : mc-lesson6A and mc-lesson6B.
These two folders have program for two Wi-Fi modes:AP mode and STA mode. The Arduino sketches for these two modes are different. Let’s explain these two modes one by one.
When working in AP mode, our robot car itself will become a Wi-Fi Hot Spot. Our cell phone can connect to Robot Car as its Wi-Fi client. The IP address of Robot is fixed as 192.168.4.1. In this case, both the robot car and your cell phone are not connected to WAN.
(1) Unzip the mc-lesson6.zip file, you will see a folder named mc-lesson6A, upload the code into Arduino.
(2) Open your Arduino Serial monitor, and you will see a similar result as AP mode. A new Wi-Fi SSID “osoyoo_robot” with IP address 192.168.4.1 will show up in the window. This means your Robot car has a Wi-Fi Hot Spot name “osoyoo_robot”, its IP address is 192.168.4.1
(3)Now your Robot car become a Wi-Fi Hot Spot and set IP address as “192.168.4.1” to your APP Setting section.
(4) Connect your cell phone to “osoyoo_robot” wifi hot_spot, and you can use the Mobile phone to control the robot car.
(5)You can click the ◄ ► ▲ ▼ direction keys to make the car move. Use “||” pause key to stop the car movement.
Click Obstacle to shift left side, Click Tracking to shift right side.
Click F1 to make upper-left diagonal movement, Click F3 to make upper-right diagonal movement
Click F4 to make back-left diagonal movement, Click F6 to make back-right diagonal movement.
In STA mode, robot car does not work as a Wi-Fi hotspot. Instead, it will become an internet node in your LAN. You need to tell Arduino sketch what is your local router’s Wi-Fi SSID and password, then Arduino talks to the router and get its own LAN IP address from DHCP server. You can use a Mobile APP to access the robot car’s IP address and control its movement.
(1) Unzip the mc-lesson6 file, you will see a folder named mc-lesson6b, then load the mc-lesson6b.ino code into Arduino.
(2) You need to change the code Line 180 and Line 181 :
char ssid[] = “YOUR_ROUTER_SSID”; // replace this with your router wifi SSID
char pass[] = “YOUR_ROUTER_WIFI_PASSWORD”; // replace with your wifi password
(3) Upload the sketch to Arduino. Finally, click the Serial monitor window in upper right corner of Arduino IDE, you will see following result:
(4)In this mode, you will see an IP address, which is our LAN IP address assigned by my router. Please write down this IP address 192.168.50.44 and click Setting to set up robot IP address and set this IP address 192.168.50.44 to your APP Setting section (no need to change default port 8888 in APP).
(5)Now your Robot car is connected to your LAN, you can use Mobile phone under the same LAN to control the robot car. If your APP is in WAN, you need to go to your Router Control Panel, forward Port 80 to Robot car LAN IP address, then you can use Router IP to control the car. This feature makes our robot car A REAL INTERNET OF THING device.
(6)You can click the ◄ ► ▲ ▼ direction keys to make the car move. Use “||” pause key to stop the car movement.
Click Obstacle to shift left side, Click Tracking to shift right side.
Click F1 to make upper-left diagonal movement, Click F3 to make upper-right diagonal movement.
Click F4 to make back-left diagonal movement, Click F6 to make back-right diagonal movement.
FAQ about the WIFI 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 following parameters in line 11 to 13:
#define SPEED 85
#define TURN_SPEED 90
#define SHIFT_SPEED 130
SPEED value determines forward moving speed
TURN_SPEED value determines turning speed
SHIFT_SPEED value determines parallel shifting speed
Q 2)What happened when you press buttons in OSOYOO WiFi UDP Robot Car APP ?
A: When you press a button of the APP, the APP will send a single-letter message through UDP protocol to the target device (in this example, our Arduino WIFI Shield)
Q3)How does Arduino handle the UDP command?
Line 230 to line 245 in mecanum-2560-lesson5A.ino file are the codes which react to Cell phone command. For example, when ▲ is pressed, according to Q1 table, a letter “A” command was sent from Cell phone to Arduino. Line 233 case ‘A’ …. statement will make the car make car moving forward.
char c=packetBuffer[0];
switch (c) //serial control instructions
{
case ‘A’:go_advance(SPEED);;break;
case ‘L’:left_turn(TURN_SPEED);break;
case ‘R’:right_turn(TURN_SPEED);break;
case ‘B’:go_back(SPEED);break;
case ‘E’:stop_Stop();break;
case ‘F’:left_shift(0,150,0,150);break; //left ahead
case ‘H’:right_shift(180,0,150,0);break; //right ahead
case ‘I’:left_shift(150,0,150,0); break;//left back
case ‘K’:right_shift(0,130,0,130); break;//right back
case ‘O’:left_shift(200,150,150,200); break;//left shift
case ‘T’:right_shift(200,200,200,200); break;//left shift
default:break;
}
DownLoad Url osoyoo.com