EggBit – Wearable Microbit

Purchase >HERE<

Overview

EggBit is a new wearable product for the popular Microbit. It comes with built-in RGB lights, buttons, animatable LED mouth and ultrasonic distance sensor. It also incoporates a battery pack, on/off switch, indicator LED and power circuitry.

EggBit is available in 3 functionally identical flavours: Sunshine, Twinkle and Dizzy

Coding them in Makecode is simpe. There is a Makecode extension written especially for them. Seacrh for EggBit in the EXtension search box.

Programming with Makecode

First you should load the EggBit extension to Makecode. Go to the Advanced section and select Extensions. Then in the search box, search for EggBit and then press Enter.

Then you can explore the various options. Within the EggBit extension are three categories: Input/Output, FireLeds and More

Input/Output section contains blocks to work with the buttons, the animatable mouth and the iultrasonic distance sensor.

FireLeds section contains the basic functions for driving the nine FireLeds, including use as a Larson scanner and a bar graph,

More section contains the advanced FireLed functions. Generally these will not be required.

Buttons

The four buttons can be coded in different ways. At any time in your code you can check the state of the button: whether it is pressed or not pressed. Alternatively, you can select a block that is only activated when the specified button is pressed or released (event-driven programming).

The following shows the method of checking the state of a button. This block is a “Boolean” value which can give the result True or False. It returns True if the button is currently pressed, otherwise it returns False. So it can be used directly in an if/then/else block as shown below. This example sets all the FireLeds to Red if the red button is pressed, otherwise it switches them off.

Using the event-driven model is equally simple. Select the button you want and whether you want to activate the block when the button is pressed, or when it is realeased. Then within the block you can run any code. The following two blocks set the mouth to Smile when the Yellow button is pressed and set it to Sad when the Blue button is pressed.

Mouth

The animatable mouth has three separately controllable sections: Upper, Middle and Lower. You can control these sections individually if you like, or you can use the predefined expressions. As there are three sections and each can be either On or Off, there are eight possible configurations of the mouth.

For instance, to make an open, happy smile you would light the middle and lower sections, leaving the upper section off. You can do this by setting each part individually, like this:

Or you could use the predefined expression, OpenSmile:

Ultrasonic Distance Sensor

This is a standard HC-SR04 type sensor that is specified to work from a few centimeters to a couple of metres. Note that as the beam angle is large, the further away the obstacle is, the larger it needs to be to provide sufficient reflection. This is normal behaviour.

There is only one block for the ultrasonic sensor, which returns the distance to the nearest reflective object. You can select whether to get the answer in centimetres, inches or microseconds. In the following example, we set the FireLeds to Red if the object is less than 50cm away, Orange if less than 1m away, otherwise we set it to Green.

FireLeds

The EggBit has nine FireLeds, which are individually addressable RGB LEDs. You may have previously known them as neopixels. Each FireLed can be set to any of 16 million different colours, because the brightness of Red, Green and Blue components can each be set using 8 bit data (256 values each). To simplify setting the colours, we have produced a palette of 25 basic colours

However, you can set the colour directly using the “convert from red, green, blue” block in the More category. Simply drop the convert block on top of the colour:

As well as setting all FireLeds to a specific colour, you can switch them all off using the “Clear all FireLeds” block, or set just a single FireLed to a specific colour using the “set FireLed at” block. The nine FireLeds on EggBit are clearly labelled with their number, from 0 to 8. This example sets FireLed 5 to Pink

Larson Scanner

You can set the Larson Scanner going by specifying the colour to use and the delay between display updates. The shorter the delay, the faster the scanner goes. Typically we set the colour as Red and the speed as 100 or 200ms

Use the “stop scanner” block to disable the scanner.

Bar Graph

The nine FireLeds can be configured as a bar graph, with the leftmost FireLed (0) being a low value and the rightmost (8) being a high value.

First, you must set up the parameters for the bar graph to work with. The system needs to know the colours to use for start and end and the value assoicated with the lowest LED and the highest LED. Use the “set graph” block to do this. The example below sets the range of values to be shown as 0 to 100 and the colours from Green to Red. The system will slowly change the colours so that the overall change starts at Green and ends at Red – in between there will be various shades of colour.

Now you can draw a bargraph by providing it with a number. The number doesn’t have to be in the range given, but anything higher than 100 (in the example above) woiuld be treated as 100, and anything lower than 0 would be treated as 0. The example below uses the value from the ultrasonic distance sensor to set the bargraph:

DriveStraight (TM)

For the latest releases of Minibit and BitBot XL, 4tronix have added DriveStraight technology in the hardware and Makecode extensions.

This works using a Flash memory chip which stores the calibration details of the motors at three different speeds: 30%, 60% and 90%. This information is used to generate the actual speeds used for each motor to give the best chance of moving straight ahead when required.

Because this data is stored in permanent memory, it only needs to be calibrated once and then it will automatically be used from then on. You don’t have to do anything in your programs for it to be used and it doesn’t matter if you change the Microbit at any point. The calibration data is specific to the robot it is created on – it isn’t related to the Microbit at all. So you can swap between Microbits including v1 and v2 types.

You may find that the calibration data changes over time as the motors wear differently. If it gets too far out, then simply run the calibration program again.

DriveStraight is built into the latest Makecode extensions. It isn’t available in Python, although you can access the Flash memory from Python and use it yourself.

On the Minibit, you also have user access to the rest of the Flash memory. You can use this for what you like: storing sequences, remembering particular LED settings, etc. This feature will be added to the BitBot code shortly.

BitBot XL calibration code >here<

Minibit calibration code >here<

Calibrating the Motors

Note that this code only works on BitBot XL v1.2 or later, or Minibit v1.3 or later.

Process: The calibration program starts at speed 30 (displaying 3 on the Microbit LEDs). You then set the left or right speeds until it is driving straight. Then give the robot a good shake and it will change to speed 60 (displaying 6). Set this speed, shake again to change to speed 90 (displaying 9). Once this speed is set correctly, shake again and it will return to speed 30. You can then switch off and all the values are stored. If you run the program again, you will start from the un-calibrated values and must follow all the steps again.

  • Load the program into the Microbit and plug it into the robot
  • Switch on the robot. It will display 13 (indicating a v1.3 Minibit) or 5 (indicating a v1.2 BitBot XL), then change to show 3 (meaning speed 30)
  • Press A or B buttons to affect the turning left or right, then press both A+B simultaneously and the robot will display the current calibration value, then move forward for 2 seconds at speed 30.
  • If it is still not moving straight, press the appropriate button one or more times to straighten it up, then press A+B again to test it
  • When you’re happy that it is moving straight, give the robot a shake and it will store the values for speed 30 and move onto Speed 60.
  • Repeat for speed 60 and speed 90
  • When you’re happy that all three speeds are set correctly, then switch off. Don’t switch it back on again without changing the software in the Microbit, because the first action of the calibration program is to reset the calibration values.