As a part of the "microbit world tour" program, I'm putting the micro:bit on a robot. This is a very basic animal, assembled from junk I had lying around, held together with two-sided tape and hot glue. No soldering required, so any kid can try and build one like this.
But then making it turn exactly 90° or travel exactly 10cm required some careful experimentation with timing.
Once I had that, hooking up the distance sensor was easy. It's an analog SHARP range finder, so all I needed was to read the analog pin. Then I added some simple logic for finding out in which direction the obstacle is further away, and voila, object avoidance:
I knew what I wanted to do with the micro:bit -- I wanted to put it into robots and program them in Python. So I decided to start with the simplest thing possible -- a two-wheeled robot, with continuous rotation servos and a caster wheel. I only had two criteria for choosing the parts:
I had to have them already, because I only had a few days, and they had to be off the shelf -- no salvaged or custom-made stuff, so that it can be replicated easily.
No soldering, laser-cutter, 3d-printer etc. Just two-sided tape and some glue.
I started by gluing everything together with the two-sided tape in several different configurations. At the beginning, I didn't have the white depron bar to hold the screws, so I simply hotglued them to the servos:
This is actually the only interface the robot has with the micro:bit, because I didn't have the edge connector for accessing all the other pins yet. But three pins is enough for me -- two for the servos, and one for the distance sensor.
After assembling and testing it with some simple code, I noticed that the servos have a lot of problems with the PWM signal generated by the micro:bit. They would basically rotate at maximum speeds in random directions... So I went to the nearby hackerspace and used their oscilloscope to look at the signal. Turns out that you have to set the frequency of the PWM signal several times for it to have the desired effect. After just one time, the frequency is off by an order of magnitude:
But then if you actually start sending a signal and set it again, it becomes correct:
Well, correct apart from some twitching, and it would still change directions randomly. Since I couldn't find the reason for that in the signal, I turned to the power. And yes, replacing the two alkaline AAA batteries with a 3.7V LiPo battery solved that problem.