Skip to content

Search the documentation

Kit
Firmware

Which way do the wheels go? — Mini

The Mini has two wheels and each one has its own motor. This program checks all four things a motor can do: forward, backward, left wheel on its own, right wheel on its own.

This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Mini.

The blocks of this example, from top to bottom.
Click the picture to view it larger.Open full sizeThe same program written as Python is further down this page, in The Python code.
Read the program as text
  • MoBot Mini Start
  • Print to serial "Wheel test — put the Mini on a book first!"
  • repeat forever
    • Print to serial "1. direction set, but speed is 0 — nothing should move"
    • set Motor 1 to Direction 1
    • set Motor 2 to Direction 1
    • set Motor 1 speed 0 %
    • set Motor 2 speed 0 %
    • wait 2 seconds
    • Print to serial "2. both wheels forward"
    • set Motor 1 speed 60 %
    • set Motor 2 speed 60 %
    • wait 2 seconds
    • Print to serial "3. both wheels backward"
    • set Motor 1 to Direction 2
    • set Motor 2 to Direction 2
    • wait 2 seconds
    • Print to serial "4. only the LEFT wheel, forward"
    • set Motor 1 to Direction 1
    • set Motor 1 speed 60 %
    • set Motor 2 speed 0 %
    • wait 2 seconds
    • Print to serial "5. only the RIGHT wheel, forward"
    • set Motor 2 to Direction 1
    • set Motor 1 speed 0 %
    • set Motor 2 speed 60 %
    • wait 2 seconds
    • Print to serial "6. stop"
    • set Motor 1 speed 0 %
    • set Motor 2 speed 0 %
    • wait 2 seconds
  • A MoBot Mini, charged and switched on.
  • A USB cable.
  • A book, a box or a cup to stand the Mini on, so both wheels spin in the air and the robot cannot drive off the table.

⚠️ First time? Read the “Before you send it” section of Blink and fade.

  1. Put the Mini on the book, wheels in the air.
  2. Open 03-motor-directions.mobot in MoBot.
  3. Plug the Mini in and choose its port.
  4. Press Send to Device.
  5. Watch the wheels and read the serial monitor at the same time.

The serial monitor tells you what is supposed to happen next. Check each one:

serial line the wheels
1. direction set, but speed is 0 nothing moves. This step is a trick — a direction on its own does nothing.
2. both wheels forward both wheels spin the same way (the way that would push the Mini forward)
3. both wheels backward both wheels spin the other way
4. only the LEFT wheel, forward the left wheel spins, the right one is still
5. only the RIGHT wheel, forward the right wheel spins, the left one is still
6. stop both wheels stop and coast

Then it starts again.

Two things to write down if they are wrong:

  • If step 4 spins the wheel on your right, the left and right motors are swapped on your board.
  • If “forward” spins the wheels the way the Mini would go backwards, the motor wires are the other way round. The app has an invert motor setting for exactly this.
block what it does
mobot_motordirection Chooses which way a wheel turns. On its own it does nothing!
mobot_motorspeed Chooses how fast, 0–100 %. This is what actually starts the wheel.
mobot_print Tells you which step you are watching.
wait Holds each step long enough to see it.

The big idea: direction says which way, speed says how fast. A wheel with a direction and no speed just sits there. Step 1 is in this program on purpose so you can see that for yourself.

The same blocks write different Python for each firmware, and MoBot picks the one that fits the robot you use. The 2.x tab is for reference. This is a reading copy: editing it changes nothing, so change the blocks instead. The name map lists the names that changed.

03-motor-directions.firmware-3.main.py
# Which way do the wheels go? — mini (firmware 3.0)
#
# This is what MoBot puts on a robot running firmware 3.0 as main.py when you open
# 03-motor-directions.mobot and press Send to Device. It is GENERATED from the blocks;
# editing this file changes nothing. Edit the blocks instead.
# The firmware 2.x version is 03-motor-directions.main.py.
from machine import Pin
import time
print("[MOBOT]", 'Wheel test — put the Mini on a book first!')
while True:
print("[MOBOT]", '1. direction set, but speed is 0 — nothing should move')
robot.left_motor.forward(abs(robot.left_motor.speed))
robot.right_motor.forward(abs(robot.right_motor.speed))
robot.left_motor.set_speed(0)
robot.right_motor.set_speed(0)
time.sleep(2)
print("[MOBOT]", '2. both wheels forward')
robot.left_motor.set_speed(60)
robot.right_motor.set_speed(60)
time.sleep(2)
print("[MOBOT]", '3. both wheels backward')
robot.left_motor.backward(abs(robot.left_motor.speed))
robot.right_motor.backward(abs(robot.right_motor.speed))
time.sleep(2)
print("[MOBOT]", '4. only the LEFT wheel, forward')
robot.left_motor.forward(abs(robot.left_motor.speed))
robot.left_motor.set_speed(60)
robot.right_motor.set_speed(0)
time.sleep(2)
print("[MOBOT]", '5. only the RIGHT wheel, forward')
robot.right_motor.forward(abs(robot.right_motor.speed))
robot.left_motor.set_speed(0)
robot.right_motor.set_speed(60)
time.sleep(2)
print("[MOBOT]", '6. stop')
robot.left_motor.set_speed(0)
robot.right_motor.set_speed(0)
time.sleep(2)
  • Change the 60 to 100 — much faster. Change it to 20 — the wheel may buzz and not turn at all, because there is not enough push. That is normal.
  • Set the left wheel forward and the right wheel backward at the same time: the Mini spins on the spot. Try it on the floor, not on the book.