Main Content

Accept Input from Android Keyboard

This example shows how to accept input values from the Android™ keyboard and convert it to a logical output using Simulink® Support Package for Android Devices.

Introduction

In this example, the Simulink modelandroidConvertTempExample, represents the equation that converts temperatures in Celsius to Fahrenheit:

F= (CX 9 / 5) + 32

This model has aData Inputblock,Celsius, and aData Displayblock,Fahrenheit. TheCelsiusblock generates aCelsiusfield on your Android device screen to accept input from the keyboard. This value is passed to theMultiplyblock, which performs the operation (CX 9 / 5). TheAdd块增加了先前计算的结果and the constant value of32. This final result is displayed in theFahrenheitfield on your Android device.

Prerequisites

Before you start with the example, we recommend you complete:

Required Hardware

  • Android device

  • USB cable

Step 1: Configure Data Input Block

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

2.Install the Simulink Support Package for Android Devices as described inInstall Support for Android Devices. If you have already installed the support package, skip this step.

3.Open theandroidConvertTempExamplemodel.

4.In the Simulink model, double-click theCelsiusblock and verify these parameter values in the Block Parameters dialog box.

Parameter | Value --------------------------------------- Character Vector Input | off Initial Value | 1.0 Data Type | double Sample Time | 0.1

5.ClickOK.

Step 2: Configure the Simulink Model

1.On theModelingtab of the toolstrip, selectModel Settings.

2.In the Configuration Parameters dialog box, selectHardware Implementation.

3.Set theHardware boardparameter toAndroid Device. This selection automatically populates the parameters in theHardware board settingswith the default values for Android.

4.From theGroupslist underTarget hardware resources, selectDevice options.

5.From theDevicelist, select your Android device. If your device is not listed, clickRefresh.

Note: If your device is not listed even after clicking theRefreshbutton, ensure that you have enabled theUSB debuggingoption on your device. To enableUSB debugging, enterandroidhwsetupin the MATLAB® Command Window and follow the onscreen instructions.

6.ClickApply. ClickOKto close the dialog box.

Step 3: Deploy Simulink Model on Android Device

1.On theHardwaretab of the Simulink model, in theModesection, selectRun on boardand then clickBuild, Deploy & Start. The Simulink model is loaded and the application starts running on your device. The application creates aCelsiusfield and aFahrenheitfield on your device.

2.Enter a value in theCelsiusfield and press the tick button on your Android keyboard. The model algorithm converts the value specified in theCelsiusfield and displays the output in theFahrenheitfield.