Main Content

Scope Block with Android Devices

This example shows how to plot real-time data on an Android® device by using the Simulink® Scope block with Simulink Support Package for Android Devices.

Introduction

Android devices provide a user interface and a set of built-in sensors. The Scope block displays signals generated during simulation in real-time.

By displaying the scope on an Android device screen, you can:

  • Display signals in real-time.

  • View signals without a connection to your development computer.

  • Customize the scope style to suit your app.

This example provides two Simulink models:

  • androidscopesim: The scope displays the roll and pitch signals from a simulated accelerometer.

  • androidscopeaccel: The scope displays the roll and pitch of your Android device extracted from the accelerometer.

Prerequisites

Required Hardware

  • Android device

  • USB cable to connect the device to your development computer

Task 1 - Display Signals During Simulation

Simulate the accelerometer signal as if the device is rotating around the Y-axis.

1. Open the androidscopesim Simulink model. The model simulates a device rotating between -45 and +45 degrees around the Y-axis.

2. Double-click the Scope block to open the Scope window.

3. Double-click the Calculate roll and pitch MATLAB Function block to see the equations that determine the roll and pitch.

4. On the Simulation tab of the Simulink model, click Run to see the simulated roll and pitch signals.

Task 2 - Display Signals on Your Android Device

Using the model from Task 1, display the simulated roll and pitch signals on your Android device.

1. Open the androidscopesim Simulink model.

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

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

4. Click Device options and ensure that the device matches your device setting. 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 to build, download, and run the model on your device.

The app displays the simulated roll and pitch signals on your device screen.

Task 3 - Display Signals from Android Device Accelerometer

Using the Accelerometer block, display the roll and pitch of your Android device on the device screen.

1. Open the androidscopeaccel Simulink model. This model replaces the Simulate accelerometer block from the model in Task 2 with the Accelerometer block from the Android Block Library.

2. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Monitor & Tune.

3. Rotate the device around the Y-axis to see the roll and pitch displayed on your device screen.

The app plots the roll and pitch of your Android device extracted from the Accelerometer.

Task 4 - Customize Scope Style on Your Android Device

Using the model from Task 3, configure the appearance and style of the Scope displayed on your Android device.

1. Open the androidscopeaccel Simulink model.

2. Double-click the Scope block to open the Scope window.

3. In the Scope menu, click View > Style to open the Style dialog.

3. Set the Figure color to gray.

4. Modify the Axes colors. Set the Axes background color to white. Set the Ticks, labels, and grid colors to gray.

5. Set Properties for line to Channel 1. Set Line width to 1.5 and Line color to blue.

6. Set Properties for line to Channel 2. Set Line width to 1.5 and Line color to red.

7. Click OK.

8. To see the style changes reflected in the app, you must remove the previous project. In the MATLAB® Command Window, run:

rmdir('androidscopeaccel_ert_rtw', 's');

9. On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Monitor & Tune.

The Scope in the app reflects the new line and axes properties from the Style dialog of the Scope block.

Other Things to Try

  • Display the roll and pitch on separate scopes.

  • Change the scope style to suit your app.

  • Modify the model to display signals from other sensors.

  • Modify the model to display signals from remote sources using UDP Send or TCP/IP Receive blocks.