4WD Omni-directional Mecanum Wheels Robotic Car Kit with Raspberry Pi Pico

4WD Omni-directional Mecanum Wheels Robotic Car Kit with Raspberry Pi Pico

Hello and welcome back! In this project, we are excited to introduce you to the 4WD Omni-directional Mecanum Wheels Robotic Car Kit provided by Adeept. I have had the pleasure of using this smart car for several days, and I must say it has been quite an enjoyable experience.

The primary purpose of this smart car is to serve as a platform for teenagers to learn coding, building, and programming skills. It offers a great opportunity to delve into the world of robotics and acquire knowledge of Python programming language, as it is primarily based on the Raspberry Pi Pico board. Python is widely regarded as the most suitable language for beginners due to its simplicity and versatility.

I have explored this car’s capabilities in various ways, which include obstacle avoidance, line tracking, IR remote control, and WIFI control to maintain distance. However, the beauty of this kit lies in its flexibility, allowing you to customize its functions according to your preferences. The standout feature of this smart car, in my opinion, is the mecanum wheels that enable it to perform Left/Right Parallel Shift, Forward/Backward, Upper Left/Right Diagonal Shift, and Lower Right/Left Diagonal Shift movements. It truly adds an element of fascination to the overall experience. Also, we can see the RGB pixel LED, buzzer, and LCD screen on the main PCB. You can use these components as you like.

OK, let’s assemble this kit step by step. For that, follow the instructions below.

Step 1

Firstly, identify the components in the box.

Step 2

Secondly, remove the acrylic parts stickers and connect the motor brackets to the base part. For that, use the M3 self-locking nuts and M3*10 round-head screws.

Step 3

Thirdly, connect the motors to the motor brackets. For that, use the M3 nuts and M3*25MM screws. And then, connect the robot car front guard. For that, use the M3*10 double-pass copper columns and M3*8 round-head screws.

Step 4

Next, install the copper columns on the base part. For that, use the M3*45 copper columns, M3*30 copper columns, and M3*10 round-head screws.

Step 5

Now, Install the tracking module bottom of the base part. For that, use the M3*14 countersunk head screws, M3 nuts, and M3 nylon columns. And then, connect the cable to the sensor module.

Step 6

And then, install the LCD screen on the structural part and connect the wire connector to it. For that, use the M3 nylon columns, M3 nuts, and M3*10 round-head screws.

Step 7

Now, install the battery holder on the structural part. For that, use the M3*8MM screws and M3 nuts. Then, connect it to the base part with the LCD screen. For that, use the M3*10 round-head screws.

Step 8

Next, install the servo motor on the structural part. For that, use the M2*8 round head screws and M2 nuts. And then, connect this part to the top of the base part. For that, use the M3*10 round-head screws and M3*20 double-pass copper columns.

Step 9

And then, connect the TT motor couplings to the gear motor shafts. Next, Install the Mecanum wheel L and the Mecanum wheel R on the coupling respectively. For that, use the M2.4*20 screws.

Step 10

Next, install the servo cross on the cat face shep structural part. For that, use the P1.2*5 self-tapping screws. Now, adjust the initial angle of the servo to 90. I have used the servo tester for that. And then, connect this part to the servo motor using a servo screw.

Step 11

Now, install the ultrasonic sensor using the M1.6*10 screws, M1.6 nuts, and nylon columns. Next, connect the wire connector to the ultrasonic sensor.

Step 12

OK, now let’s prepare the circuit of this robot. For that, use the picture below.

Step 13

Next, install the Pico Robot Expansion Board on top of the robot car. Then, place the Raspberry Pi Pico board and the ESP8266 module on the board.

Step 14

Now, connect this smart car to the computer. And then, save the below scripts on the raspberry pi pico board.

  • How to set up the Raspberry Pi Pico board — Read me
  • Python scripts — Download
  • Now, save the following script as main.py.
from pico_car import Motor,IR, I2cLcd, Servo
from machine import I2C, Pin
from ws2812 import WS2812
import time
import array
import avoid_obstacles
import line_tracking
import keep_distance


RGB_LED = WS2812()
servo = Servo()
motor = Motor()
PIN = 22;
irm = IR(PIN)


DEFAULT_I2C_ADDR = 0x27
i2c = I2C(0,sda=Pin(20),scl=Pin(21),freq=400000)
lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)

info = ''
lcd_print = ''
lcd_print2 = ''
speed = 30
# Infrared reception interval time.
IR_delay_time = 0.11

mark = 1
mark_ir = ''


def IR_control():
    global info, lcd_print, mark_ir, mark
    IR_re = irm.scan()
    if IR_re != mark_ir:
        print(IR_re)
        mark_ir = IR_re
    if(IR_re[0]==False):
        #print("_____________")
        mark = 1
    if(IR_re[0]==True and IR_re[1]!=None):
        # remove the first possibly wrong command.
        # 删除第一个可能错误的指令
        if IR_re[0] != None and mark!= -999:
            mark = -999
            
        elif IR_re[1] == "*":
            try:
                while True:
                    avoid_obstacles.test()
#                     RGB_LED.breath(0,0,255)
                    IR_re = irm.scan()
                    if IR_re[1] == "ok":
                        RGB_LED.black()
                        servo.set_angle(7, 0)
                        break
            except KeyboardInterrupt:
                motor.motor_stop()
        elif IR_re[1] == "0":
            try:
                while True:
                    line_tracking.line_track()
                    IR_re = irm.scan()
                    if  IR_re[1] == "ok":
                        RGB_LED.black()
                        break
            except KeyboardInterrupt:
                motor.motor_stop()
                
        elif IR_re[1] == "#":
            try:
                servo.set_angle(7, 0)
                
                while True:
                    keep_distance.keep_distance()
                    IR_re = irm.scan()
                    if  IR_re[1] == "ok":
                        RGB_LED.black()
                        break
            except KeyboardInterrupt:
                motor.motor_stop()      
           
        
        else:
            if IR_re[1] == "up":
                motor.move(1, "forward", speed)
                lcd_print = "Forward"
                RGB_LED.red()
            elif IR_re[1] == "down":
                motor.move(1, "backward", speed)
                lcd_print = "Backward"
                RGB_LED.yellow()
            elif IR_re[1] == "left":
                motor.move(1, "left", speed)
                lcd_print = "Left"
                RGB_LED.blue()
            elif IR_re[1] == "right":
                motor.move(1, "right", speed)
                lcd_print = "Right"
                RGB_LED.green()
            elif IR_re[1] == "1":
                motor.move(1, "left_forward", speed)
                lcd_print = "Left Forward"
            elif IR_re[1] == "3":
                motor.move(1, "right_forward", speed)
                lcd_print = "Right Forward"
            elif IR_re[1] == "7":
                motor.move(1, "left_backward", speed)
                lcd_print = "Left Backward"
            elif IR_re[1] == "9":
                motor.move(1, "right_backward", speed)
                lcd_print = "Right Backward"
            elif IR_re[1] == "4":
                motor.move(1, "turn_left", speed)
                lcd_print = "Turn Left"
            elif IR_re[1] == "6":
                motor.move(1, "turn_right", speed)
                lcd_print = "Turn Right"
            
            else:
                pass
            
            if info != lcd_print:
                lcd.clear()
                lcd.putstr(lcd_print)
                info = lcd_print
    else:
        motor.motor_stop()
        RGB_LED.black()

        
if __name__ =="__main__":
    try:
        while True:
            IR_control()
            time.sleep(IR_delay_time)
            
    except KeyboardInterrupt:
        motor.motor_stop()
  • Now, click the run button.

Step 15

Next, remove the USB cable and put the batteries into the battery holder. And then, power on this smart car.

Now, you can control this smart car using IR remote control.

  • Up key — Forward
  • Down key — Backward
  • Left key — Left
  • Right key — Right
  • 1 — Left forward
  • 3 — Right forward
  • 7 — Left backward
  • 9 — Right backward
  • 4 — Turn left
  • 6 — Turn right
  • * — Avoid obstacles
  • 0 — Line tracking
  • # — Keep distance
  • OK — Stop

Step 16

Next, let’s control it using WIFI. For that, connect this car to the computer and run the following script as main.py on the Raspberry Pi Pico board. And then, click the run button.

from machine import UART, Pin, I2C
from pico_car import Motor, I2cLcd, Servo
import time
import line_tracking
import avoid_obstacles
#import keep_distance

SSID=''
password =''
Port = '8080'

uart = UART(0, 115200)
servo = Servo()
motor = Motor()
#motor.init_setup()

DEFAULT_I2C_ADDR = 0x27
i2c = I2C(0,sda=Pin(20),scl=Pin(21),freq=400000)
lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16)

info = ''
lcd_print = ''
lcd_print2 = ''
speed = 40
mark = 1
servo_angle = 0
servo_mark = -1

# Send commands to the ESP8266.
def sendCMD(cmd,ack,timeout=2000):
    uart.write(cmd+'\r\n')
    t = time.ticks_ms()
    while (time.ticks_ms() - t) < timeout:
        s=uart.read()
        if(s != None):
            s=s.decode()
            #print(s)
            if(s.find(ack) >= 0):
                return True
    return False


def sendData(ID,data):
    sendCMD('AT+CIPSEND='+str(ID)+','+str(len(data)),'>')
    uart.write(data)

# Receive and process the data sent by APP.
def ReceiveData():
    s=uart.read()
    if(s != None):
        s=s.decode()
        #print(s)
        if(s.find('+IPD') >= 0):
            n1=s.find('+IPD,')
            n2=s.find(',',n1+5)
            ID=int(s[n1+5:n2])
            n3=s.find(':')
            s=s[n3+1:]
            s = s.strip('\n')
            #print("ID="+str(ID) + ", Data="+s)
            print(s)
            return ID,s
    return None,None

#ESP8266 with WiFi on, IP address: 192.168.4.1, port: 8080
def setup():
    uart.write('+++')
    time.sleep(1)
    if(uart.any()>0):uart.read()
    sendCMD("AT","OK")
    sendCMD("AT+CWMODE=3","OK")
    #sendCMD("AT+CWJAP=\""+SSID+"\",\""+password+"\"","OK",20000)
    sendCMD("AT+CIPMUX=1","OK")
    sendCMD("AT+CIPSERVER=1,"+Port,"OK")
    sendCMD("AT+CIFSR","OK")
    
    # Avoid the problem of only one motor turning.
    #motor.move(1, "backward", 0)
    #motor.move(1, "forward", 0)
    
# APP Control commands.
def WiFi_control():
    global info, lcd_print, servo_mark, mark
    ID,s=ReceiveData()
    if(ID != None):
        sendData(ID,s)
        print('_____')
        print(s)
        print('_____')
        
        # Obstacle avoidance function. A:Start, B:Stop
        if s == "aStart":
            try:
                avoid_obstacles_mark = 0
                while True:
                    avoid_obstacles.test()
                    ID,s=ReceiveData()
                    if(ID != None):
                        
                        if s == "aStop" and avoid_obstacles_mark !=1: 
                            avoid_obstacles_mark = 1
                        elif s == "bStart" and avoid_obstacles_mark ==1:
                            servo.set_angle(7, 0)
                            lcd_print = "functionA stop"
                            avoid_obstacles_mark = -1
                            break
            except KeyboardInterrupt:
                motor.motor_stop()
        
        # line tracking function. C:Start, D:Stop
        elif s == "cStart":
            try:
                line_tracking_mark = 0
                while True:
                    line_tracking.line_track()
                    ID,s=ReceiveData()
                    if(ID != None):
                        if s == "cStop" and line_tracking_mark !=1: 
                            line_tracking_mark = 1
                        elif s == "dStart" and line_tracking_mark ==1:
                            lcd_print = "functionC stop"
                            motor.motor_stop()
                            break
            except KeyboardInterrupt:
                motor.motor_stop()
            
        # Arrow keys to control the direction of movement of the car.
        else:
            if s == "forwardStart" or s == "lookLeftStart":
                motor.move(1, "forward", speed)
                
                lcd_print = "Forward"
            elif s == "backwardStart" or s == "lookRightStart":
                motor.move(1, "backward", speed)
                lcd_print = "Backward"
                
            elif s == "leftStart":
                motor.move(1, "left", speed)
                lcd_print = "Left"
            elif s == "rightStart":
                motor.move(1, "right", speed)
                lcd_print = "Right"
                
            elif s == "downStart":
                motor.move(1, "left_forward", speed)
                lcd_print = "Left Forward"
            elif s == "upStart":
                motor.move(1, "right_forward", speed)
                lcd_print = "Right Forward"
            else:
                motor.motor_stop()
                
        if lcd_print== "functionA stop":
            print("funcA stop")
        if info != lcd_print:
            lcd.clear()
            lcd.putstr(lcd_print)
            info = lcd_print
            

if __name__ == '__main__':
    setup()
    connect_mark = 0
    while True:
        WiFi_control()
        if connect_mark == 0:
            print("Waiting for connection...")
            connect_mark = 1


  • Next, download and install the app below.
  • WIFI control app — Download
  • Then, open this application and enter the IP address and port.
  • IP — 192.168.4.1
  • Port — 8080
  • Finally, click the connect button.

Troubleshoot

  • Check the Raspberry Pi Pico expansion board connections.
  • Check the Python scripts and libraries.

OK, enjoy this project. The full video guide is below. We hope to see you in the next project or tutorial.

4WD Omni-directional Mecanum Wheels Robotic Car Kit with Raspberry Pi Pico

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *