Introduction: GiggleBot Line Follower Using Python
This time around, we are programming in MicroPython the Dexter Industries GiggleBot to follow a black line using its built-in line follower sensor.
The GiggleBot has to be paired with a BBC micro:bit in order for it to be controlled appropriately.
If this tutorial is too advanced for you and programming the GiggleBot is too much for now, you can always go through the starter tutorial that shows you how the robot can be programmed in MakeCode here . The linked tutorial will walk you through the very basics.
Step 1: Required Components
The following hardware components are required:
- x3 AA batteries - in my case I'm using rechargeable batteries which have a lower voltage overall.
- A Dexter Industries GiggleBot robot for the micro:bit.
- A BBC micro:bit.
Of course, you also need a micro USB cable to program the BBC micro:bit - this cable generally comes within the BBC micro:bit's package or you can always use one that's used for charging (Android) smartphones.
Step 2: Setup the Tracks
You will have to go through printing some tiles and designing your own tracks. You can use our own tiles so that you are 100% sure you are replicating our conditions. Or if you feel adventurous, you can use some black tape and make your own. Here's the PDF for the tiles we have used.
The above track is composed of the following number of different tiles:
- 12 tiles of type #1.
- 5 tiles of type #2.
- 3 templates of tile type #5.
- 3 templates of tile type #6 - here, you'll end up with one extra tile.
Next up, print them and cut them. Try placing them like in the above photo and keep in mind that on the right top side of the track, 2 tiles have to overlap one with another - this is expected in case you're wondering if you're doing something wrong.
Step 3: Setting Up the Environment
In order for you to be able to program the BBC micro:bit in MicroPython, you have to set up an editor for it (the Mu Editor) and set the GiggleBot MicroPython Runtime as its runtime. For that, you have to follow the instructions on this page . As of this moment, version v0.4.0 of the runtime is used.
Step 4: Programming the GiggleBot
Before getting down to it, the GiggleBot MicroPython runtime contains the classic runtime for the BBC micro:bit and other libraries to support the GiggleBot and other Dexter Industries Sensors.
After setting it up, open the following script in the Mu editor and click on Flash. This will flash the GiggleBot MicroPython Runtime and the script you've just opened up to your BBC micro:bit. The script is also shown down below.
Once the flashing process is done, stack the BBC micro:bit into the GiggleBot with the board's neopixels facing forward, place it on the track and switch it on.
Notice that in the script, the PID and other 2 constants (the speed setpoint and minimum speed constants) are already set.
Note: The following script might have missing whitespaces and this seems to be due to some issue in displaying GitHub Gists. Click on the gist to take you to its GitHub page where you can copy-paste the code.
Step 5: Letting It Run
There are 2 buttons on the BBC micro:bit: button A and button B:
- Pressing on button A sets the GiggleBot to follow the line (if there's one).
- Pressing on button B stops the GiggleBot and resets everything so that you can use it again.
It's highly advised to not lift the GiggleBot while it's following a line and then put it back on it because the error that's calculating could accumulate and totally mess the robot's route. If you want to lift it, press on button B and then when you put it back press A again.