Main Content

Getting Started with Simulink Coder Support Package for BeagleBone Blue Hardware

This example shows you how to use Simulink® Coder™ Support Package for BeagleBone® Blue Hardware to run a Simulink model on a BeagleBone Blue hardware.

Copyright(C) 2017-2023 The MathWorks, Inc.

Introduction

The Simulink Support Package for BeagleBone Blue Hardware provides a set of predefined blocks. These blocks include algorithms that you can use to configure peripherals on the BeagleBone Blue hardware. In this example, you will learn how to create a Simulink model that blinks the green LED on Beaglebone Blue.

Prerequisites

If you are new to Simulink, we recommend completing the Interactive Simulink Tutorial, Get Started with Simulink documentation, and Simulink Getting Started video.

Required Hardware

  • BeagleBone Blue board

  • Micro USB cable

Task 1: Create a Model

A sample model is available at Getting Started with BeagleBone Blue Support Package Model for you to use. You can either click the link and save the model on your computer, or perform these steps to create the model:

1. In the MATLAB® Command Window, enter simulink.

2. On the Simulink Start Page, click the Blank Model template.

3. On the Simulink model toolbar, click the Library Browser button.

4. From the Simulink Library Browser dialog box, add these blocks to your model:

a. Pulse Generator: Select Simulink > Sources. In the right pane, right-click the Pulse Generator block, and select Add block to model untitled.

b. Data Type Conversion: Select Simulink > Signal Attributes. In the right pane, right-click the Data Type Conversion block, and select Add block to model untitled.

c. LED: Select Simulink > Simulink Coder Support Package for BeagleBone Blue Hardware. In the right pane, right-click the LED block, and select Add block to model untitled.

5. Connect the blocks as shown in the image and save the model.

Task 2: Configure the Block Parameters

If you are using the sample model, skip this task.

1. In the Simulink model, double-click the Pulse Generator block. In the Block Parameters dialog box:

a. From the Pulse type list, select Sample based.

b. In the Sample time box, enter 0.1.

c. Click OK.

2. Double-click the LED block. In the Block Parameters dialog box, from the LED list, select Green and click OK.

Task 3: Connect BeagleBone Blue to the Computer

1. Connect the micro USB cable into the micro USB port of the hardware.

2. Connect the other end of the cable to your computer. Wait for the power LED on the hardware to start blinking and become stable.

Task 4: Configure the Simulink Model

A pre-configured sample model is available at beagleboneblue_gettingstarted for you to use.

You can either click the link and save the model on your computer, or perform these steps to configure the model:

1. To configure the model, click the Model Configuration Parameters button on the Simulink toolbar.

2. In the Configurations Parameters dialog box, select Hardware Implementation.

3. From the Hardware board list, select BeagleBone Blue. This selection automatically populates the parameters in Hardware board settings with the default values for the BeagleBone Blue hardware.

4. Under Target Hardware Resources, select Board Parameters.

5. Verify the values for the Device Address, Username, and Password parameters. The default values are 192.168.7.2, debian, and temppwd, respectively. Change the values as required and click OK.

Task 5: Run the Model on the Hardware

1. To run the model on the BeagleBone Blue hardware, click the Deploy to Hardware button on the toolbar.

The green LED on the hardware starts blinking once per second. If the LED does not blink, analyze the log result, as described in the Analyze the Log Result section.

2. To verify that the model is running on the BeagleBone Blue hardware, enter these commands in the MATLAB Command Window:

bbblue = beagleboneblue;
isModelRunning(bbblue,'beagleboneblue_gettingstarted');

bbblue is an object that represents the BeagleBone Blue hardware. For more information on the beagleboneblue function, see beagleboneblue.

beagleboneblue_gettingstarted is the name of your Simulink model. This command returns true if the model is running on the BeagleBone Blue hardware.

Task 6: Stop and Rerun the Model

1. In the MATLAB Command Window, create a connection from the MATLAB software to the Beaglebone Blue hardware.

bbblue = beagleboneblue;

bbblue is an object that represents the BeagleBone Blue hardware. For more information on the beagleboneblue function, see beagleboneblue.

2. To stop the model running on the hardware, use this command:

stopModel(bbblue,'beagleboneblue_gettingstarted');

beagleboneblue_gettingstarted is the name of your Simulink model.

The green LED on the BeagleBone Blue hardware stops blinking. If the LED does not stop blinking, analyze the log result, as described in the Analyze the Log Result section.

3. To verify if the model has stopped running on the hardware, use this command.

isModelRunning(bbblue,'beagleboneblue_gettingstarted');

This command returns false if the model has stopped running on the BeagleBone Blue hardware.

4. To rerun the stopped model, use this command:

runModel(bbblue,'beagleboneblue_gettingstarted');

The model starts running on the hardware, and the LED starts blinking again. If the LED does not start blinking, analyze the log result, as described in the Analyze the Log Result section.

Task 7: Analyze the Log Result

The output of the model running on the BeagleBone Blue hardware is redirected to a log file. In case of unexpected results when running your model on the hardware, analyze the diagnostic messages in the log file. To see the contents of the log file for the beagleboneblue_gettingstarted model, use this command in the MATLAB Command Window:

system(bbblue,'cat beagleboneblue_gettingstarted.log');

You can import the log file to your computer by using this command in the MATLAB Command Window.

getFile(bbblue,'beagleboneblue_gettingstarted.log');

The getFile command saves the log file to your current MATLAB directory.