This example shows how to use the Simulink® Support Package for Android™ Devices to send and receive serial data from Arduino hardware.
In this example, you can exchange data between an Android device and Arduino hardware using a USB cable.
This example uses two Simulink models:
With these models, you can:
Set up a USB serial connection between an Android device and Arduino board
Configure and run Simulink models for Android device and Arduino board
Before you start this example, you must:
Android phone or tablet
Arduino Mega 2560/Mega ADK/Due/Leonardo/MKR1000
USB OTG converter
You can skip this task if you are using the Arduino MKR1000.
In this task, you configure the model for the supported Arduino board.
1. In your Simulink model, open the Modeling tab and press Ctrl+E to open the Configuration Parameters dialog box.
2. Select the Hardware Implementation pane and select your Arduino hardware from the Hardware board parameter list. Do not change any other settings.
3. Click OK.
4. Similarly, configure the model for Android device
Note: Ensure that Baud rate (Hardware Implementation > Hardware board settings > Target Hardware resources > Serial port properties) is the same in both the Android device and the Arduino hardware. Serial communication is not possible if Baud rate is different.
1. Open the Android model.
2. Go to the Hardware tab and click Build, Deploy & Start to run this model on the Android device.
3. Open the Arduino model
4. Go to the Hardware tab and click Build, Deploy & Start to run this model on the Arduino device.
5. Connect the micro-USB end of the USB OTG converter cable to the Android device. Connect the USB OTG converter end to regular USB end of the USB cable. Also connect the micro-USB end of the regular USB cable to the Arduino hardware. You can also connect the USB OTG converter to the Arduino hardware and USB cable to Android device.
Note: For security reasons, whenever an USB device is connected to an Android device, accept the message that appears on the Android screen.
6. On your Arduino hardware, verify if the LED is glowing. This indicates that the Arduino hardware is receiving power from the Android device.
Replace the TCP/IP blocks with serial send receive blocks for serial communication in the Control Brightness of Arduino Onboard LED from Android Device example.
Connect the humidity sensor to the Arduino and, with the help of the Android device monitor the plots.
This example showed you how to:
Power the Arduino board using an Android device and control the application running on an Arduino board from an Android device.
Send serial commands from an Android device to Arduino hardware.