This extension contains blocks for most 2 wheeled robots available for the micro:bit. This library is compatible with micro:bit V1 and V2.
- 4tronix MiniBit
- DFRobot Maqueen
- DFRobot Maqueen Plus
- Elecfreaks Cutebot
- Elecfreaks Cutebot PRO
- InkSmith K8
- KeyStudio KS0426 Mini Smart Robot
- KittenBot MiniLFR
- KittenBot Robotbit
- KittenBot Nanobit
- Yahboom Tiny:bit
The firmware is designed for popular rover robots found in the micro:bit ecosystem (and more can be added):
- 2 motors that can be forward, backward, left, right turns. Precise detection of distance is not needed.
- 2 or more line sensors
- a distance sensor, typically an ultrasonic sensor
The following features are found often but are optional:
- RGB LEDs
- Buzzer
- Programmable LED strip
- Open https://makecode.microbit.org
- Add this extension to your project by adding url https://github.com/microsoft/microbit-robot
The extension uses the 5x5 screen to show the state of the robot (you can turn off this behavior see configuration). This is particularly useful to debug your robot program.
- left and right LED column show the line detector state
- center column shows the obstacle distance in multiple of 5cm
- 2nd and 4th column show the motor throttle
At the start of any robot program, you need add the block to select the robot model you will be using.
This should be done before using any other blocks.
robot.elecfreaksCuteBot.start()
This is the only code that is specific to the robot you are using. The rest of the blocks are the same for all robots.
- move
input.onButtonPressed(Button.A, () => {
robot.motorRun(0, 100)
})
The move block takes a steering`` and
speedparameters. The
steeringcontrols how much "turn",
speed` controls the throttle on the motors.
- stop the robot
input.onButtonPressed(Button.B, () => {
robot.motorStop()
})
- open the claw/arm
input.onButtonPressed(Button.B, () => {
robot.armOpen(50)
})
- set LED and headlights color
input.onButtonPressed(Button.A, function () {
robot.setColor(0xff0000)
})
- play tone
input.onButtonPressed(Button.A, function () {
robot.playTone(262, music.beat(BeatFraction.Whole))
})
- detect when an obstacle is changing and read the current distance (in cm)
let dist = 0
robot.onObstacleChanged(function () {
dist = robot.obstacleDistance()
})
- detect line changes or read line state
let left = false
robot.onLineDetected(RobotLineState.Left, function () {
left = robot.detectLines(RobotLineState.Left)
})
- turn off robot screen
robot.setDisplay(false)
- configure the motor drift
robot.setMotorDrift(10)
- disable or enable line assist
robot.setLineAssist(false)
Use micro:code to remote control a robot using this library.
- for PXT/microbit
- for PXT/calliope
MIT
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
To add a new robot to the list, prepare a pull request in microsoft/microbit-robot with:
- a new class extending
Robot
and configuring the hardware (see other robots) - a global field instance instantiating the robot (see other robots)
- a URL in the jsdocs of the class pointing to the robot homepage
- add
main{company}{productname}.ts
file that starts the robot - add
pxt-{company}{productname}.json
file that overrides the test files to loadmain{company}{productname}.ts
- add call to
mkc -c pxt-{company}{productname}.json
in.github/workflows/makecode.yml
- add image under
assets
Make sure to test and tune the configuration options in the robot class for your particular chassis/motor/line detectors. You may want to tweak some of the constants in the robot class to optimize the behavior of the robot.
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.
<script src="https://makecode.com/gh-pages-embed.js"></script><script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script