Skip to content

About

PyoBot micro:bit robot board extension for MakeCode

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

25 Commits

Folders and files

Repository files navigation

PyoBot

PyoBot

PyoBot is a micro:bit robot car board extension for Microsoft MakeCode. Control motors, line sensors, ultrasonic sensor, LEDs, buzzer, and servo with simple blocks.

Add to MakeCode

  1. Open https://makecode.microbit.org
  2. Create or open a project
  3. Click Extensions
  4. Paste this URL: https://github.com/pyocodingcompany-crypto/pyobot-makecode

Product Page

Purchase & Inquiry

For purchase, bulk orders, or classroom use inquiries:

Tutorials and Resources

API Reference

~hint

Hardware Required

This extension requires a PyoBot robot car board connected to a BBC micro:bit. Motor, line sensor, ultrasonic and LED blocks automatically disable the micro:bit LED matrix due to shared pin usage (P3, P4, P6, P7, P9, P10).

~

Motors

Run motors forward or backward at a given speed (0–1023).

// Run both motors forward at speed 500
pyobot.motorRun(PyoMotor.Both, PyoDirection.Forward, 500)

// Run left motor backward at speed 300
pyobot.motorRun(PyoMotor.Left, PyoDirection.Backward, 300)

// Stop all motors
pyobot.motorStop(PyoMotor.Both)

Turn by stopping one side and driving the other.

// Turn left at speed 500
pyobot.motorTurn(PyoTurn.Left, 500)

// Turn right at speed 500
pyobot.motorTurn(PyoTurn.Right, 500)

Line Sensor

Read line sensor values. Returns 0 for white surface, 1 for black line.

// Read raw value
let val = pyobot.lineSensor(PyoLineSensor.Left)

// Boolean: is black line detected?
if (pyobot.lineDetected(PyoLineSensor.Left)) {
    pyobot.motorRun(PyoMotor.Left, PyoDirection.Forward, 1023)
}

// Boolean: is black line NOT detected?
if (pyobot.lineNotDetected(PyoLineSensor.Right)) {
    pyobot.motorStop(PyoMotor.Right)
}

Line tracing example:

basic.forever(function () {
    if (pyobot.lineDetected(PyoLineSensor.Left)) {
        pyobot.motorRun(PyoMotor.Left, PyoDirection.Forward, 1023)
    } else {
        pyobot.motorStop(PyoMotor.Left)
    }
    if (pyobot.lineDetected(PyoLineSensor.Right)) {
        pyobot.motorRun(PyoMotor.Right, PyoDirection.Forward, 1023)
    } else {
        pyobot.motorStop(PyoMotor.Right)
    }
})

Ultrasonic

Measure distance in centimeters using the ultrasonic sensor (P1 trig, P10 echo).

// Show distance on LED matrix
let dist = pyobot.ultrasonic()
basic.showNumber(dist)

Obstacle avoidance example:

basic.forever(function () {
    if (pyobot.ultrasonic() < 15) {
        pyobot.motorStop(PyoMotor.Both)
        pyobot.motorTurn(PyoTurn.Right, 500)
        basic.pause(500)
    } else {
        pyobot.motorRun(PyoMotor.Both, PyoDirection.Forward, 500)
    }
})

LED

Control left (P3) and right (P4) LEDs on the board.

// Turn on both LEDs
pyobot.pyoLed(PyoLED.Both, PyoLEDState.On)

// Turn off left LED
pyobot.pyoLed(PyoLED.Left, PyoLEDState.Off)

Buzzer

Play tones on the buzzer (P0). Frequency in Hz, duration in ms.

// Play middle C for 500ms
pyobot.buzzer(262, 500)

// Stop buzzer
pyobot.buzzerOff()

Servo

Control a servo motor on P2. Angle range: 0–180 degrees.

// Set servo to 90 degrees
pyobot.servo(90)

// Release servo (stop PWM signal)
pyobot.servoRelease()

Pin Map

Function Pin
LED Left / Right P3 / P4
Buzzer P0
Line Sensor Left / Right P6 / P7
Ultrasonic Trig / Echo P1 / P10
Motor Left (PWM, Dir) P8, P9, P13
Motor Right (PWM, Dir) P16, P14, P15
Servo P2
I2C (SCL / SDA) P19 / P20

Note: Motor, line sensor, ultrasonic and LED blocks disable the micro:bit LED matrix because P3, P4, P6, P7, P9, P10 are shared with the LED display. Use an I2C OLED display if you need a screen alongside these blocks.

Use with HuskyLens

PyoBot works alongside HuskyLens over I2C (P19/P20). No pin conflict.

Testing

See test.ts for a complete test suite. Press buttons A, B, or A+B on the micro:bit to run different test groups.

License

MIT

Supported targets

  • for PXT/microbit

Metadata

<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>

About

PyoBot micro:bit robot board extension for MakeCode

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages