This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Set Up and Connect to Android Device

Connect to Android Device

You can use MATLAB® on a computer or on the MathWorks Cloud. The following sections outline the connection procedure for each scenario.

Use MATLAB on a Computer

Before you can acquire sensor data from the Android Sensors screen in MATLAB Mobile™ on your device, you need to set up MATLAB on your computer to communicate with MATLAB Mobile. You only need to do this once for the computer that will be communicating with the Android™ device.

If you have not already done so, download and install the MATLAB Support Package for Android Sensors on your computer, and MATLAB Mobile on your Android device. See Get Started with Android Sensors for complete setup steps.

This example shows how to set up using MATLAB on a computer, and assumes that your computer and device are on the same wireless network. (For information on alternative configurations, see the MATLAB Mobile documentation.) Follow these steps to connect your computer and the Android device.

  1. Use MATLAB Connector™ to set up the connection between your computer running MATLAB and the MATLAB Mobile application on your Android device. This example assumes that your computer and device are on the same wireless network. (For information on alternative configurations, see the MATLAB Mobile documentation.) Enter the following in MATLAB:

    connector('on', 'password', 'mypassword');

    Specify your own password in the last argument.

    You don’t need to specify a port here since you should always use the default port. To check which port the connector is using, start the connector and look at the URL it displays for the test link.

  2. In the MATLAB Command Window, click on the test link displayed along with the DNS name and IP address of the computer to ensure that the computer is ready to connect.

  3. In the MATLAB Mobile application on your device, select the option Connect to Your Computer. If you previously connected to the cloud or a different computer, use the Settings screen and tap Add a Computer.

  4. In the Computer setting, enter the DNS name or IP address that was displayed in step 2.

  5. In the Connector Password and Port settings, enter the password and port that you previously specified in step 1.

  6. Save your settings and start the connection by tapping the Connect button at the top of the screen.

  7. Once this initial setup is complete, the only thing you have to do in subsequent MATLAB sessions with the same computer is to start the connection on the computer and the device.

    In MATLAB, enter connector on.

    On the MATLAB Mobile Settings > Computer screen on the device, tap Connect.

  8. You can now create your mobiledev object and start acquiring data, as described in Acquire Sensor Data Streaming.

Note

If you are using Wi-Fi as your connection method, the Wi-Fi on your device may have a sleep setting that you should adjust.

Note

If you turn off MATLAB Connector after you have created a mobiledev object, the object will not be able to receive data from the device, even if the Connector is turned on again. You have to create another mobiledev object in this case.

Use MATLAB on the MathWorks Cloud

Alternatively, you can use MATLAB on the MathWorks Cloud instead of a computer. The support package is already installed in the MathWorks Cloud. If you use MathWorks Cloud, connect to the Cloud in Settings.

  1. In MATLAB Mobile on your device, go to Settings > Connect to MathWorks Cloud.

  2. Tap MathWorks Account.

  3. Enter your credentials on the MathWorks Account screen and tap Log In.

  4. You can now create your mobiledev object and start acquiring data, as described in Acquire Sensor Data Streaming.

Android Sensors Settings in MATLAB Mobile

The sensor settings on the device are on the Settings screen of MATLAB Mobile. To access them, tap the Menu button, then Settings, and then scroll to the Sensors section.

  • Control from MATLAB — this is on by default and needs to remain on in order to control the sensors and logging of data from MATLAB.

  • Send Data in Background — this is off by default, but turn it on if you want to continue to send sensor data when the application goes into the background on the device.

  • Getting Started with Sensors — use to access the Getting Started information.

Note

If you are using Wi-Fi as your connection method, the Wi-Fi on your device may have a sleep setting that you should adjust.

Sensors Screen in MATLAB Mobile

To open the Sensors screen in MATLAB Mobile, tap Sensors on the menu.

Turn the five sensors on and off using their icons at the top of the screen.

The sensor buttons display in this order across the top of the screen, and show these measurements:

  • Acceleration — the three data points are the acceleration reading in X, Y, and Z coordinates, in m/s2 (meters per second squared).

  • Magnetic Field — the three data points are the magnetic field reading in X, Y, and Z coordinates, in microtesla.

  • Orientation — the three data points are the position reading in X, Y, and Z coordinates, in degrees, for azimuth, pitch, and roll.

  • Angular Velocity — the three data points are the angular velocity reading in X, Y, and Z rotations, in radians per second.

  • Position — data points representing latitude, longitude, speed, course, altitude, and horizontal accuracy. Position data is obtained from GPS, Wi-Fi, or the cellular network, using whichever is available. The measurements are:

    Latitude in degrees relative to the equator, with positive values indicating latitudes north of the equator.

    Longitude in degrees relative to the zero meridian, with positive values extending east of the meridian.

    Speed in meters per second.

    Course in degrees relative to true north.

    Altitude in meters above sea level.

    Horizontal Accuracy in meters defined by a circle around the latitude and longitude.

When you tap a sensor, the measurement readings begin and are displayed below the buttons in the order in which you select the sensors. In this example, Acceleration and Orientation have been selected.

After you have selected any sensors, use the Start button to send the data to MATLAB on your computer. You can also start the transmission of data from MATLAB programmatically using the Logging property. You can stop the transmission using the Stop button on the device, or the Logging property in MATLAB.