Approved content
The content below is provided by a partner.
Nexus:bit is a powerful BBC micro:bit multiple-purpose extension board made by Taiwan Coding Education Association. You can program Nexus:bit by using only standard MakeCode blocks plus third party PCA9685/Sonar extensions; however this extension/package provides various functions which are more powerful and easier to use.
In the MakeCode editor go to Advanced -> +Extension… and enter “nexusbit”, “nexusbot or “TCEA” into the serach box. Press enter and you’ll be able to import it. (Depending on Internet status you might need to wait for a bit. Another way is to copy/paste the extension url https://github.com/alankrantas/pxt-Nexusbit into the search box.)
Check out our webpage for more information:
NexusBot assembly/calibration/basic control manual - English
Nexus:bit user manual - English
The onboard PCA9685 chip has the I2C address of 0x40 (64).
NexusBot is an Otto-like 8-dof biped robot powered by micro:bit and Nexus:bit. This extension comes with basic control blocks for this robot.
The robot can also be refitted into a small 2WD car, using 2 DC motors in servo bodies with wheels attached. We use the DC motors since they are easier to control.
NexusBot was inspired by another robot Otto. You can download our NexusBot of 3D printable files. Gather all the off the shelf parts that you’ll need for this assembly.
One major function of this extension is to control servos by relative degrees, or vectors from their default position. This allows users to define and repeat more precise servo movements after simple calibrations. The extension also constrains servos’ target position to be within 0-180 degrees, or whatever range the user defined.
Example:
nexusbit.servoConfig(
1,
80,
30,
150,
5
)
nexusbit.servosToDefl()
basic.forever(function () {
nexusbit.servoDeltaFromDefl(1, -60)
basic.pause(1000)
nexusbit.servoDeltaFromDefl(1, 60)
basic.pause(1000)
})
The default position of Servo 1 (on PCA9685) is set to 80 degrees with min and max degrees as 30 and 150. In the loop the servo would be turned to -60 (20) and +60 (140) degrees from its default position. However, due to the min constraint of 30 the servo would only be allowed to turn to 30 degrees.
The following code demostrates how to gradually (slowly, smoothly) turn 4 servos of a Otto-like biped robot (first two servos are legs, last two are feet):
basic.forever(function () {
nexusbit.servosSlowTurnDeltaFromDefl(
[null, null, 40, 15],
0
)
nexusbit.servosSlowTurnDeltaFromDefl(
[20, 20, null, null],
0
)
nexusbit.servosSlowTurnDeltaFromDefl(
[null, null, -15, -40],
0
)
nexusbit.servosSlowTurnDeltaFromDefl(
[-20, -20, null, null],
0
)
})
The servo turning direction may be different on different robot configurations.
It can also be used like this, using while() loops which you can stop/break out whenever you want:
basic.forever(function () {
while (nexusbit.servoSlowTurnDeltaFromDeflAndCheck([null, null, 40, 15])) {
}
while (nexusbit.servoSlowTurnDeltaFromDeflAndCheck([20, 20, null, null])) {
}
while (nexusbit.servoSlowTurnDeltaFromDeflAndCheck([null, null, -15, -40])) {
}
while (nexusbit.servoSlowTurnDeltaFromDeflAndCheck([-20, -20, null, null])) {
}
})
In the NexusBot section some of the leg movements are already implemented, so you can simply use
basic.forever(function () {
nexusbot.robot_walk(botWalk.forward)
})
It is not recommended to gradually turn more than 4 servos at the same time, since this would slow down all servos’ turning speed.
To calibrate the robot, use the calibration block in the NexusBot section without any changes and flash the code onto your micro:bit.
nexusbot.robotCalibrate(
0,
0,
0,
0,
0,
0,
15,
-15,
true
)
Power up the robot and all servos should be turned to default position (90 degrees for legs and feet, 0 or 180 degrees for arms and hands). Adjust each servo’s installed position so that the robot stands more or less straight, with both hands pointing to the ground.
Now calibrate all servos’ default position (plus or minus degrees) in the MakeCode editor, until legs are straight, feet are flat on the ground and hands are pointed directly downward. Save the .hex file in your computer for future use.
See the NexusBot assembly manual for more details.
nexusbit.servosToDegree([90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90])
input.onButtonPressed(Button.A, function () {
nexusbit.servosToDegree([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
if (Math.randomBoolean()) {
music.beginMelody(music.builtInMelody(Melodies.PowerUp), MelodyOptions.Once)
} else {
music.beginMelody(music.builtInMelody(Melodies.PowerDown), MelodyOptions.Once)
}
})
input.onButtonPressed(Button.B, function () {
nexusbit.servosToDegree([180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180])
nexusbit.vibrator(512, 500)
nexusbit.vibrator(128, 500)
})
basic.forever(function () {
if (nexusbit.micTriggered()) {
basic.showIcon(IconNames.Yes, 100)
} else {
basic.clearScreen()
}
if (nexusbit.joystickToDir(joystickDir.forward)) {
nexusbit.rgbLedPreset(colorType.white, 100)
nexusbit.DC(dcMotor.P15_16, 100)
} else if (nexusbit.joystickToDir(joystickDir.backward)) {
nexusbit.rgbLedPreset(colorType.blue, 100)
nexusbit.DC(dcMotor.P15_16, -100)
} else if (nexusbit.joystickToDir(joystickDir.left)) {
nexusbit.rgbLedPreset(colorType.red, 100)
nexusbit.DC(dcMotor.P13_14, 100)
} else if (nexusbit.joystickToDir(joystickDir.right)) {
nexusbit.rgbLedPreset(colorType.green, 100)
nexusbit.DC(dcMotor.P13_14, -100)
} else {
nexusbit.rgbLedPreset(colorType.off, 100)
nexusbit.DC(dcMotor.P13_14, 0)
nexusbit.DC(dcMotor.P15_16, 0)
}
})
Joseph of Taiwan Coding Education Association
Email: joseph@beyond-coding.org.tw
This extension is also appliable to Thunder:bit V2/V1 expansion boards made by TCEA (you’ll need to select the board type). Thunder:bits are similar to Nexus:bit, except they are larger (more suitable for maker projects), have no microphone and only have 8 (V2) or 4 (V1) PCA9685 servo pins. V2 version has a buzzer jumper as well.
MIT
Nexusbit=github:beyond-coding-tw/pxt-nexusbot#v0.0.2