The Totem custom-designed boards are made for the BBC micro:bit and comprise a “power board” and a “sensor board”.
The power board consists of an edge connector into which you slot the micro:bit, a 3xAAA battery holder, three motor ports (one of which controls the crab's claw) and an on/off switch. The sensor board contains 4 RGB LEDs, a piezo-sounder, vibration motor, a light-level sensor, temperature sensor and two touch button/slider sensors.
Whether you follow the instructional videos on the BinaryBots website, or use the booklet provided (“Inventors Manual”), the first bit of coding you will do will be to make the claw open and close using the excellent MakeCode for micro:bit block-based coding environment.
As far as I could see, after that, you are on your own unless you then move to the Python environment as there are no further examples or tutorials using MakeCode. Specifically, there is no way to control any of the components on the sensor board using MakeCode blocks. For younger children, this could be disappointing, as they would want to make use of the sensor board with its RGB LEDs, vibration motor and piezo-sounder. It could be quite a big leap to go straight into Python coding. This blogpost is about how to control the sensor board with MakeCode.
|Board function||Micro:bit pins|
|Motor 1||Pins P13 and P14|
|Motor 2||Pins P15 and P16|
|Motor 3||Pins P8 and P12|
|Pin 0 (front of board)||P0|
|Pin 1 (front of board)||P1|
|Pin 2 (front of board)||P2|
|3V (front of board)||3V|
|GND (front of board)||GND|
Coding with PythonBinaryBots have provided several examples of Python code on their website [https://www.binarybots.co.uk/activities] to move the crab’s pincers, control the LEDs and read the touch and temperature sensors. For beginners, I think it would have been more helpful if BinaryBots had written a Python module with functions to which you can pass parameters, rather than having to use the ‘struct’ data format, which can be quite complicated.
Read Light sensor
Read Temperature sensor
Where there is more than one byte, the ‘<’ symbol signifies that the byte values are to be passed in ‘little-endian’ order. In the case of the LEDs, the five bytes (BBBBB) are:
LED# can take one of five values (one for each LED or 0 for all four). For example, to turn all four sensor board LEDs green, the example Python code is:
Although the sensor board has a light sensor and temperature sensor, there is no documentation provided on either sensor, apart from some sample code. Although BinaryBots provide some sample code for reading these sensors, they do not provide any information on what the numbers represent. The Python code for the light and temperature sensors suggest that the outputs are 16-bit signed integers (0-1023) so it appears they are analogue sensors. The light sensor is clearly visible and marked on the board but there is no sign of a temperature sensor. I conclude that the temperature reading is actually the ARM Core CPU temperature, which is supported by the fact that placing my finger directly onto the MCU caused the reading to rise.
Here is the micropython code for reading the temperature sensor and printing the raw analogue value via the USB cable to the PC console (REPL):
from microbit import *
temp = i2c.write(42,struct.pack('B',7))
rx = i2c.read(42,2)
temp = rx + (256 * rx)
(42,struct.pack('B',7))will print the raw light sensor readings, instead of the CPU temperature, to the REPL.
let buf = pins.createBuffer(5);
buf.setNumber(NumberFormat.Int8LE, 0, 0);
buf.setNumber(NumberFormat.Int8LE, 1, 0);
buf.setNumber(NumberFormat.Int8LE, 2, 0);
buf.setNumber(NumberFormat.Int8LE, 3, 255);
buf.setNumber(NumberFormat.Int8LE, 4, 0);
pins.i2cWriteBuffer(42, buf, false);
If you go back to the Blocks window, you'll see something like this:
As can be seen, the Python code is much more economical. However, I wanted to use MakeCode because I have not yet found a reliable way to use the Grove Ultrasonic Ranger in micropython and I wanted one of those to make my Crab more entertaining. Also, I wanted to show that it is possible!
Post a Comment