Skip to content

Search the documentation

Kit
Firmware

Slow, faster, fastest — Mini

A ladder of speeds. The wheels start slow, climb to full speed, come back down, then do it backwards. It uses one block that does two jobs at once: the direction and the speed in a single click.

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 "Speed ladder — put the Mini on a book first!"
  • repeat forever
    • Print to serial "--- going FORWARD ---"
    • Print to serial (create text with "speed " 20 " %")
    • set Motor 1 to Direction 1 with speed 20 %
    • set Motor 2 to Direction 1 with speed 20 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 40 " %")
    • set Motor 1 to Direction 1 with speed 40 %
    • set Motor 2 to Direction 1 with speed 40 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 60 " %")
    • set Motor 1 to Direction 1 with speed 60 %
    • set Motor 2 to Direction 1 with speed 60 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 80 " %")
    • set Motor 1 to Direction 1 with speed 80 %
    • set Motor 2 to Direction 1 with speed 80 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 100 " %")
    • set Motor 1 to Direction 1 with speed 100 %
    • set Motor 2 to Direction 1 with speed 100 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 60 " %")
    • set Motor 1 to Direction 1 with speed 60 %
    • set Motor 2 to Direction 1 with speed 60 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 20 " %")
    • set Motor 1 to Direction 1 with speed 20 %
    • set Motor 2 to Direction 1 with speed 20 %
    • wait 1.2 seconds
    • Print to serial "--- going BACKWARD ---"
    • Print to serial (create text with "speed " 40 " %")
    • set Motor 1 to Direction 2 with speed 40 %
    • set Motor 2 to Direction 2 with speed 40 %
    • wait 1.2 seconds
    • Print to serial (create text with "speed " 80 " %")
    • set Motor 1 to Direction 2 with speed 80 %
    • set Motor 2 to Direction 2 with speed 80 %
    • wait 1.2 seconds
    • Print to serial "--- stop ---"
    • set Motor 1 to Direction 1 with speed 0 %
    • set Motor 2 to Direction 1 with speed 0 %
    • wait 2 seconds
  • A MoBot Mini, charged and switched on.
  • A USB cable.
  • A book or a box to stand the Mini on so the wheels spin in the air.

⚠️ 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 04-speed-ramp.mobot in MoBot.
  3. Plug the Mini in and choose its port.
  4. Press Send to Device.
  5. Listen as much as you watch — the motor’s sound changes with the speed.
  • The serial monitor counts the speeds out loud: [MOBOT] speed 20 %, speed 40 %, speed 60 %, speed 80 %, speed 100 %, and back down.
  • The wheels get visibly faster at every step and the motor whine gets higher.
  • Then --- going BACKWARD --- and the wheels do it the other way.
  • Then --- stop --- and everything is still for two seconds.

What to check: every step must look and sound different from the one before. If 20 % and 40 % look the same, or if 20 % just buzzes without turning, write down the lowest speed that actually moves your wheels — that number is useful to the people who write the robot’s insides.

block what it does
mobot_motordirspeed Direction and speed together. The block you will use most.
text_join + mobot_print Glues the word “speed” to a number to make a readable line.
repeat_forever, wait Keeps the ladder going, and holds each rung long enough to see.

Compare this with 03-motor-directions, which uses two separate blocks to do the same job. This one is shorter; that one shows you why it works.

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.

04-speed-ramp.firmware-3.main.py
# Slow, faster, fastest — mini (firmware 3.0)
#
# This is what MoBot puts on a robot running firmware 3.0 as main.py when you open
# 04-speed-ramp.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 04-speed-ramp.main.py.
from machine import Pin
import time
print("[MOBOT]", 'Speed ladder — put the Mini on a book first!')
while True:
print("[MOBOT]", '--- going FORWARD ---')
print("[MOBOT]", (''.join([str(x) for x in ['speed ', 20, ' %']])))
robot.left_motor.forward(20)
robot.right_motor.forward(20)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x2) for x2 in ['speed ', 40, ' %']])))
robot.left_motor.forward(40)
robot.right_motor.forward(40)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x3) for x3 in ['speed ', 60, ' %']])))
robot.left_motor.forward(60)
robot.right_motor.forward(60)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x4) for x4 in ['speed ', 80, ' %']])))
robot.left_motor.forward(80)
robot.right_motor.forward(80)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x5) for x5 in ['speed ', 100, ' %']])))
robot.left_motor.forward(100)
robot.right_motor.forward(100)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x6) for x6 in ['speed ', 60, ' %']])))
robot.left_motor.forward(60)
robot.right_motor.forward(60)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x7) for x7 in ['speed ', 20, ' %']])))
robot.left_motor.forward(20)
robot.right_motor.forward(20)
time.sleep(1.2)
print("[MOBOT]", '--- going BACKWARD ---')
print("[MOBOT]", (''.join([str(x8) for x8 in ['speed ', 40, ' %']])))
robot.left_motor.backward(40)
robot.right_motor.backward(40)
time.sleep(1.2)
print("[MOBOT]", (''.join([str(x9) for x9 in ['speed ', 80, ' %']])))
robot.left_motor.backward(80)
robot.right_motor.backward(80)
time.sleep(1.2)
print("[MOBOT]", '--- stop ---')
robot.left_motor.forward(0)
robot.right_motor.forward(0)
time.sleep(2)
  • Add a rung at 10 % at the bottom and see whether the wheels move at all.
  • Make one wheel 100 % and the other 40 % — the Mini drives in a big curve. Try that one on the floor.