Posted on Leave a comment

Getting Started with BoBBoT

Now you have assembled BoBBoT it’s time to program a micro:bit to control it!

We recommend using MicroPython and the Mu Editor to program your micro:bit.

1. Visit the Mu editor website and download the latest version. If you are using Windows you simply need to double click on the exe to run Mu, no installation necessary. Mu Website Screenshot2. Now you are going to start writing your first program. Enter this line of code into the Mu editor, this imports microbit module which allows us to access pre-written code designed specifically for the micro:bit.

from microbit import *

3. Next add this code to give the micro:bit pins that are used to control BoBBoT easy to remember names.

rightFwd=pin16
leftFwd=pin12
rightBck=pin8
leftBck=pin0
lineSensor=pin1

4. Add these two lines to set both motors to move forward.

rightFwd.write_digital(1)
leftFwd.write_digital(1)

5. These lines of code will make BoBBoT continue to move forward for 2 seconds before the motors are turned off.

sleep(2000)
rightFwd.write_digital(0)
leftFwd.write_digital(0)

6. Add these lines of code to the bottom of your program to make BoBBoT move backward for 2 seconds before stopping.

rightBck.write_digital(1)
leftBck.write_digital(1)
sleep(2000)
rightBck.write_digital(0)
leftBck.write_digital(0)

Here is the complete code listing:

from microbit import *
rightFwd=pin16
leftFwd=pin12
rightBck=pin8
leftBck=pin0
lineSensor=pin1
rightFwd.write_digital(1)
leftFwd.write_digital(1)
sleep(2000)
rightFwd.write_digital(0)
leftFwd.write_digital(0)
rightBck.write_digital(1)
leftBck.write_digital(1)
sleep(2000)
rightBck.write_digital(0)
leftBck.write_digital(0)

7. Connect your micro:bit to your computer using a micro USB cable and click on the Flash button to transfer the program to your micro:bit. Flashing is complete when the orange LED at the back of the micro:bit stops flashing.

Mu Flash Screenshot

8. Disconnect the USB cable from the micro:bit and insert it into BoBBoT (it doesn’t matter which way).

9. Place BoBBoT on the floor and switch it on using the switch on the battery pack. It should move forwards and then backwards before stopping.