microbit

Connect to BBC micro:bit hardware

Description

example

obj = microbit connects to the BBC micro:bit board. If there is more than one board connected to the computer, this command connects to the first board detected by the operating system.

example

obj = microbit(port) connects to the BBC micro:bit board on the specified serial port.

While creating the microbit object, MATLAB connects to a server running on the BBC micro:bit through serial port. A server needs to be loaded only once in a BBC micro:bit. Multiple BBC micro:bits, with server loaded, can be connected to the host computer and the corresponding objects can be created by specifying the serial port numbers.

Examples

collapse all

Autodetect and connect to a BBC micro:bit board.

m = microbit
m = 
  microbit with properties:

                  Port: "COM4"
  AvailableDigitalPins: ["P0-P16"]
      AvailablePWMPins: ["P0-P10", "P12-P16"]
   AvailableAnalogPins: ["P0-P4", "P10"] 
    AvailableI2CBusIDs: 1
    AvailableSPIBusIDs: 1
Show all properties, functions, latest values

The properties of the microbit object shows information about the connected BBC micro:bit and the status of some of the hardware peripherals available:

  • Port – The port used for serial communication

  • AvailableDigitalPins, AvailableAnalogPins, AvailablePWMPins – The pins that you can use for digital, analog and PWM I/O operations

  • AvailableI2CBusIDs and AvailableSPIBusIDs – The I2C bus and SPI channels that can be used to communicate with sensors and actuators supporting the I2C and SPI communication protocols

  • Click the link all properties to view an additional property called AvaliablePins

  • Click the link functions to view all the interfaces to access peripherals

  • Click the link latest values to view the current acceleration in ㎨ and the current magnetic field in µTesla, in a timetable

Connect to a BBC micro:bit connected to the COM4 port.

m = microbit('COM4')
m = 
  microbit with properties:

                  Port: "COM4"
  AvailableDigitalPins: ["P0-P16", "P19-P20"]
      AvailablePWMPins: ["P0-P16", "P19-P20"]
   AvailableAnalogPins: ["P0-P4", "P10-P10"]
    AvailableI2CBusIDs: 1
    AvailableSPIBusIDs: 1

Connect to two BBC micro:bits connected to the COM5 and COM16 ports.:

m1 = microbit('COM5');
m2 = microbit('COM16');

Note

If the server is not already available in the BBC micro:bit, a server will be created and uploaded into hardware. However, while loading the server, only one BBC micro:bit must be connected to the host computer.

Input Arguments

collapse all

Hardware port, specified as a character vector or string.

Example: a = microbit('COM4')

Output Arguments

collapse all

BBC micro:bit hardware connection, returned as a microbit object.

Introduced in R2017b