In this tutorial, we will show how to use Arduino to control an Osoyoo Brand Mecanum wheel robot and how to assemble it.
The content shown in this tutorial is based on the tutorial provided by the brand Osoyoo containing some images of their property as you can see here.
This tutorial also shows you how to install the chassis of this car and connect Arduino control signal wires to two model-X (L298N) motor driver boards. This installation will be the start point of our other posts about this robot.
Parts Required
You can buy your kit @Amazon
- 1x Mecanum wheels robotic car chassis (2x left-wheels +2x right-wheels and 4x motor)
- 1 x Arduino Mega2560
- 1 x Wifi Shield
- 2 x Model X motor driver
- 1 x battery box
- 2x 18650 batteries(3.7V) + charger
- Jumper wires
Procedure
Following are the steps required to perform this tutorial.
Hardware Assembly
Step 1: Install 16pcs M3 plastic screws and plastic pillars as per the chassis screw location map (view from top).
Step 3: Fasten the 4 motors onto the 4 standoffs. Make sure the motor directions must be correct (exactly same as picture).
Step 4: Install the 4 wheels with 4pcs M2.6×14 screws as per the following pictures (view from bottom of the chassis).
The Mecanum wheel has some sub-wheels on the main wheel. The four Mecanum wheels have two types by the sub-wheel directions. Check the type A wheel and type B wheel by following picture 8 left side . You must be 100% sure that the correct type of wheel is installed into correct position as per picture 8 right side, the rolling direction of each wheel will determine the whole car moving directions showed in the picture.
Different rotation combination of 4 wheels will result in different car movement directions. Following pictures shows how they works.
Step 5: Install Mega2560, 2pcs model X boards(L298N), Wifi shield and voltage meter onto the chassis with M3 nuts.
Step 6: Install battery box with 4pcs M3x10 screws.
Step 7: Insert OSOYOO Uart WIFI shield onto your mega2560 board.
Circuit Connection
Step 1: Connect front model X board (L298N) to front motors as per the picture.
Step 2: Connect rear model X board(L298N) to rear motors as per the picture.
Step 3: Connect front model X control pins to MEGA2560 with 6pin male to female jumper wire.
Note: purple wire is connected to D22 which is located on the SECOND female hole from right in following.
Front Model X board IN1,IN2,IN3,IN4 pin connect to D22,D24,D26,D28.
Step 4: Connect Rear model X control pins to Mega2560 with 6pin male to female jumper wire.
Step 5: Connect Voltage meter to model X with 3pin female to female jumper wire.
Step 6: Connect OSOYOO two model X board 12V-GND socket with 2pin PnP cable 20cm as per following image.
Code
#define SPEED 100 #define TURN_SPEED 100 #define speedPinR 9 // Front Wheel PWM pin connect Right MODEL-X ENA #define RightMotorDirPin1 22 //Front Right Motor direction pin 1 to Right MODEL-X IN1 (K1) #define RightMotorDirPin2 24 //Front Right Motor direction pin 2 to Right MODEL-X IN2 (K1) #define LeftMotorDirPin1 26 //Front Left Motor direction pin 1 to Right MODEL-X IN3 (K3) #define LeftMotorDirPin2 28 //Front Left Motor direction pin 2 to Right MODEL-X IN4 (K3) #define speedPinL 10 // Front Wheel PWM pin connect Right MODEL-X ENB #define speedPinRB 11 // Rear Wheel PWM pin connect Left MODEL-X ENA #define RightMotorDirPin1B 5 //Rear Right Motor direction pin 1 to Left MODEL-X IN1 ( K1) #define RightMotorDirPin2B 6 //Rear Right Motor direction pin 2 to Left MODEL-X IN2 ( K1) #define LeftMotorDirPin1B 7 //Rear Left Motor direction pin 1 to Left MODEL-X IN3 (K3) #define LeftMotorDirPin2B 8 //Rear Left Motor direction pin 2 to Left MODEL-X IN4 (K3) #define speedPinLB 12 // Rear Wheel PWM pin connect Left MODEL-X ENB /*motor control*/ void go_advance(int speed){ RL_fwd(speed); RR_fwd(speed); FR_fwd(speed); FL_fwd(speed); } void go_back(int speed){ RL_bck(speed); RR_bck(speed); FR_bck(speed); FL_bck(speed); } void right_shift(int speed_fl_fwd,int speed_rl_bck ,int speed_rr_fwd,int speed_fr_bck) { FL_fwd(speed_fl_fwd); RL_bck(speed_rl_bck); RR_fwd(speed_rr_fwd); FR_bck(speed_fr_bck); } void left_shift(int speed_fl_bck,int speed_rl_fwd ,int speed_rr_bck,int speed_fr_fwd){ FL_bck(speed_fl_bck); RL_fwd(speed_rl_fwd); RR_bck(speed_rr_bck); FR_fwd(speed_fr_fwd); } void left_turn(int speed){ RL_bck(0); RR_fwd(speed); FR_fwd(speed); FL_bck(0); } void right_turn(int speed){ RL_fwd(speed); RR_bck(0); FR_bck(0); FL_fwd(speed); } void left_back(int speed){ RL_fwd(0); RR_bck(speed); FR_bck(speed); FL_fwd(0); } void right_back(int speed){ RL_bck(speed); RR_fwd(0); FR_fwd(0); FL_bck(speed); } void clockwise(int speed){ RL_fwd(speed); RR_bck(speed); FR_bck(speed); FL_fwd(speed); } void countclockwise(int speed){ RL_bck(speed); RR_fwd(speed); FR_fwd(speed); FL_bck(speed); } void FR_fwd(int speed) //front-right wheel forward turn { digitalWrite(RightMotorDirPin1,HIGH); digitalWrite(RightMotorDirPin2,LOW); analogWrite(speedPinR,speed); } void FR_bck(int speed) // front-right wheel backward turn { digitalWrite(RightMotorDirPin1,LOW); digitalWrite(RightMotorDirPin2,HIGH); analogWrite(speedPinR,speed); } void FL_fwd(int speed) // front-left wheel forward turn { digitalWrite(LeftMotorDirPin1,HIGH); digitalWrite(LeftMotorDirPin2,LOW); analogWrite(speedPinL,speed); } void FL_bck(int speed) // front-left wheel backward turn { digitalWrite(LeftMotorDirPin1,LOW); digitalWrite(LeftMotorDirPin2,HIGH); analogWrite(speedPinL,speed); } void RR_fwd(int speed) //rear-right wheel forward turn { digitalWrite(RightMotorDirPin1B, HIGH); digitalWrite(RightMotorDirPin2B,LOW); analogWrite(speedPinRB,speed); } void RR_bck(int speed) //rear-right wheel backward turn { digitalWrite(RightMotorDirPin1B, LOW); digitalWrite(RightMotorDirPin2B,HIGH); analogWrite(speedPinRB,speed); } void RL_fwd(int speed) //rear-left wheel forward turn { digitalWrite(LeftMotorDirPin1B,HIGH); digitalWrite(LeftMotorDirPin2B,LOW); analogWrite(speedPinLB,speed); } void RL_bck(int speed) //rear-left wheel backward turn { digitalWrite(LeftMotorDirPin1B,LOW); digitalWrite(LeftMotorDirPin2B,HIGH); analogWrite(speedPinLB,speed); } void stop_Stop() //Stop { analogWrite(speedPinLB,0); analogWrite(speedPinRB,0); analogWrite(speedPinL,0); analogWrite(speedPinR,0); } //Pins initialize void init_GPIO() { pinMode(RightMotorDirPin1, OUTPUT); pinMode(RightMotorDirPin2, OUTPUT); pinMode(speedPinL, OUTPUT); pinMode(LeftMotorDirPin1, OUTPUT); pinMode(LeftMotorDirPin2, OUTPUT); pinMode(speedPinR, OUTPUT); pinMode(RightMotorDirPin1B, OUTPUT); pinMode(RightMotorDirPin2B, OUTPUT); pinMode(speedPinLB, OUTPUT); pinMode(LeftMotorDirPin1B, OUTPUT); pinMode(LeftMotorDirPin2B, OUTPUT); pinMode(speedPinRB, OUTPUT); stop_Stop(); } void setup() { init_GPIO(); go_advance(SPEED); delay(1000); stop_Stop(); delay(1000); go_back(SPEED); delay(1000); stop_Stop(); delay(1000); left_turn(TURN_SPEED); delay(1000); stop_Stop(); delay(1000); right_turn(TURN_SPEED); delay(1000); stop_Stop(); delay(1000); right_shift(200,200,200,200); //right shift delay(1000); stop_Stop(); delay(1000); left_shift(200,200,200,200); //left shift delay(1000); stop_Stop(); delay(1000); left_shift(200,0,200,0); //left diagonal back delay(1000); stop_Stop(); delay(1000); right_shift(200,0,200,0); //right diagonal ahead delay(1000); stop_Stop(); delay(1000); left_shift(0,200,0,200); //left diagonal ahead delay(1000); stop_Stop(); delay(1000); right_shift(0,200,0,200); //right diagonal back delay(1000); stop_Stop(); delay(1000); } void loop(){ }
References
[1] https://osoyoo.com/2019/11/13/mecanum-omni-wheel-robotic-kit-v1-for-arduino-mega2560-lesson-14/