Python

Helpful tips for coding the Sumo Board

Remember to include a 3 second delay at the start

The game needs a three second start at the beginning of the game. However if you use a 3 second delay, you might find that your code takes longer to start than the 3 seconds from power on. This is because the Python core needs time to start up.

The best advice is to test your board to see what delay is needed to get close to the 3 second delay needed in the game:

import time

time.sleep(2.5) #try 2.5 seconds at the start of your program - time it!

Motors move in the wrong direction?

If your motors are moving in the wrong direction, we can change the direction in code, look at the following BBRSumoClass.py:


 self.leftMotor = MotorClass.Motor(board.M1B, board.M1A)
 self.rightMotor = MotorClass.Motor(board.M2A, board.M2B)

Move the pin setup around, so if the left motor is spinning in the wrong direction, try making the code (Swap the A and B):


 self.leftMotor = MotorClass.Motor(board.M1A, board.M1B)
       

Include a small sleep in each loop

This gives the micropython core a chance to do any other important background work.

Declare your pins first

Make sure that you setup all of the pins at the top of your file. Then you can use them as needed in your code / logic.

A simple example

The follow is a simple example of a basic robot's movement:

Last updated