Kitronik Custom MakeCode Editor Servo Blocks
We’ve released several new robotics products recently that make use of servos and motors to provide movement. We recognised that creating code for the microbit to control these servos and motors can become time-consuming. Especially if you are experimenting or re-purposing your robots projects regularly. adding a servo With that all in mind, we thought it would be useful to create some custom blocks for the MakeCode editor.  Blocks that make the job of coding these devices as quick and as painless as possible.  

Adding Kitronik Custom MakeCode Editor Blocks:

At the time writing, we have three packages. They have been added directly to the Microsoft Makecode Editor and can be added in the same way that other Extensions are. Click the Cog icon in the top right of the editor and select 'Extensions' from the menu. This will open the Extensions window. Click into the search bar and type Kitronik then hit enter. The window should now look like the image below and you can make a selection from the available tiles. You will now have access to the blocks that you have chosen via the blocks menu. As can be seen with the Servo:Lite blocks shown below: Now that we know how to add them to the MakeCode Editor we’ll have a look at each block individually to see what they all do, most are as straightforward as they look but a couple warrant a little explanation. Either scroll down to the section of interest or jump straight there via the links below.  

The Servo:Lite Blocks:

Note: These blocks were written specifically for coding for the :MOVE mini buggy, however, if you are using 360 degree continuous rotation servos orientated in the same way as in :MOVE mini then the directional blocks will work in the same way. NOTE: A recent update to the MakeCode Editor included cosmetic changes. The blocks below now look slightly different but the still function in exactly the same way.
1
Allows the setting of the :MOVE mini forward/reverse speed. The allows tuning for the drive forwards and drive backwards x distance commands.
block image
Turns right through the requested degrees and then stops. This needs the calibrate turn speed to x degrees per second tuned to make it accurate, as it uses a simple turn, wait, stop method. It also runs the servos at a slower pace than the right function to reduce wheel slip.
block image
Drives backwards the requested distance and then stops.
block image
Drives forward the requested distance and then stops.
block image
Sends servos to a neutral position. On a well trimmed 360 degrees servo this is stationary, on a normal 180-degree servo this is 90 degrees. This is especially useful for coding servos that will be performing tasks other than driving wheels, for example, a servo that is controlling a steering rack or part of a robot arm.
block image
Stop for 360-degree servos, rather than write 90 as in the ‘goto neutral position’ block, which may or may stop the servo depending on how well trimmed it is. The Stop command literally stops sending pulses to the servo. On a normal servo, this will stop the servo where it is rather than return it to a neutral position, it will also not provide any holding force.
block image
Turns right, call ‘stop’ to stop.
block image
Turns left, call ‘stop’ to stop.
block image
Drives backwards, call ‘stop’ to stop.
block image
Drives forwards, call ‘stop’ to stop.
block image
Allows the setting of the :MOVE mini turn speed. This allows tuning for the turn x degrees command.
block image
Turns through the requested degrees and then stops, needs NumberOfDegreesPerSec tuned make it accurate as it uses a simple turn, wait, stop method. Runs the servos slower than the turn left block to reduce the chance of wheel slip.
  For most applications, ie coding a remote control buggy, the Forwards, Backwards, Turn Right, Turn Left and Stop commands are all that should be required. However, if you are writing code for a drawing robot or a robot arm then you will need to calibrate turn speed and forward speed and use commands such as Turn left x degrees, which offers greater precision.  

The Motor Driver Board Blocks:

NOTE: A recent update to the MakeCode Editor included cosmetic changes. The blocks below now look slightly different but the still function in exactly the same way. These blocks have been specifically designed to make coding the Kitronik Motor Driver Board for the BBC microbit as easy as possible. With the blocks below, you can control the direction and speed of each motor individually and also stop each one.
kitronik-custom-blocks-motor-direction
This block allows you to chose a motor, either one or two, and to instruct it to drive either forwards or backwards at a speed of your choosing. The range of values for speed are between 0 - 100.
kitronik-custom-blocks-motor-turn-off
This block allows you to turn off either motor.
   

The 16 Servo Control Board Blocks:

NOTE: A recent update to the MakeCode Editor included cosmetic changes. The blocks below now look slightly different but the still function in exactly the same way. Our 16 Servo Control Board for the BBC micro:bit allows for much more ambitious projects than are possible with our other motor and servo driver boards. With the single code block below, you can specify which of the 16 servos you wish to control and what angle you wish it to move to.
kitronik-custom-blocks-16-serevo-control-board
This block has a drop-down menu from which you can select any of the 16 servos that this board can control and it has an input area for you to type in the angle you require, from 0 - 180.

8 comments

Mark Donnison

Mark Donnison

Hi, if you contact us at support@kitronik.co.uk we can try to help you with your work.

Ugo

Ugo

Hi, I am on Crowdin with other acquaintances of mine. We are giving a hand to translate MakeCode blocks from English to French. We would like to translate the MotroDriver (2 blocks) and the ServoLite (12 blocks). Where can we find you? On Crowdin? Tks

Mark Donnison

Mark Donnison

Hej. Det är möjligt att kalibrera servon med kod. Det betyder att du inte behöver demontera den. https://www.kitronik.co.uk/blog/calibrating-360-degree-servos-move-mini/

Mark Donnison

Mark Donnison

The page has now been updated with the new blocks and with revised instructions with regard to how to add them. You’ll be pleased to note that they can be added from within the Makecode Editor as opposed to using the Git Hub link.

Mark Donnison

Mark Donnison

Hi Matthew, thanks for the feedback. This is on today's to-do list as we have released some new custom blocks, which requires that we update a few of our resources etc. Thanks again!

Matthew

Matthew

The location of the code blocks you provide did not work, https://github.com/KitronikLtd/MakeCode-kitronik-servo-lite. However I tried https://github.com/KitronikLtd/pxt-kitronik-servo-lite and this did work. You might want to change the link on your web page.

Mark Donnison

Mark Donnison

Hi David, yes they can be used with other servos but you will need to take into account the following info. The code breaks out to P1 & P2 for use with the :MOVE mini kit. The servos will need a separate power supply to the micro:bit. We will be adding more blocks soon that will increase their usefulness for a wider range servo based activities.

David Held

David Held

Can the servo blocks be used without having your servo board?

Leave a comment

All comments are moderated before being published