Main Content

Getting Started with Android Devices

This example shows you how to use Simulink® Support Package for Android® Devices to run a Simulink model on an Android device.

Introduction

Simulink Support Package for Android Devices enables you to create and run Simulink models on Android devices. The support package includes a library of Simulink blocks for using Android device sensors and network interfaces.

In this example, you learn how to create and run a simple Simulink model on an Android device.

When you have completed this example, try these other examples:

Prerequisites

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

Required Hardware

  • Android device, configured using androidhwsetup

  • USB cable to connect the device to host computer

Task 1 - Review Android Block Library

Simulink Support Package for Android Devices provides blocks that you can use to work with device sensors and network interfaces.

1. Enter slLibraryBrowser at the MATLAB® prompt. This opens the Simulink Library Browser.

2. In the Simulink Library Browser, navigate to Simulink Support Package for Android Devices.

3. Double-click the Camera block. Review the block mask, which contains a description of the block, a list of 'Resolution', a 'Refresh' button, and a 'Sample time' parameter.

Task 2 - Create Simulink Model for Android Devices

In this task, you will create a simple Simulink model that observes the images captured by the device camera.

1. In MATLAB, select HOME > New > Simulink Model.

2. Drag the Camera block from Android Devices library to the model.

3. Drag the Video Display block from Android Devices library to the model.

4. Connect each output of the Camera block to the corresponding input of the Video Display block.

5. Save your model. A preconfigured Simulink model is included for your convenience.

Task 3 - Configure and Run Simulink Model on Android Devices

In this task, you will configure and run your model on a Android device.

1. Connect an Android device to your computer with a USB cable.

2. If you did not enable USB debugging on the device when you installed the support package, enter androidhwsetup in the MATLAB Command Window and follow the instructions to update the device settings.

3. On the Modeling tab of the toolstrip, select Model Settings.

4. In the Configuration Parameters dialog box, select the Hardware Implementation pane and select Android Device from the Hardware board parameter list. Click OK.

5. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start.

6. An app is built, downloaded and run on your device. The app displays the camera image on the device screen.

7. Save your model. A pre-configured androidGettingStartedExample model is included for your convenience.

Other Things to Try

  • In the Camera block mask, click Refresh to query the connected device for a list of supported resolutions.

  • Deploy the model with different camera resolutions by updating the Resolution parameter list in the Camera block mask.