This time around, we're making the GiggleBot follow a source of light, like the light coming from a flashlight. This will all be done in MicroPython. For that, you'll need to download the GiggleBot MicroPython Runtime.
Step 1: Getting the Required Stuff
Well, just like in other GiggleBot tutorials, you'll need the usual GiggleBot, a set of 3 AA batteries and a BBC micro:bit board.
Apart from these 3, you will also need a flashlight to make the GiggleBot follow it. Or you could just as easily use the smartphone's flash for that matter.
Step 2: Setting Up the Environment
The GiggleBot MicroPython Runtime is required. This runtime can be downloaded from its documentation here . For that, you'll have to follow the instructions on the Getting Started chapter of the documentation.
Step 3: What Light Sensors (not Actually a Step)
The GiggleBot comes with 2 light sensors that sit right in front of the PCB, next to the 2 NeoPixel LEDs. They are very small and quite hard to spot. They are the size of an ultra-small resistor.
Step 4: Processing the Light Sensor Signals
When integrating their signal, we first run a weighted average on both of them and then make the resulting signal go through a low pass filter. We need to make it go through a low pass filter because both sensors are quite noisy and if we were to also take into account these high-frequency noises, the GiggleBot would have a hard time following the actual light source.
These 2 sensors are especially noisy in low light situations, so if the GiggleBot would be left to go into the dark while there's no strong light source around and no low pass filter is applied, it would then have a choppy trajectory - constantly going to the left and right.
Step 5: Programming It
The following code is the program for the GiggleBot light follower. One thing to keep in mind is that you need to use the GiggleBot Runtime for the GiggleBot, which can be found on its documentation here. At this moment, version v0.4.0 is used, but later versions could be very well used too.
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 6: Running It
While running the program, you have at your disposal 2 actions:
- Pressing on button A to make the GiggleBot follow the light source.
- Pressing on button B to make the GiggleBot stop in its tracks.