Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

Small Basic + micro:bit

Discussion in 'Official Microsoft News' started by Ed Price - MSFT, Sep 14, 2017.

Thread Status:
Not open for further replies.
  1. Ed Price - MSFT

    Ed Price - MSFT Guest

    Blog Posts:
    Today is a guest blog post from teacher, Jez Dean...


    In this blog post: Build a computer-to-micro:bit connection with Small Basic.

    You can write a simple GUI to send commands to a micro:bit running Python:


    The program sends Python commands over a serial connection to the micro:bit. I've kept it as simple as possible so you can customize it further.

    Clicking PIN0 High sends the command pin0.write_digital(1) to the micro:bit. You could type display.show(Image.HAPPY) and click Send Command would show a smiley on the micro:bit.


    1. Flash a Python program to the micro:bit. You can just flash an empty program from within mu.
    2. Install the lit dev extensions for Small Basic. These are used to communicate over a serial connection.
    3. Find out the COM port of your microbit.
    4. Add your COM port at the top of the Small Basic code.

    comPort = "COM4"


    While ("True")

    Sub Initialise
    'draw window'
    GraphicsWindow.Width = 500
    GraphicsWindow.Height = 100
    GraphicsWindow.Title = "Small Basic Microbit Controller"

    'draw pin control buttons'
    pin0high = Controls.AddButton("PIN0 High", 20, 10)
    pin0low = Controls.AddButton("PIN0 Low", 100, 10)

    'draw status and command buttons & boxes'
    statusbox = Controls.AddTextBox(20,50)
    value = Controls.AddTextBox(210,13)
    send = Controls.AddButton("Send Command", 380, 10)

    'Open connection to microbit'
    Controls.SetTextBoxText(statusbox,"Status : "+ LDCommPort.OpenPort(comPort, 9600))

    'Assign variables'
    Controls.ButtonClicked = OnButtonClicked
    nl = Text.GetCharacter(10) 'new line character'

    Sub OnButtonClicked
    button = Controls.LastClickedButton
    val = Controls.GetTextBoxText(value)

    'if button pressed, send command and new line character'
    If (button = pin0high) Then
    ElseIf (button = pin0low) Then
    If (button = send) And (val <> "") Then

    Adapted from litdev on the Small Basic blog


    • This is not interactive; it will not return any value the microbit sends.
    • This will only work over USB. Python does not work over Bluetooth.
    See Also

    Other Resources from Jez Dean

    Continue reading...
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software