Drive it from your phone — Mini
Everything so far has been the Mini talking to itself. This one lets you talk to it, over Bluetooth: the Mini gives itself a new name, lights up when something connects, and lets the Game Pad in the MoBot app spin its wheels.
This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Mini.
The program
Section titled “The program”Read the program as text
- MoBot Mini Start
- Print to serial
"Bluetooth test — look for \"MoBot Mini Test\" on your phone." - Change MoBot Mini’s name:
"MoBot Mini Test" - repeat forever
- if Is Bluetooth connected to the app ?
- Set LED 1 ON
- else
- Set LED 1 OFF
- if Is button A pressed ?
- Set LED 2 ON
- else
- Set LED 2 OFF
- Print to serial (create text with
"x: "Read from joystick the value of X" y: "Read from joystick the value of Y) - set Motor 1 to Direction 1 with speed Read from joystick the value of Y %
- set Motor 2 to Direction 1 with speed Read from joystick the value of Y %
- wait 0.2 seconds
- if Is Bluetooth connected to the app ?
What you need
Section titled “What you need”- A MoBot Mini, charged and switched on.
- A USB cable.
- A phone or tablet with the MoBot app.
Read this first — the Mini must be in Programmable
Section titled “Read this first — the Mini must be in Programmable”Your program only runs while the Mini’s mode is Programmable. The Game Pad does not change the mode: opening it never switches the Mini to anything else. Only a mode tile in the app does that. So the order is:
- Set the Mini to Programmable. Pick the tile called Programmable, not the one called Programmable Sequence.
- Then open the Game Pad. Your program receives the stick and the buttons.
Do not tap the Manual driving tile. It sets the Mini to Manual driving, and your program stops. To get it back, tap the Programmable tile: your program starts again from its first line.
An old version of the MoBot app switched the Mini to Manual driving as soon as you opened the Game Pad, and that stopped your program. If your app has no Programmable tile, update the app first.
⚠️ First time? Read the “Before you send it” section of Blink and fade.
How to run it
Section titled “How to run it”- Stand the Mini on a book so the wheels spin in the air.
- Open 08-ble-joystick.mobot in MoBot and press Send to Device. If the Mini is in another mode, MoBot asks: “The robot is in Manual driving. Switch it to Programmable to run your program?” Answer Switch to Programmable.
- Open the serial monitor. It will start printing
x: 0 y: 0five times a second. - Open the MoBot app and scan for Bluetooth devices.
- Connect. On the home screen, under Activities, the app says Robot mode and the mode’s name. If it does not say Robot mode: Programmable, tap the Programmable tile. The app sets the Mini to Programmable and opens the Programmable screen. Press the back arrow to return to the home screen.
- Tap Open Game Pad.
What you should see
Section titled “What you should see”In the card in the middle of the Game Pad, the app says Your program reads this pad while your program is running. (A Mini with the oldest firmware, 2.0.0, shows no line there.) If it says No program on the robot yet, send the program again.
Test 1 — the new name. Your phone’s scan list should show
MoBot Mini Test instead of MobotMini. If it still says MobotMini,
disconnect everything and restart the Mini — the new name is saved forever, and
appears the next time the Mini shouts its name.
Test 2 — the connection light. Connect to the Mini from the phone. LED 1 comes on and stays on. Tap the Switch Robot button at the top of the home screen, and it goes out. This is the clearest test on the page — a light that follows your phone around the room.
Test 3 — the joystick numbers. On the Game Pad, hold the up arrow of the
D-pad. The serial monitor changes to x: 0 y: 127 and both wheels start
turning. Let go and it reads x: 0 y: 0 again and the wheels stop. Hold the
right arrow and it reads x: 127 y: 0 and the wheels stay still.
The Game Pad has two settings, Digital and Joystick, at the top. Switch
it to Joystick and push the stick slowly forward: y climbs from 0 and the
wheels speed up with it.
Test 4 — the A button. The Mini’s Game Pad has no button with the letter A. Its A button is the Siren button (the one with the siren icon). Tap it: LED 2 comes on and stays on. Tap it again and LED 2 goes out.
The blocks
Section titled “The blocks”| block | what it does |
|---|---|
mobot_blename |
Gives the Mini a new name. It keeps it forever, even switched off. |
mobot_bleconnected |
True when a phone is connected. |
mobot_blebuttonpressed |
True while one of the eight buttons is held down. |
mobot_blejoystick |
The joystick position, x or y, from -128 to 127. |
Something to notice — the joystick numbers are the wrong size
Section titled “Something to notice — the joystick numbers are the wrong size”Speed is 0 to 100. The joystick is -128 to 127. They do not match:
- push the stick only half way and
yis about 60 — the wheels go at 60 %. ✅ - push it all the way and
yis 127 — but the motor only goes to 100. The last third of the stick does nothing. 🤔 - pull the stick back and
ygoes negative — and the motor treats anything below 0 as stop, so the Mini will not reverse. ❌
There is a block made for exactly this — the map block, which stretches one range of numbers onto another. 09-ble-map-check is a one-line example that tries it.
The Python code
Section titled “The Python code”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.
# Drive it from your phone — mini (firmware 3.0)## This is what MoBot puts on a robot running firmware 3.0 as main.py when you open# 08-ble-joystick.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 08-ble-joystick.main.py.
from machine import Pinimport time
print("[MOBOT]", 'Bluetooth test — look for "MoBot Mini Test" on your phone.')robot.set_name('MoBot Mini Test')while True: if robot.bluetooth.is_connected(): robot.led1.set(1) else: robot.led1.set(0) if robot.gamepad.is_pressed("a"): robot.led2.set(1) else: robot.led2.set(0) print("[MOBOT]", (''.join([str(x) for x in ['x: ', robot.gamepad.x, ' y: ', robot.gamepad.y]]))) robot.left_motor.forward(robot.gamepad.y) robot.right_motor.forward(robot.gamepad.y) time.sleep(0.2)# Drive it from your phone — mini## This is what MoBot puts on the board as main.py when you open# 08-ble-joystick.mobot and press Send to Device. It is GENERATED from the blocks;# editing this file changes nothing. Edit the blocks instead.
from machine import Pinimport time
print("[MOBOT]", 'Bluetooth test — look for "MoBot Mini Test" on your phone.')mobotMINI.ble.changeName('MoBot Mini Test')while True: if mobotMINI.ble.is_connected: mobotMINI.led1.setState(1) else: mobotMINI.led1.setState(0) if mobotMINI.ble.isPressed['a']: mobotMINI.led2.setState(1) else: mobotMINI.led2.setState(0) print("[MOBOT]", (''.join([str(x) for x in ['x: ', mobotMINI.ble.x, ' y: ', mobotMINI.ble.y]]))) mobotMINI.left_motor.set_direction_and_speed(0, mobotMINI.ble.y) mobotMINI.right_motor.set_direction_and_speed(0, mobotMINI.ble.y) time.sleep(0.2)Try changing it
Section titled “Try changing it”- Use
xinstead ofyfor the left wheel andyfor the right — now you can steer. - Light LED 2 on the up button instead of A.
- Rename your Mini to your own name. Every Mini in the class can have a different one.