Drive:Bit Affordable Motor Controller for Microbit

Drive:Bit Motor Controller

Purchase Drive:Bit here

Drive:Bit has been created to provide a really affordable motor and robotics controller board for the BBC micro:bit. Even though we reduced the price as much as we could, we kept some great features which will make it an excellent board to build DIY buggies and the like


NB: Fit the Microbit into the connector with the LEDs on the Microbit facing the switch and indicator LED.

Connect your batteries to the 2-pin screw terminal, or the 2-pin header pins, on the left. The battery voltage should be in the range 6V to 10V, so use 4 x AA alkaline cells, or a 9V PP3 battery or similar. This input voltage is what is used to drive the motors and generate the 3.3V for the Microbit, so make sure that your motors can cope with the voltage you provide and that the voltage is kept high enough when the motors take a lot of current.

Connect your motors to the 2-pin screw terminals (or 2-pin male headers). Motor 1 is on the left, labelled M1. Motor 2 is on the right, labelled M2. The current to the motors is limited by the circuitry so it won’t damage the DriveBit if you try and take too much current. However, if things aren’t working, switch off and check for short circuits. Better safe than sorry!

In the centre of the DriveBit is a group of pins, 4 x 3. These are GVS (Ground, Voltage, Signal) pins that allow you to connect 3.3V devices (inputs or outputs) directly to the Microbit pins 0, 1, 2 and 8. Small, micro, servos such as SG90 can be plugged in directly – although they are 5V devices they will generally work at 3.3V.

Other pins are available on the top of the board as pads. You will have to solder wires in there, or you could add a (male or female) header yourself.

Programming Drive:Bit with Makecode

There is a Makecode extension available which makes it trivial to control the motors or set the status FireLed to any colour with or without flashing. The 4 GVS pins are general purpose so use other Makecode libraries to drive what you connect to these pins.

In Makecode editor go to Advanced and Extensions, then search for DriveBit

Driving Motors:

Setting the Status LED


Using Drive:Bit with MicroPython

For micro Python, you can drive the motors and the onboard status LED very simply. The pins used are:
Motor 1: Pin 12 and Pin 13
Motor 2: Pin 14 and Pin 15
LED: Pin 16

To drive forward, Set Pin 12 and Pin 14 to the speed you want, from 0 to 1023. And set Pin 13 and Pin 15 to 0. Eg. to drive at speed 600

pin12.write_analog (600)
pin13.write_analog (0)
pin14.write_analog (600)
pin15.write_analog (0)

To drive backwards, set Pin 12 and Pin 14 to zero, and set Pin 13 and Pin 15 to the speed you want, from 0 to 1023. eg to reverse at speed 600

pin12.write_analog (0)
pin13.write_analog (600)
pin14.write_analog (0)
pin15.write_analog (600)

To stop the motors, set both pins of each motor to 0. This will coast to a stop

pin12.write_analog (0)
pin13.write_analog (0)
pin14.write_analog (0)
pin15.write_analog (0)

To brake the motors quickly, set both to 1023

pin12.write_analog (1023)
pin13.write_analog (1023)
pin14.write_analog (1023)
pin15.write_analog (1023)

To drive the LED, you will need to import and use the neopixel library. This example sets the LED to Red

import neopixel
np = neopixel.NeoPixel(pin16, 1)
np[0] = (255, 0, 0)

  • Line 1 imports the neopixel library
  • Line 2 sets up the array of LEDs that the library will use. We only have 1 LED
  • Line 3 sets element 0 (our only LED) to Red=255, Green=0, Blue=0
  • Line 4 copies the array of LED data to the LED itself


M.A.R.S. Rover Assembly

Assembly of 4tronix M.A.R.S. Rover Kit

Click on any photo to enlarge

The 4tronix Mars Rover is loosely based on the Curiosity and Mars 2020 rovers from NASA. It uses the same rocker arm, bogey and differential arm mechanism.

Purchase M.A.R.S. Rover from here

Coding for the M.A.R.S. Rover for Microbit in Makecode here

Coding for the M.A.R.S. Rover for Pi Zero in Python here

Some stats on the 4tronix Mars Rover

  • 6 Motors. 80 rpm 6V, N20 micro gear motors
  • 4 Servos. MG90S metal gear analog micro servos
  • Total number of special PCBs: 30
  • Number of different PCB designs: 11
  • Length: 200mm
  • Width: 185mm
  • Height without Mast and Microbit: 95mm
  • Height with Mast: 170mm

Kit Contents

NOTE: The kits for Raspberry Pi Zero and BBC Microbit are identical, except for the mainboards which are slightly different. The assembly guide is the same, whichever one you have. ALl photos are for the Microbit version.

The kit is packed in 10 bags, which should be assembled in order as follows

  1. Side pack. PCBs and screws to assemble both side pieces of the main body
  2. Brains (Top) Pack. This PCB houses all the electronics and together with the side pieces (1) forms the structural body of the 4tronix Mars Rover
  3. Rocker Pack. These 2 rocker arms are pivoted on the screws fitted into each side piece. Each rocker arm carries a single servo for a front corner wheel assembly
  4. Bogey Pack. These two rear bogeys carry the centre and rear wheels for each side. The rear corner wheels are steered with a servo
  5. Servo Pack. This contains 4 metal gear micro servos together with screws to fix them into the Rockers and Bogeys
  6. Differential Arm Pack: The differential arm and couplers joins the two Rockers in such a way that it tries to keep the main body level (side to side) as one side or the other traverses uneven terrain. In earlier NASA Mars Rovers, this arm was replaced by a differential gear train, but the arm was found to be simpler and less prone to failures.
  7. Corner Wheels Pack. Each corner wheel is steered by its own servo. This pack contains the PCBs and screws needed to connect all four of the motor mounts to the servos
  8. Motors Pack. This includes the 6 motors, each ready-wired with a JST connector lead which plugs into the underneath of the main brains board. Plastic mounting brackets and associated screws are also included
  9. Wheels Pack: Six wheels. Just push them onto the motors. You must enusre that the D-shaped axle is aligned with the D-shaped hole in the wheel
  10. Mast Pack. Includes another servo, the mast base and a plug-in mast head with an ultrasonic sensor and some LEDs.


You should allow 2 hours to build this if you are used to assembling kits of this nature. If it is your first assembly of something like this, then you may have to double the expected timeframe.

Step 0

Check you have all the bags described above. There is also a spares bag, a spare servo, a screwdriver and a wrench. The screwdriver has both a flat blade and a philips blade end. Pull out the metal part and insert it the other way round to change ends.

Step 1: Assemble the Sides

You should have two sides pieces (left and right), four aluminium brackets, eight 8mm M3 screws and two long 16mm M3 screws. Photo above shows 2 brackets fitted and two brackets ready to fit.

Screw the brackets into the side pieces from the inside as shown above. Make sure that the vertical screw holes in each brackets are next to the top surface of each side.

Then screw the long screw from the inside, through the PCB and through the fitted nut. .Make sure all screws are tight as once it is assembled it will be very hard to get at them again

Step 2: Fit the Brains/Top to the Sides

You should have the Brains PCB and eight M3, 6mm screws

The sides should be fitted as shown above with the rocker mounting screw nearest the front (the end with the servo hole in the top/brains PCB)

Step 3: Fit the Rocker Arms

You should have two rocker arms (left and right) with servo mounts fitted, two M3 nyloc nuts and 4 M3 washers

Place a washer onto the rocker pivot screw, then place the rocker arm, then a second washer and finally the M3 nyloc nut. Tighten up the nut as far as it will go, then back it off the tiniest bit until the arm moves freely. If you loosen the nut too much the arm will wobble, so get it as tight as possible without binding.

The servo carrier on each side is at the front of the rover, facing outwards as shown above.

Step 4: Fit the Bogeys

You have two bogeys (left and right) with servo and motor carriers attached, two M3, 10mm screws, 4 washers and two nyloc nuts.

Fit the screw from the inside, through the rocker arm, then a washer, then the bogey, then a second washer and finally the nyloc nut. As with the rocker arms, do the nyloc nut up tightly then back it off slightly so the bogey moves freely.

The bogeys also have the servo carriers facing outwards in each rear corner of the rover.

Step 5: Fit the Steering Servos

You have four servos and eight 6mm, M2.5 screws. You  may also have 8 nuts.

Mount each servo with the output shaft nearest the centre of the rover as shown above. Screw from underneath the servo mounting PCB into the holes on the side of each servo, as shown below. Depending on the exact model of servos you may also require the nuts to hold it tight. Keep hold of the servo arms and servo shaft screws, ready for Step 7.

Step 6: Fit the Differential Arm

You should have the differential arm PCB, a long screw, 2 washers and a nyloc nut and 2 push-rods with 4 screw on snap links.

Screw the long screw from underneath, through the main board and into the fitted nut. Do up tightly.

Place a washer over the long screw and onto the fitted nut, then the differential arm, then the second washer and finally the nyloc nut. As with the rocker arms and bogeys, do up the nyloc nut tightly then slacken it off slightly

Finally adjust the pushrods and snap links by screwing in and out until the distance between the clip points is about 53mm. Then clip firmly into the top of each rocker arm and the ends of the differential arm.

When you have fitted the wheels (later) you can adjust the length of the pushrods to ensure that the body of the Rover sits level.

Step 7: Fit the Corner Wheel Mountings

You should have four top pieces with 4mm nuts attached and eight 6mm black screws.

Also included is the Zero Servo – a little magic PCB that centres your servos without hassle.

You will also need the four cross-shaped servo arms and servo shaft screws from the servo packs. Do not use the longer screws in the servo packs. If the soldered nuts still have the orange kaptan tape on, you will need to peel it off.

Fit the cross-shaped  servo arms to the top pieces with the nuts attached. The arms fit on the opposite side to the nuts and with the hole that accepts the servo shaft facing outwards. Note that the arms are not symmetrical – so the holes will only line  up properly one way round – the longer end goes towards the straight edge of the mounting PCB. You can use a pair of side-cutters (or nail clips?) to chop off the protruding ends of the servo arms.

IMPORTANT: it is important that the motors are mounted so they are pointing outwards at as close to 90 degrees as possible when the servos are set to 0 degrees. Use a ServoZero (included) connected to power by a USB cable and plug each servo in turn into it to set to the zero position. We can fine tune the position later in software, but it is important to get it close mechanically.

Use the little servo shaft screws from the servo packs to fit each motor mounting securely.

Step 8: Fit the Motors

You should have 6 motors with JST leads attached, 6 mounting brackets, 20 M2 screws and 12 M2 nuts. You will also have the 4 lower motor mount PCBs

Mount the centre motors by fitting the nuts into the plastic brackets, then screwing through from underneath into the nuts. See photo above.

The corner motors are mounted by first fitting them to the lower motor PCBs from Pack 7 using 2 screws and 2 nuts for each.

Then screw the resulting assembly onto the 2 fitted 4mm nuts on the PCBs you assembled in step 7.

With all six motors fitted, attach the JST leads to the connectors underneath the main board. It doesn’t matter which connector you use as long as the left side connects to left motors and the right side connects to right motors.

You can use this opportunity to connect all the servo leads as well. These need to be connected to the servo connector nearest to them. So use 9, 11, 13 and 15.

You can wrap the spare lead around the servos to tidy the cables up a little. An alternative method that I use is to put the cables down the side of the battery holders underneath and hold them in with a peice of foam cut from the packing in the box.

Step 9: Fit the Wheels

The six wheels simply push on, but be careful to line up the D-shaped hole in the wheels with the D-shaped axle. Only push the wheel when holding the motor, not when hold the body.

It looks better (I think) if the wheels are on “backwards” with the spokes showing

Step 10: Fit the Mast

The mast houses an ultrasonic distance sensor and 2 White LEDs (not controllable). It is fitted onto a steerable servo and can be removed simply by unplugging it.

This pack contains the servo, the mast base PCB, the mast head PCB, two M2.5 screws to secure the servo and 4 short self-tapping screws to secure the servo horn to the mast base

Fit the servo by screwing the M2.5 screws through the top PCB into the holes on the side of the servo. Connect the servo lead to position SV0 underneath.

Fit the cross-shaped servo horn from the servo bag to the bottom of the mast base PCB using the 4 small self tapping screws.

Fit it so that the connector is pointing forwards when the servo is at its centre position. Use the small shaft mounting screw in the servo bag to fix it firmly to the top of the servo shaft.

Then plug in the mast head and plug the 3-wire lead from the mast base to position P13 on the top of the main board. Ensure the Brown wire is next to G on both boards.


Now for some coding using Microsoft Makecode: Makecode extension is from

In Makecode, click on Advanced, then Extensions. Enter the URL above into the search bar. See this guide.

For Pi Zero and Python, see this guide.


Pi2Go Mk2 Programming

Programming the Pi2Go Mk 2

Preparing your Raspberry Pi

Before you can install the Pi2Go Mk 2 software, you will need to ensure that your Raspberry Pi is up and running and connected to the internet. You will need to be able to see the desktop or console (either using direct connections, or SSH or VNS over the network).

Setting up a Raspberry Pi is not covered here. It is best to get the information from the source at Raspberry Pi

You will also need to enable SPI and I2C. Do this from raspi-config

sudo raspi-config

Select interfaces and enable both SPI and I2C. Then reboot.

Using with ScratchGPIO

Simplesi (Simon Walters) has generously included Pi2Go Mk2 in the list of directly supported devices in ScratchGPIO.

Visit this blog post for installation and coding tips

Installing the Pi2Go Mk2 Python Software

NB. Note that this software is still in Python 2. Python 3 will not work due to Print statements. Hopefully this will be resolved shortly

First you will need to prepare your Pi for the Smart RGB LEDs (fully compatible with neopixels). The best way we’ve found to do this is run Pimoroni’s curl script.
With your Pi connected to the internet, run (you don’t need to install the resources and examples):

curl -sS | bash

Download the Python library module and example software for Pi2Go Mk2 with

wget -O


This installs the following, which should be run in Python 2 for now (unless otherwise stated)

  • ipd.desktop in home/pi/.config/autostart which will start the IP Display on boot. This will silently fail if the optional IP Display is not plugged into either port.
  • Creates a folder home/pi/pi2go2 for all the example files and library module (the main library module)
  • to demonstrate driving the motors. Must be run in a terminal, not from an IDE like Idle or Thonny. Use LXTerminal for this
  • to demonstrate running motors controlled by the wheel sensors. Must be run in a terminal, not from an IDE like Idle or Thonny. Use LXTerminal for this
  • shows the light sensor values and raw battery voltage
  • flashes all LEDs through Red, Green, Blue and White. This must be run using sudo. ie: sudo python3
  • sets the LEDs to rainbow colours (static, but flashes every 10 seconds). This must be run using sudo in Python 3. ie: sudo python3
  • shows the value of the line sensors
  • is very basic line follower program
  • shows the distance in cm for an obstacle using the optional ultrasonic breakout in either or both expansion slots
  • this is the program run on boot up to display the IP address of the Pi to make it easy to connect to using VNC or SSH

Using the Library Module

To use this module, you must first import it into your program using

import pi2go2

Then, before using any other functions you should call the init ( ) function to initialise all the variables used by the library. The init ( ) function has an optional parameter which is the default brightness of the LEDs. If omitted, this defaults to 40. So the following call will initialise the library and set the default brightness to 100:

pi2go2.init (100)

Hot Tip:
As a special case, if you set the brightness to zero, then the LEDs are not initialised. As this would require use of the sudo command, it can be beneficial to call init (0) so that your program can be run without using sudo.

When your program has finished, it is good practice to close down everything tidily by calling:

pi2go2.cleanup ( )

Motor Functions

  • stop ( ): Stops both motors – coast slowly to a halt
  • brake ( ): Stops both motors – brakes quickly
  • forward (speed): Sets both motors to move forward at speed. 0 <= speed <= 100
  • reverse (speed): Sets both motors to reverse at speed. 0 <= speed <= 100
  • spinLeft (speed): Sets motors to turn opposite directions at speed. 0 <= speed <= 100
  • spinRight (speed): Sets motors to turn opposite directions at speed. 0 <= speed <= 100
  • turnForward (leftSpeed, rightSpeed): Moves forwards in an arc by setting different speeds. 0 <= leftSpeed,rightSpeed <= 100
  • turnreverse (leftSpeed, rightSpeed): Moves backwards in an arc by setting different speeds. 0 <= leftSpeed,rightSpeed <= 100


Wheel Sensor Functions

  • stepForward (speed, steps): Moves forwards specified number of steps, then stops
  • stepReverse (speed, steps): Reverses specified number of steps, then stops
  • stepSpinL (speed, steps): Spins left specified number of steps, then stops
  • stepSpinR (speed, steps): Spins right specified number of steps, then stops


RGB LED Functions

  • setColor (color): Sets all LEDs to color – requires show()
  • setPixel (ID, color): Sets pixel ID to color – requires show()
  • show ( ): Updates the LEDs with state of LED array
  • clear ( ): Clears all LEDs to off – requires show()
  • rainbow ( ): Sets the LEDs to rainbow colors – requires show()
  • fromRGB (red, green, blue): Creates a color value from R, G and B values
  • toRGB (color): Converts a color value to separate R, G and B
  • wheel (pos): Generates rainbow colors across 0-255 positions

IR Sensor Functions

  • irLeft ( ): Returns state of Left IR Obstacle sensor
  • irRight ( ): Returns state of Right IR Obstacle sensor
  • irAll ( ): Returns true if either of the Obstacle sensors are triggered
  • irLeftLine ( ): Returns state of Left IR Line sensor
  • irRightLine ( ): Returns state of Right IR Line sensor

UltraSonic Function

  • getDistance (sonar = 0). Returns the distance in cm to the nearest reflecting object. 0 == no object. Sonar 0 is the front connector, Sonar=1 is the side connector. If you don’t include the parameter it defaults to 0 (front)

    Analog and Light Sensor Functions

  • getLight (Sensor). Returns the value 0..1023 for the selected sensor, 0 <= Sensor <= 3
  • getLightFL ( ). Returns the value 0..1023 for Front-Left light sensor
  • getLightFR ( ). Returns the value 0..1023 for Front-Right light sensor
  • getLightBL ( ). Returns the value 0..1023 for Back-Left light sensor
  • getLightBR ( ). Returns the value 0..1023 for Back-Right light sensor
  • getBattery ( ). Returns the voltage of the battery pack (>7.2V is good, less is bad)

    Switch Function

  • getSwitch ( ). Returns the value of the tact switch: True == pressed

Pi2Go Mk 2 Home Page



The Pi2Go Mk2 is the evolution of the very popular original Pi2Go, first shipped in April 2015. The major changes are:

  • Improved assembly method, particularly the motor mounts
  • No wires for attaching the battery packs
  • Better quality wheels with high grip tyres
  • Wheel sensors built into both wheels
  • Programmatic access to the raw battery voltage
  • Improved analog light sensors – one in each corner
  • 10 individually addressable Smart RGB LEDs
  • 2 edge connectors compatible with Pimoroni’s Breakout Garden with full access to I2C signals and individual GPIO signals
  • Improved motor controller allowing higher speeds and optional braking on stop
  • Now with 4WD option



  • Requires 6 x AA rechargeable battery cells (not included)
  • Supports all versions of 40-pin Raspberry Pi
    (NB. the Raspberry Pi 4 consumes a lot of power and it is recommended to use one of the optional 7 x AA, or 2 x 18650 battery boards)
  • Motor controller: DRV8833
  • Analog input (light sensors and battery) MCP3008
  • Switching 5V power supply using TPS5430
  • 10 x SK6812-3535 Smart RGB LEDs (compatible with neopixels) – on battery board
  • On/Off switch with Blue indicator LED – on battery board
  • 2 x TCRT5000 infra-red obstacle sensors (front corners)
  • 4 x SFH3710 light sensors (all 4 corners)
  • 2 x TCRT5000 infra-red line follower sensors
  • 6mm tact switch for programmatic use
  • 4 x servo connections – direct from GPIO pins, with 5V and Gnd signals
  • 2 x optical wheel sensors with 20 slot encoder wheels (ie. 20 pulses per revolution)
  • 2 slots for breakout boards, including ultrasonic distance sensor and IP Display. These slots are compatible with Pimoroni’s Breakout Garden range.
  • Overall size with wheels attached: 148 x 118 x 98mm (length x width x height)
  • Weight (excluding Raspberry Pi & batteries): 282g


GPIO Connections

(Broadcom numbering)

  • Left Motor: 26, 19
  • Right Motor: 21, 16
  • Smart RGB LEDs: 18
  • Left Obstacle Sensor: 22
  • Right Obstacle Sensor: 17
  • Left Line Sensor: 23
  • Right Line Sensor: 27
  • Front ultrasonic (or general I/O): 20
  • Side ultrasonic (or general I/O): 4
  • Tact switch: 15
  • Left wheel sensor: 5
  • Right wheel sensor: 6
  • Servos: 12, 13, 24, 25



MiniBit Entry-Level Robot for Microbit

Purchase here


MiniBit is a ready-assembled simple and inexpensive robot for the BBC micro:bit.

It has the following features:

  • Ready-assembled. Just push on the wheels
  • Edge connector to easily insert the Microbit
  • Micro metal gear motors with fully-enclosed gearbox (no grit or fluff can enter)
  • Wire-free battery holder for 3 x AA batteries
  • 4 x Smart RGB LEDs (neopixel compatible)
  • Integrated Pen holder for 10mm diameter pens (eg. Sharpie felt tips)
  • Robust On/Off switch with Blue indicator LED
  • Wide chunky wheels with lots of grip
  • Metal ball front caster
  • Connector for optional ultrasonic sensor or I2C breakouts (fully compatible with Pimoroni’s Breakout Garden range)
  • The Microbit pins 0, 1, 2, Gnd and 3V are available for use with croc clips etc.
  • Lots of mounting holes to create your own “body” for the robot or additional sensors etc.
  • Makecode extension and micropython examples available


Please use Alkaline batteries. Rechargeable batteries do not provide sufficient voltage once they have started to deplete. This primarily affects the ultrasonic sensor, so you may be okay to use with the other functions even when the batteries get low

Coding Your MiniBit

Microsoft MakeCode

Click any image to enlarge.

To load the extension, select Advanced, then Extensions. Then enter “Minibit” into the search box and press Enter. If that doesn’t find it (there are sometimes earch glitches) you can enter the full URL into the search box: “”

NB. This post is being updated to relate to the new functions added (Feb 2020). Images may not match the text.

Once loaded, you will have a MiniBit menu item with 4 sub-folders: Motors, FireLeds, Sensors, Addons

Motor Blocks

The “New style block” section contains command for basic movements eg. “Go Forwards/Reverse at speed 60” or “Rotate Left/Right at speed 40 for 700 ms”. All the commands in this section use speeds from 0 to 100 inclusive.

Both the “Go” and the “Rotate” blocks have a paired block that will do the command for a selected amount of time and then stop

There are two ways of stopping. Coasting to a stop or braking. If you set the speed to 0 or use the “stop with no brake” command, then it will stop gently over the coourse of a second or so depending on initial speed). If you use the “stop with brake” block (or the go/rotate for a time block) then it will stop almost immediately.

You can also drive each motor individually using the “Move Left/Right/Both motors…” block. For instance if you set the left motor to drive at 600 and the right motor to drive at 1000, then it will perform an arc towards the left

We have introduced a new command to bias the driving in one direction or the other. This is to counteract any mismatch between the motors. So if your robot drifts over the left when you want it to go straight, then add a bias to the Right. At a speed of 60, a bias of 10% is roughly equal to 10 cms or so.

FireLed Blocks

You can use these blocks to set and clear one or all the FireLeds.

Note that the MiniBit defaults to automatically updating the FireLeds whenever any change is made, but you can change this behaviour by setting the update mode to manual. Then you would have to run the “Show LED changes” block after making any changes to the LED settings.

The LEDs on the MiniBit are labelled from 0 to 3. Use these numbers in the Makecode blocks to change the colour. eg setting LED 1 to Purple could be done like this:

The default brightness level is 40. This is plenty bright enough for most uses, saves damaging eyes, and reduces battery consumption. If required you can change the brightness from 0 up to 255

In the Advanced section of FireLeds :

Set update mode is used to switch between automatic LED updates or manual LED updates. The default is for automatic updates: every change to the LEDs results in all the LEDs being written to with the updated values. This is easy to understand, but it does mean that when making a lot of changes it can slow things down considerably. If doing that, it is best to use Manual update mode, make all the changes required, then use the show LED changes block to make all the updates in one go.

Rotate LEDs block will move the colour in LED 0 to LED 1, LED1 to LED2, LED2 to LED3 and LED3 to LED0. If done repeatedly, with a delay between each one, it will show the LED colours rotating around all the 4 LEDs.

Shift LEDs block will move LED0 to LED1, LED1 to LED2 and LED2 to LED3. It will blank LED0. So all the colours will disappear one at a time from 0 to 3

You can also create your own colours and replace the fixed list of colours in any command using the convert from red, green, blue block. For example, to set LED0 to a blue-green colour:


Sensor Blocks

Ultrasonic distance sensor: You can get the values to the nearest object in cm, inches or microseconds. This block returns a number that you can put into a variable or use it directly in a calculation or test

Line sensors: This optional accessory has 3 sensors: left, centre and right. These are connected directly to Pin 0, 1 and 2 of the Microbit. There are two ways of using the sensors: a) read the current value and check it’s state before deciding what to do, or b) use a block that only gets run when the requested event occurs. eg: when the left sensor finds a (black) line

More Blocks

These are the advanced usage blocks. Most students will not need to use them.

  • Set update mode is used to switch between automatic LED updates or manual LED updates. The default is for automatic updates: every change to the LEDs results in all the LEDs being written to with the updated values. This is easy to understand, but it does mean that when making a lot of changes it can slow things down considerably. If doing that, it is best to use Manual update mode, make all the changes required, then use the show LED changes block to make all the updates in one go.
  • Rotate LEDs block will move the colour in LED 0 to LED 1, LED1 to LED2, LED2 to LED3 and LED3 to LED0. If done repeatedly, with a delay between each one, it will show the lED colours rotating around all the 4 LEDs.
  • Shift LEDs block will move LED0 to LED1, LED1 to LED2 and LED2 to LED3. It will blank LED0. So all the colours will disappear one at a time from 0 to 3
  • You can also create your own colours and replace the fixed list of colours in any command using the convert from red, green, blue block. For example, to set LED0 to a blue-green colour:


Programming in microPython

Driving Motors

The motors use 2 pins each to determine the speed and direction. In microPython we use write_analog ( ) to set the first pin to a value between 0 and 1023 and the second pin to 0 in order to go forward. To reverse, we swap the pins so that the first pin is set to 0 and the second pin is set to the value.

On the MiniBit the left motor uses pins 12 and 8, and the right motor uses pins 16 and 14.

So to move the left motor forwards at speed 600:


And to move the right motor in reverse at speed 450:


To stop with no brake, use write_digital ( ) to set both pins to 0. To stop with brake, set both pins to 1.
eg. stop left motor with coasting and right motor with brake:



So a complete, but fairly useless, program to drive the motors for 2 seconds and then stop quickly, would look like this:

from microbit import *
pin12.write_analog(0) # temporary fix for python bug

pin16.write_analog(0) # temporary fix for python bug


Note the 2 lines that write_analog(0) before swapping a pin from analog to digital. These are required until a fix is obtained for the python PWM driver continually updating the pin type to analog

Lighting the LEDs

This uses the standard neopixel code, with the LEDs connected to Pin 13.

At the top of your program add import neopixel then:

leds = neopixel.NeoPixel(13, 4)

leds is then an array of all 4 LEDs. leds[0] refers to the LED 0 and leds[3] refers to LED3. Each element of the array is a set of 3 numbers representing the Red, Green and Blue values (each 0..255) for that LED. So to set LED2 to Blue:

leds[2] = (0, 0, 255)

All this does is update the array. To show the new value of the array, we need to call the show ( ) function as follows: ( )


Reading the Ultrasonic Distance Sensor

The ultrasonic sensor breakout is on pin15.

The concept is simple: send an ultrasonic pulse out, then time how long it takes to return. Using the speed of sound and some maths, we can then work out the distance. The following complete program has 2 parts to it: a function sonar ( ) which returns the distance to the object, and the main code in a loop which continually prints the distance. We also need to import the utime library:

from microbit import *
from utime import ticks_us, sleep_us

def sonar():
    pin15.write_digital(1) # Send 10us Ping pulse
    pin15.set_pull(pin15, NO_PULL)
while pin15.read_digital() == 0: # ensure Ping pulse has cleared

    start = ticks_us() # define starting time
    while pin15.read_digital() == 1: # wait for Echo pulse to return
    end = ticks_us() # define ending time
    echo = end-start
    distance = int(0.01715 * echo) # Calculate cm distance
    return distance

while True:



Scooter for Raspberry Pi Zero

Scooter Robot for Raspberry Pi Zero

Purchase Scooter


Step 1 – Check you have all the parts

  • Main board with attached battery holder
  • 2 x wheels
  • 2 x 16mm pillars
  • 4 x screws
  • Female header

Step 2 – Remove the Battery Holder

Unscrew the battery holder, taking careful note of which way it is fitted


Step 3 – Fit the Raspberry Pi Zero

NB. You need to have a Pi Zero with the headers fitted. Model Zero WH is recommended

Screw the 16mm pillars onto the main board

Push the included female header into the low-profile header on the main board

Fit the Pi Zero to the header, with the Pi Zero sitting over the motors as shown below

Screw the Pi Zero onto the headers so it doesn’t fall off in use


Step 4 – Complete the Assembly

Refit the battery holder

Push on the wheels

Add batteries

Start coding…

Coding for the Scooter

Install the software

First you will need to prepare your Pi for the Smart RGB LEDs (fully compatible with neopixels). The best way we’ve found to do this is run Pimoroni’s curl script.
With your Pi connected to the internet, run (you don’t need to install the resources and examples):

curl -sS | bash

Then install the Scooter software:

wget -O


This installs the following files:

  • the main library module
  • Use the arrow keys to control the motors. Use . and , to speed up and slow down after next arrow press. Press space bar to stop slowly and ‘b’ to brake quickly
  • Sets the Smart RGB LEDs to Red, Green, Blue, White in turn. Run with sudo python
  • shows the states of the line follower sensors
  • gives the distance in cm to an obstacle using the optional HC-SR04P
  • is a simple obstacle avoider. Run with sudo python
  • is a simple line follower. This runs the Scooter backwards and is best with lines printed from RobotSquare.




Pi2Go Mk2 Assembly

Assembly Instructions for Pi2Go Mk2

Click any image to enlarge

Step 1 – Check the Contents

Check you have:

  • Main Board
  • Battery Board
  • Caster Board
  • 2 Wheels
  • 2 Motors
  • 2 Motor Fixings Bags
  • Bag with mechanical parts (caster, encoder disks, headers)
  • Fixings Bag with screws and spacers

Fixings bag contains:

  • 4 x 5mm, M3, Male-Female pillars
  • 4 x 11mm, M2.5 Male-Female pillars
  • 4 x 19mm, M2.5 Female-Female pillars
  • 2 x 24mm, M3, Female-Female pillars
  • 4 x 4mm, M3 screws
  • 4 x 8mm, M3 screws
  • 8 x 6mm, M2.5 screws


Step 2 – Fit the Raspberry Pi Mountings

You will need 4 x 19mm, M2.5 pillars and 4 x 6mm, M2.5 screws.

Fit the 4 pillars to the main board as shown below


Step 3 – Prepare the Motor Mounts

Screw 2 of the 5mm, M3 pillars into the top of each motor mount. Ensure they are fitted tightly


Step 4 – Fit the Motor Mounts to the Motors

Pass one of the long screws from the outside of the motor (the side without the wires), through the motor and through the motor mount. Then loosely fit one of the nuts. It will sit at a strange angle as shown below

Then pivot the mount on the long nut, so that it pushes the wires out of the way and allows you to put the second long screw in. Then tighten up both nuts.

Repeat for the second motor, but fit the mount the other way up.

You should now have a left-hand and a right-hand motor assembly as shown above

Step 5 – Fit the Motor Assemblies to the Main Board

First, attach an encoder wheel to the inside shaft of each motor. Just push it on so that it is flush with the end of the shaft. It may take some pushing to get it on, and when it is on it will be a bit floppy. This is normal

Now use the 4mm, M3 screws, 2 for each motor, to screw through the main board into the pillars that you fitted into each motor mount in step 3


Step 6 – Assemble the Front Caster board

Use 2 of the 8mm, M3 screws to screw through the caster, through the caster PCB and into the 24mm, M3 pillars. Ensure the header pins are on the opposite side to the caster, and the same side as the pillars.


Step 7 – Fit the Caster Board to the Main Board

First push the extended 6-pin header into the header on the bottom of the main board, then plug the assembled caster board into the 6-pin header as shown below

Finally screw the 2 remaining 8mm, M3 screws through the main board and into the top of the pillars from the caster board. Tighten up well.


Step 8 – Fit the Raspberry Pi

You can use a Model A, A+, B or B+.

NB: To use a Raspberry Pi Zero, use the “Zero Spacer” PCB that is included with Pi2Go Mk2 since 1st September 2019. Kits shipped prior to that date do not include that spacer so you would have to use washers or similar to make up the extra 1.6mm height.

Push the 40-pin header onto the header on the main board

Then push the Raspberry Pi, upside down, into the 40-pin header, ensuring that all the pins line up and the mounting holes on the Raspberry Pi match the pillars

Screw the 11mm, M2.5 Male-Female pillars in well to hold the Pi firmly


Step 9 – Fit the Battery Board

Standard 6 x AA battery board shown. Fitting the other types is the same

Making sure that the LEDs marked 0 through 7 are at the front, use the 6mm, M2.5 screws to fix the battery board tightly to the 4 pillars.
Note that these pillars all carry power and/or signals, so it is important that they are all screwed in well. Failure to attach screws or pillars properly will result in failure of the Pi2Go.


Step 10 – Add the Wheels

Push on the wheels

And the build is complete!

Now go to the Programming Pi2Go Mk2 article to get it going



PiBug Assembly and Coding


Click on any image to enlarge

A barebones, but sturdy, 2WD buggy for the Raspberry Pi, that uses the Pi itself as the chassis for the robot.

Purchase PiBug Here

Assembling the PiBug

Step 0 – Check you have all the parts

  1. Main board
  2. Caster board
  3. Battery board
  4. Battery holder
  5. Castor Pack containing:
    1. Castor ball and housing
    2. Screws: M3, 6mm X 2
    3. Nuts: M3 X 2
  6. Fixings Pack containing:
    1. 22mm F-F pillars X 2
    2. 22mm M-F pillars X 2
    3. 30mm Pillars with holes X 2
    4. 25mm F-F pillars X 2
    5. 9mm M-F pillars X 8
    6. 6mm M2.5 screws X 6 (2 for the caster board)
    7. 30mm M2.5 screws X 4
  7. Motors X 2
  8. Wheels X 2

Step 1 – Attach the Castor to the Castor board

Put the M3 nuts in the holes in the castor housing, then use the 6mm M3 screws to fit the housing tightly to the castor board as shown, with the castor on the bottom and the large 4tronix logo on the top.

Step 2 – Assemble the Motor Mounts

  1. Screw a 22mm Male-Female pillar into a 22mm Female-Female pillar tightly, making a 44mm female-female spacer (remember: 22mm is not the same as 25mm)
  2. Repeat to create a second 44mm spacer
  3. Thread the 30mm screws through the holes in the motor and through the holes in the side of the 30mm pillars, then screw into the 44mm spacers
  4. Important: The 30mm pillars with holes have one end rounded for about 1mm. This is the bottom, the other end is the top that fits to the Raspberry Pi. The rounded end is tapped for M3, and the hex end is tapped for M2.5. Ensure you have these the correct way up
  5. Ensure that the motors shafts are facing outwards as shown in the photo

Step 3 – Fit Motor mounts to Raspberry Pi

You can use either Model A or Model B varieties of Pi. You can’t use a Zero (at least not without some ingenuity…)

  1. In this step we will use 4 of the 9mm pillars
  2. Screw the threaded end of the 9mm pillars through the 2 holes in the SD card end of the Raspberry Pi and into the top of the 30mm pillars of the motor mount assembly
  3. Ensure all screws are tightly fastened

Step 4 – Fit the Castor assembly to Raspberry Pi

  1. Use 2 of the 6mm M2.5 screws to attach the 25mm pillars to the top of the castor board
  2. Use the 2 more of the 9mm pillars and screw through the holes in the Pi into the top of the 25mm pillars as shown

Step 5 – Fit the PiBug Main Board

  1. Push the PiBug main board onto the GPIO connector of the Pi. Ensure all the pins are lined up properly and that the holes on the PiBug board line up with the 9mm pillars
  2. Use the threaded ends of the 4 remaining 9mm male-female pillars to fit the PiBug main board into position.

Step 6 – Fit the Battery Holder Board

Use the 4 remaining 6mm, M2.5 screws to fit the battery holder PCB as shown, with the snap connectors at the USB/ethernet end of the Raspberry Pi

Step 7 – Connecting it up

  1. Connect the JST leads from the motors into the appropriate motor connector on the PiBug board
  2. Fit 6 AA rechargeable batteries into the battery holder and then plug it into the connectors on the battery board.
  3. Note that it will work with alkaline batteries, but when the batteries get low it may suddenly reset the Pi when changing motor direction. This behaviour is better with rechargeable batteries.
  4. We recommend that you use a velcro strap or similar to hold the battery pack in place in case of accidents

Step 8 – Fitting the Optional Line Sensor Board

Use the servo leads to connect the line sensors from the caster board to the male header on the PiBug main board. Ensure the correct orientation of the cable: Brown wire should be on the robot’s right side of the castor board (labelled ‘G’) and on the bottom of the header on the PiBug board (labelled Gnd). Use the leftmost and rightmost positions for the cables

Step 9 – Fitting the Optional Ultrasonic Distance Sensor

  1. Use a HC-SR04P which is 3.3V compatible. Do not use the older HC-SR04.
  2. Remove the black plastic spacer, so that it can push all the way down.
  3. Plug it through the 4 holes in the battery board and push it all the way down (see photo above)
  4. The sensor is now connected to pin 20 on the Raspberry Pi

NB. We have also sold the HC-SR04+ for this purpose. it doesn’t need modifying by removing the spacer, but it is a little shorter and may need holding in to keep a good connection.

You have now completed the buggy and all you need to do is code it!

Coding PiBug

Pins used:

Left motor: #19, #26

Right motor: #16, #21

Ultrasonic: #20

Line sensors: #04, #27

Tact switch: #13

There are also 2 spare GVS style connectors which you can use for what you want on #17 and #18

A PiBug library module and example code is available by running the following commands in a terminal window on your Pi

  • wget -O
  • bash



Programming Robobit Buggy in Makecode

Programming Robobit Buggy

The Microbit Makecode Package supports all versions of the Robobit. Go to or download the PC app from here 

Select Advanced or click on the gear icon, then select Extensions. Enter Robobit in the search box and search.

After it has loaded you will have an extra tool in 4tronix Orange with the Taxi icon, called Robobit

If you click on the Robobit tool, there are 3 subfolders for the Motors, the Sensors and the LedBar. There is also a single top-level block to allow you to select your model of Robobit – this should be used at the very start as shown below. In fact it can be the only thing in the start block

Now you are ready to start programming…

Programming the Motors

It’s a robot – you want it to move. So let’s see what we need to do.

The motors are individually controllable. So if you want, you can set different speeds for the left and right motors. But to start simply, let’s just drive forwards and backwards.

Forwards is represented by speeds from 0 to 1023. Backwards is speeds from -1023 to 0.

In both cases, 1023 is the fastest and 0 is dead stop. You will find that speeds below 200-300 may not be able to move the robot very much (it depends on battery levels, how “free” the motors are, etc)

The following code simple drives forwards at speed 600 (both motors at the same speed) for 1 second, stops for a second, then reverses and stops again. It repeats this forever

Yes, we have a moving robot!

NB. You may find, especially when the motors are new, that they go at different speeds and it doesn’t travel in straight lines. This is normal. The motors have a 10% speed tolerance, so can always be different speeds, but when they are new they can be especially stiff and even more different. Run the motors at full spoeed for a few minutes to free them up.


More Complex Motor Control

We can try and move in a square, or other shape. Great if you’re on a piece of paper and using the pen (Pen holders are designed for Sharpie felt tip pens – other pens are available)

Drive forwards for a bit, turn for a bit and do this 4 times. If you get the speed and times correct then a square can be formed. You will have to experiment with the speeds and times

The code above (click to enlarge) will do a four-sided figure and then stop. You will have to adjust the timings and/or speed of the spin to get it to accurately draw a square.

Of course, this software is tedious. It does the same thing 4 times. It would be better to use a loop function like this:

Here, we are using the “repeat nn times” block from the “Loops” toolbox


Now Let’s Flash some LEDs

It’s always fun to light LEDs and especially fun if you can control them individually with different brightness and colours.

The Robobit Mk3 and the Mk2 with LedBar have a row of 6 LEDs across the front as well as one in each front corner for a total of 8.

Scanner Feature

The Makecode package has a unique “Larsson Scanner” feature built-in which enables you to very easily scan the centre 6 LEDs back and forth at your choice speed and colour. Let’s do this to start with:

From the LedBar section of Robobit, select the “start scan…” block and insert it into the program after setting the required Robobit model. Here we are using a Mk2 Robobit with a LedBar attachment.

This code will immediately start the centre 6 LEDs scanning using various intensities of Red, with a delay of 100ms between changes, just like the Knight Rider KITT car!

Standard LED Programming

Normally when using the LEDs you will set on or more LEDs to a particular colour depending what you want the program to display. To do this, you need to understand how to work with individualy LEDs.

There are blocks you can use to set individual LEDs (or pixels), or all the LEDs at the same time. You can select colours using the names of colours (eg. Red, Yellow, Green, etc) or you can specify your own colour in terms of Red, Green and Blue components. All these blocks set the memory in the Microbit for the LEDs, but they do NOT update the LEDs with this memory information. To do that, you must use the most important block of all:

After doing this, all the changes you have made will be shown on the LEDs.

The other thing to remember is that the 8 LEDs are numbered from the left at 0 to the right at 7. So to flash the leftmost LED in Orange, we could do this:

This will set the LED at position 0 to orange, then wait for half a second, then set the LED to black (this is the same as OFF), then wait another half a second. Then this keeps repeating forever. Notice that each time we update the LED information, we than “show the LedBar changes”.


Using Sensors

Depending on your Robobit model and options fitted you may have an Ultrasonic Distance sensor and/or line following sensors. For the Robobit Mk3, these are both included as standard. For the Mk2, they can be purchased as options.

The Robobit Makecode extension includes blocks for using these easily.

Line Following Sensors

There are 2 of these mounted underneath the buggy, close to the front caster. They both use the same hardware sensor (TCRT5000) but the integrated ones on the Mk3 use 4tronix electronics specifically designed for this application whereas the Mk2 uses generic modules which have a trimmer on. Turn this until the LED turns off when it goes over a black line. You will find that the integrated units perform better.

The key thing to remember is that the Robobit buggy and the motors have a lot of interia when moving and cannot stop very quickly, so you must design your line follower program to move slowly (there are clever things that can be done, but we won’t look at that now). The Mk2 will have to go slower than the Mk3 because of the difference in sensitivity of the sensors.

To create a track to follow, you can use black electrical tape, or a permanent black marker. The surface needs to be reflective and the tape or marker pen needs to be not reflective. I prefer to print the tracks using track tiles from RobotSquare as these work excellently.

The simplest algorithm will be to check each sensor. If it is over a line, then turn the buggy that way, otherwise carry straight on. Keep checking in a loop like this:

Note that we are using speeds of less than 400. For a Mk1 or Mk2 you will probably have to go even slower.

This is a very basic algorithm and will have problems with junctions on the track etc. it also won’t do very well in a speed trial.


Ultrasonic Distance Sensor

These little sensors work like bats, by sending out an ultrasound ping and waiting for the echo to come back. The time for the echo to come back, together with the speed of sound, gives us an idea of the distance. Do not expect ultimate accuracy from these sensors.

You can choose to get the distance back in different units: centimetres, inches or microseconds. These examples all use centimetres (cm).

Obstacle Avoider

This simple program drives forwards until it detects an obstacle, then spins and reverse to avoid it before setting off again.

The first block checks if the robot is within 20cm of an object. If it is then it reverses at speed 500 for half a second, before turning left for 400ms. If it is not less than 20cm from an object it just drives straight on at speed 600.


Follow Me Program

This fun little program drives forwards until it gets close to an object and then stops. Then if the object (eg. your leg) gets further away, it will start moving again to follow you. However, if your leg gets closer then it will back away trying to keep the same distance from you:

In this one, we have created a variable called Distance so that we can check it against 2 values without reading the sensor again. Here we reverse the robot if it less than 20cm away and go forwards if it is more than 30cm away. Between 20cm and 30cm the robot will stay still.

Robobit Buggy Mk3

Assembling and Using Robobit Mk3

Robobit Mk3 buggy is a fully integrated and updated version of the Mk2 with all options (except Talon grabber) ready integrated into the unit

Purchase Robobit Mk3 here


  • Compact design DIY robot that is easy and quick to build
  • No soldering required. Screwdriver and spanner widget included and are the only tools required
  • Presented in an attractive gift box
  • Integrated ultrasonic distance sensor
  • Integrated line follower sensors
  • Integrated pen holder (designed for Sharpies, but other pens will fit)
  • Integrated RGB smart LEDs (aka neopixels) with semi-automatic Larsson scanner function
  • Fully supported by the Microsoft Makecode extension – search extensions for “Robobit”
  • Powered by 4 x AA batteries (not included)


Step 1 – Check you Have the Correct Parts


  • Main PCBA with prefitted ultrasonic sensor
  • Battery Holder PCBA (NB. Ring fits to rear of robot – no matter what it says on it!)
  • 2 x bags with motor mountings
  • Bag with 4 x 6mm M2.5 screws and 2 x 25mm pillars (6 screws on v1.2 and earlier)
  • 2 x motors with pre-fitted cables and plugs
  • 2 x Wheels

You should also have 2 tools: a double ended screwdriver (pull out of handle and turn round ot get alternate end), and a Pimoroni “spanner widget” for the motor mount nuts


Step 2 – Fit the motor brackets to the Motors


Mount the brackets the opposite way to each other so you have left hand and right hand assmblies as shown.

Use the Pimoroni spanner widget to held the nuts while you tighten the screws.

NB. Very important to ensure the edges of the nuts are flat with the top of the motors or the motors will be at a strange angle when fitted.


Step 3 – Fit Motors to Mainboard


Use the two 8mm M3 screws in each motor mount bag to fit the motors to the top of the main PCBA as shown above. Do these up tightly so the motors do not come loose with use.

Ensure the axles are at the rear and facing outwards.


Tighten the screws fully


Step 4 – Fit the Front Caster (v1.2 and earlier only)


Remove the ball if it is supplied already in the housing

Use two of the 6mm screws to fit the housing the the bottom of the main board as shown above


Step 5 – Fit the Battery Mounting Pillars


Use two of the 6mm screws to fit the 25mm pillars as shown above

Tighten up fully


Step 6 – Attach the Battery Holder


Use the remaining two 6mm screws to attach the battery holder firmly

Ensure the pen holder ring of the battery holder is directly above the pen holder hole in the main board


Step 7 – Finish

Push on the wheels and pop in the caster ball

Fit batteries.

Add your Micro:Bit and start programming!

Visit Programming Robobit Buggy in Makecode

Programming in Python

For text-based programming there is micro-python, and I prefer to use this offline using the Mu editor.  It provides a very neat and easy way of interfacing to the micro:bit without all the fuss of dragging and dropping.

Note on examples: We want to show people how the various features can be used. We don’t want to do the coding for you – that is the learning experience you should be taking away from using it. In the following examples, we will give you the tools to use all the features of Bit:Bot but it is up to you to combine them together in your code to make it do something useful. We do give a complete example of line-following – but it is a very basic algorithm and will get confused at T-junctions  and crossings; and it doesn’t use the neopixels.

Some great tutorials/examples for BitBot (which is very similar) by Mark Atkinson here


Each motor has two pins connected to it. One determines the speed and the other the direction:

Left motor: Speed Pin 0, Direction, Pin 8

Right motor: Speed Pin 1, Direction Pin 12

The simplest way to make the motors move is to set the Speed pin to HIGH and the Direction pin to LOW (to move full speed forwards)

Move left motor Forwards:


Move left motor Reverse:


If we want to change the speed of a motor, so that it is not going at full speed all the time, we need to use PWM (Pulse Width Modulation). This is means of changing the amount of power given to the motor by switching it on and off very fast. The percentage value of PWM determines the amount of each cycle that the output is ON. So a percentage of 100% is the same as being on all the time and thus the same as the examples above. A percentage of 50% would mean that the motor is only energised half the time, so it will go much slower. Note that the actual speed of the motor is not the same as the percentage of PWM – the motor won’t turn at all if the PWM value is too low and you will also get some stuttering at certain values. Nevertheless, being able to change the speed makes for a much better robot. For example, you can make a line follower that smoothly follows the line, rather than the normal shaking left and right.

To change the PWM value of a pin, we must use the analog_write commands. These can be set to a value between 0 (always off) to 1023 (always on), so 50% would be 511. Here are the commands to change the speed of the Right motor to approx 75% (value is 770)

Move right motor forwards at 75%


Doing this for the motors moving in reverse is a little confusing. Remember we need to change the direction pin to 1 for reverse. Then we need to set the amount of time in each cycle that the speed pin is LOW. This is the opposite of moving forwards, where we set the time for it to be High. Se we simply take the number (770 in this case) away from 1023, giving 253:

Move right motor Reverse at 75%




In fact, the name “neopixel” is a termed coined by Adafruit, but like “hoover” was a name of a brand of vacuum cleaner and is now a general term for all similar products, whoever makes it. The generic term is “smart RGB pixel” and is usually referenced with the name of the chip WS2812B. However, there are many different chips, all performing in a compatible way. The ones on the Robobit Buggy Mk3 are actually SK6812-3535

These smart RGB pixels are able to display any of 16 million colours by selecting a value of 0 to 255 for each of the Red, Green and Blue LEDs on each chip. The whole thing is controlled by a single pin on the BBC micro:bit (pin 13 for Robobit Buggy Mk3). It is simple to use the included neopixel libraries to control each pixel individually.

The 8 pixels are labelled on the Robobit Buggy Mk3, from 0 on the left arm to 7 on the right.

Set neopixel 2 to purple (red and blue)

import neopixel
np = neopixel.NeoPixel(pin13, 12)
np[2] = (40, 0, 40) )

The first line imports the neopixel library. We only need to do this once, at the very top of your Python programThe second line creates an Python list with an element for each pixel. As shown, it specifies 12 pixels connected to pin 13. If you added more neopixels then you would increase the number from 12 by the number of pixels you added. eg. if you added a McRoboFace, then the total would be 12 + 17 = 29 so you would change the line to: np = neopixel.NeoPixel(pin13, 29)
The third line sets the pixel we have selected (number 2 in this case) to the colour which is set by three values in the brackets, each value can be from 0 to 255 and covers Red, Green and Blue. In our example we have set Red and Blue to 40.
The fourth line tells the neopixel library to copy all the data to the neopixels, from the Python list that we have been working with. It is only at this point that the LEDs change. In general, you would make all the changes you want and only at the end would you use a )

Line Follower Sensors

These are digital inputs and connected to Pin 16 (left) and Pin 14 (right).

You can use digital_read commands (as shown below) to read the value of each sensor. If the left sensor detects a line, it means the Robobit Buggy Mk3 is too far to the right, so it should move left. The opposite is the case if the right sensor detects a line. Here is some simple code for line following in Python (the actual motor commands are in separate functions for clarity)

while True:
    lline = pin16.read_digital()
    rline = pin14.read_digital()
    if (lline == 1):
        spinLeft( )
    elif (rline == 1):
        spinRight( )

Ultrasonic Distance Sensor

The integrated HC-SR04P ultrasonic distance sensor addon can be used most easily in Microsoft PXT. In MicroPython we can use the utime module to measure time at microsecond level. Below we have a function called getDistance() which returns the number of cm to the nearest object. Then we have a while loop that prints the distance every second:

def getDistance():
    pin15.write_digital(1) # Send 10us Ping pulse
    while pin15.read_digital() == 0: # ensure Ping pulse has cleared
    start = ticks_us() # define starting time
    while SONAR.read_digital() == 1: # wait for Echo pulse to return
    end = ticks_us() # define ending time
    echo = end-start
    distance = int(0.01715 * echo) # Calculate cm distance
    return distance

while True:
    display.scroll (getDistance ( ) )