Getting Started with Simulink Coder Support Package for BBC micro:bit
This example shows you how to use Simulink® Coder™ Support Package for BBC micro:bit to run a Simulink® model on a BBC micro:bit.
Introduction
Simulink Coder Support Package for BBC micro:bit enables you to create and run Simulink models on a BBC micro:bit. The support package includes a library of Simulink blocks for configuring and accessing BBC micro:bit peripherals and communication interfaces.
In this example you learn how to configure a simple Simulink model to generate code for BBC micro:bit and run the generated code on the board.
Prerequisites
If you are new to Simulink, complete the Interactive Simulink Tutorial.
If you are new to Simulink Coder, visit the Simulink Coder product page for an overview and tutorials.
Required Hardware
To run this example you need this hardware:
BBC micro:bit
USB type A to Mini-B cable

Task 1 - Connect a BBC micro:bit to Host Machine
Connect the BBC micro:bit to your development machine.
1. Plug in a Mini USB cable from a USB port on the development machine to the USB connector on the BBC micro:bit. The BBC micro:bit comes with the mass-storage device (MSD) Flash Programmer OpenSDA Application preinstalled.
2. Before using the BBC micro:bit, install the mbed Serial Driver (see Download and Install mbed Windows Serial Port Driver).
The device appears as a removable storage drive with a volume label of BBC micro:bit.

Task 2 - Review BBC micro:bit Support Package Block Library
1. Open the Library Browser and navigate to Simulink Coder Support Package for BBC micro:bit.
2. In the LED Library, double-click the 5x5 LED Matrix block. Review the block mask, which contains a description of the block and block inputs for the associated 5x5 LED Matrix.

Task 3 - Create a Model for BBC micro:bit
Create a Simulink model that sets the image on the 5x5 LED Matrix.
1. In MATLAB, select HOME > New > Simulink Model. Under Simulink, select Blank Model > Create Model.
2. From the BBC micro:bit block library, add a 5x5 LED Matrix block to the model.
3. Add a Constant block to the model. Set the value of Constant block to a 5x5 Matrix pattern. For example, for the letter "X" pattern, set the value to [ 1 0 0 0 1;0 1 0 1 0;0 0 1 0 0;0 1 0 1 0;1 0 0 0 1]
4. Connect the Constant block to the input of 5x5 LED Matrix block.
Task 4 - Configure and Run the Model on BBC micro:bit
Configure and run the model on the BBC micro:bit.
1. Connect the BBC micro:bit to your development computer with a USB cable.
2. In the Simulink model window, on the Modeling tab, click Model Settings.

3. When the Configuration Parameters dialog box opens, navigate to the Hardware Implementation pane.
Set the Hardware board parameter to
BBC micro:bit.On the Target Hardware Resources pane, Set the Build action to
Build, load and runto automatically download the generated binary file on to the connected BBC micro:bit.
4. Navigate to the Solver pane and set the Solver parameter to discrete (no continuous states).
5. Click OK.
6. In Simulink model window, on the Hardware tab, click Build, Deploy & Start. The model is deployed to the BBC micro:bit.

7. Observe that the input pattern is displayed in the 5x5 LED Matrix.
8. Save your model.
Other Things to Try with RGB LED Block
Create and run a model that displays different Smiley patterns.
Create and run a model that can blink the pattern (use other Simulink blocks also).
Summary
This example introduced the workflow for creating an algorithm from a Simulink model and then running it on BBC micro:bit. In this example you learned that Simulink Coder Support Package for BBC micro:bit provides blocks for configuring, reading from, and writing to BBC micro:bit peripherals.