This appendix lists common error messages you may see while working through the AIDriver challenges, what they mean in plain English, and how to fix them.
Use it as a quick reference when something goes wrong.
Example message:
NameError: name 'driver' is not defined
What it means (plain English):
Python can’t find a variable or name called driver.
Likely causes:
- You created your robot with a different name (e.g.
my_robot = AIDriver()) but later useddriver. - You mis-typed the name (e.g.
my_robtvsmy_robot).
How to fix:
-
Find where you created the robot (usually near the top of
main.py). -
Use exactly the same name everywhere you refer to it.
-
A simple pattern is:
my_robot = AIDriver() my_robot.drive_forward(200, 200)
Example message:
AttributeError: 'AIDriver' object has no attribute 'backward'
What it means:
The AIDriver class does not have a function called backward.
Likely causes:
-
You used a name from a flowchart or from another language instead of the actual library function.
-
You wrote:
my_robot.backward(200, 200)
instead of:
my_robot.drive_backward(200, 200)
How to fix:
- Use the correct function names from the AIDriver library:
drive_forward(right_speed, left_speed)drive_backward(right_speed, left_speed)rotate_left(turn_speed)rotate_right(turn_speed)brake()read_distance()
Example message:
File "main.py", line 12
while driver.read_distance() == -1
^
SyntaxError: invalid syntax
What it means:
Python expected a : or some other symbol at the end of the line.
Likely causes:
- You forgot the colon (
:) at the end of awhile,if,for, ordefline.
How to fix:
-
Check the line the error points to (e.g.
line 12) and make sure it ends with a colon:while driver.read_distance() == -1: print("Robot too close")
Example messages:
IndentationError: unexpected indent
or
IndentationError: expected an indented block
What it means:
Python is confused by how far your lines are indented.
Likely causes:
- Code inside a
while,if,for, ordefis not indented at all. - Some lines inside the same block are indented differently.
How to fix:
-
For a
whileloop, the body should be indented, for example:while True: my_robot.drive_forward(200, 200) sleep(0.1)
-
Make sure all lines inside the block start with the same number of spaces.
Example message:
ImportError: no module named 'aidriver'
What it means:
Python cannot find the aidriver library. The library is built into the AIDriver firmware, so this means the robot doesn't have the AIDriver firmware installed.
How to fix:
Press Connect robot. If it says the firmware is missing or needs updating, give your robot to your teacher to install the AIDriver firmware.
What it looks like:
- Program runs, no error is shown, but the robot does not move.
Likely causes:
- You never call a movement function inside your loop.
- Your loop is empty or only has
sleep()statements. - Speeds set too low (e.g. below ~120).
How to fix:
-
Make sure your
while True:loop contains commands like:while True: my_robot.drive_forward(200, 200) sleep(0.1)
-
Use speed values around
200for reliable motion.
The robot prints each of these once per run (the simulator shows the same ones):
| Warning | What it means |
|---|---|
Speed 300 is above 255 ... |
Speeds go from 0 to 255. Above 255 the robot treats the number as a raw PWM value, so 300 is almost stopped. |
Speed 50 is in the stopped range (0-80) ... |
The motors need more power than this to turn. Try 150-220. |
hold_state(1000) waits 1000 seconds ... |
hold_state uses seconds. For one second write hold_state(1), for half a second hold_state(0.5). |
hold_state(-1) - time can't be negative ... |
Check the calculation that gives the time. The robot does not wait at all. |
Program ended: motors stopped automatically |
Your program finished, crashed or was stopped while the motors were running, so the robot braked by itself. Read the lines above it for any error. |
What it looks like:
- The board disconnects, restarts, or stops responding while the program is running.
Likely causes:
- An infinite loop with no
sleep()call (CPU never gets a break). - Very tight loops that spam the console with prints.
- Old AIDriver firmware (before version 2026.12.01): every drive, brake and
hold_statecall was written toevent_log.txt, so a fastwhile Trueloop filled the robot's storage within minutes. This can happen even when the same code runs perfectly in the simulator. The simulator shows Firmware update needed when you connect a robot like this.
How to fix:
-
If the robot has old firmware, copy your code somewhere safe, then connect GP4 to GND while powering on. This deletes the files on the robot and restores
main.py. Then give the robot to your teacher to update the firmware. -
Always include a small delay in your main loop, for example:
while True: # your logic here sleep(0.05) # 50 ms pause
-
Reduce the number of
print()calls inside fast loops.
What it looks like:
my_robot.read_distance()returns-1every time.
Likely causes:
- Sensor is too close (< 20 mm) or too far (> 2000 mm) from any object.
- Sensor is pointing into open space. The robot prints
No echo – nothing in range?. - Wiring issue on TRIG/ECHO pins. The robot prints
Echo pin stuck HIGH – check wiring(only after several readings in a row, so a single long echo is not mistaken for a wiring fault).
How to fix:
-
Place an object 10–50 cm in front of the sensor.
-
Check the wiring matches the assembly instructions.
-
Turn on AIDriver debug and watch the messages:
import aidriver from aidriver import AIDriver aidriver.DEBUG_AIDRIVER = True robot = AIDriver()
-
Run a simple distance test loop and see what the debug messages say.
The Robot buttons above the code editor (Connect robot, Upload, Upload & Run, Logs, Stop robot) need Chrome or Edge on a computer.
| Message | What to do |
|---|---|
| "Upload needs Chrome or Edge" (in the code editor's header) | Open the simulator in Chrome or Edge. Firefox, Safari and phones can't connect to the robot. |
| "The robot is being used by another program or tab." | Close MicroPython Lab, Thonny or any other simulator tab that is connected, then press Connect robot again. |
| "Connected, but the robot didn't answer like MicroPython." | Give your robot to your teacher to install the AIDriver firmware. |
| "This robot doesn't have the AIDriver firmware" or "This robot's AIDriver firmware is out of date" (the status shows Firmware update needed) | Give your robot to your teacher to install or update the firmware. You can still upload, but your code may not work properly until the firmware is updated. |
| "The robot's program won't stop." | Your program is ignoring Stop (for example a try/except around while True). Copy your code somewhere safe. Unplug the robot, connect GP4 to GND and plug it back in: this deletes all files on the robot and restores the default main.py. Remove the wire, then upload again. |
| "Fix the error on line … before uploading." | The simulator found a syntax error. Fix the marked line: the robot would stop at this error. |
| "The simulator found: …" | These are simulator rules (for example only aidriver and time imports). Your code may still work on the robot, so you can choose Upload anyway. |
| "The upload didn't save correctly, so your old main.py was kept." | Press Upload again. The robot still has its previous program. |
| "The robot's storage is full." | Give the robot to your teacher to run GP4 recovery mode (this deletes everything except main.py and the logs). |
| "The robot was disconnected." | Plug the USB cable back in. The simulator reconnects by itself for 10 seconds; after that, press Connect robot. |
If you see an error that is not listed here, try to:
- Read the first line of the error message.
- Note the type (e.g.
NameError,SyntaxError,AttributeError). - Use that as a keyword to search in your docs or ask for help.