├── AndroidManifest.xml ├── README.md ├── ant.properties ├── arduino-serial.iml ├── build.xml ├── gen └── com │ └── example │ └── arduino_serial │ ├── BuildConfig.java │ ├── Manifest.java │ └── R.java ├── libs └── usb-serial-for-android-v010 (1).jar ├── out └── production │ └── arduino-serial │ ├── arduino-serial.apk │ ├── arduino-serial.unaligned.apk │ └── com │ └── example │ └── arduino_serial │ ├── ArduinoSerial$1$1.class │ ├── ArduinoSerial$1.class │ ├── ArduinoSerial.class │ ├── BuildConfig.class │ ├── R$attr.class │ ├── R$id.class │ ├── R$layout.class │ ├── R$string.class │ ├── R$xml.class │ └── R.class ├── proguard.cfg ├── project.properties ├── res ├── layout │ └── main.xml ├── values │ └── strings.xml └── xml │ └── device_filter.xml └── src └── com └── example └── arduino_serial └── ArduinoSerial.java /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | android-arduino-usb-serial 2 | ========================== 3 | 4 | A basic Android application to read serial input from an Arduino that is connected over USB (via a USB on-the-go cable on Android 3.1+). -------------------------------------------------------------------------------- /ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked in Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /arduino-serial.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 40 | 41 | 42 | 43 | 47 | 48 | 49 | 51 | 63 | 64 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /gen/com/example/arduino_serial/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | /** Automatically generated file. DO NOT MODIFY */ 4 | package com.example.arduino_serial; 5 | 6 | public final class BuildConfig { 7 | public final static boolean DEBUG = true; 8 | } -------------------------------------------------------------------------------- /gen/com/example/arduino_serial/Manifest.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.example.arduino_serial; 4 | 5 | /* This stub is for using by IDE only. It is NOT the Manifest class actually packed into APK */ 6 | public final class Manifest { 7 | } -------------------------------------------------------------------------------- /gen/com/example/arduino_serial/R.java: -------------------------------------------------------------------------------- 1 | /*___Generated_by_IDEA___*/ 2 | 3 | package com.example.arduino_serial; 4 | 5 | /* This stub is for using by IDE only. It is NOT the R class actually packed into APK */ 6 | public final class R { 7 | } -------------------------------------------------------------------------------- /libs/usb-serial-for-android-v010 (1).jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/libs/usb-serial-for-android-v010 (1).jar -------------------------------------------------------------------------------- /out/production/arduino-serial/arduino-serial.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/arduino-serial.apk -------------------------------------------------------------------------------- /out/production/arduino-serial/arduino-serial.unaligned.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/arduino-serial.unaligned.apk -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/ArduinoSerial$1$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/ArduinoSerial$1$1.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/ArduinoSerial$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/ArduinoSerial$1.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/ArduinoSerial.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/ArduinoSerial.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/BuildConfig.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/R$attr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/R$attr.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/R$id.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/R$id.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/R$layout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/R$layout.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/R$string.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/R$string.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/R$xml.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/R$xml.class -------------------------------------------------------------------------------- /out/production/arduino-serial/com/example/arduino_serial/R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtbaker/android-arduino-usb-serial/eec14df4d04620b9c27b01dd1925ea042461d620/out/production/arduino-serial/com/example/arduino_serial/R.class -------------------------------------------------------------------------------- /proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-17 12 | -------------------------------------------------------------------------------- /res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 17 | 18 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World, DemoActivity! 5 | arduino serial 6 | 7 | -------------------------------------------------------------------------------- /res/xml/device_filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/com/example/arduino_serial/ArduinoSerial.java: -------------------------------------------------------------------------------- 1 | package com.example.arduino_serial; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | 7 | import android.app.Activity; 8 | import android.content.Context; 9 | import android.hardware.usb.UsbManager; 10 | import android.os.Bundle; 11 | import android.os.Environment; 12 | import android.util.Log; 13 | import android.widget.ScrollView; 14 | import android.widget.TextView; 15 | 16 | import com.hoho.android.usbserial.driver.UsbSerialDriver; 17 | import com.hoho.android.usbserial.driver.UsbSerialProber; 18 | import com.hoho.android.usbserial.util.HexDump; 19 | import com.hoho.android.usbserial.util.SerialInputOutputManager; 20 | 21 | import java.io.BufferedWriter; 22 | import java.io.File; 23 | import java.io.FileWriter; 24 | import java.io.IOException; 25 | import java.util.concurrent.ExecutorService; 26 | import java.util.concurrent.Executors; 27 | 28 | /** 29 | * A sample Activity demonstrating USB-Serial support. 30 | * 31 | * @author mike wakerly (opensource@hoho.com) 32 | */ 33 | public class ArduinoSerial extends Activity { 34 | 35 | private final String TAG = ArduinoSerial.class.getSimpleName(); 36 | 37 | /** 38 | * The device currently in use, or {@code null}. 39 | */ 40 | private UsbSerialDriver mSerialDevice; 41 | 42 | /** 43 | * The system's USB service. 44 | */ 45 | private UsbManager mUsbManager; 46 | 47 | private TextView mTitleTextView; 48 | private TextView mDumpTextView; 49 | private ScrollView mScrollView; 50 | 51 | private final ExecutorService mExecutor = Executors.newSingleThreadExecutor(); 52 | 53 | private SerialInputOutputManager mSerialIoManager; 54 | 55 | private final SerialInputOutputManager.Listener mListener = 56 | new SerialInputOutputManager.Listener() { 57 | 58 | @Override 59 | public void onRunError(Exception e) { 60 | Log.d(TAG, "Runner stopped."); 61 | } 62 | 63 | @Override 64 | public void onNewData(final byte[] data) { 65 | ArduinoSerial.this.runOnUiThread(new Runnable() { 66 | @Override 67 | public void run() { 68 | ArduinoSerial.this.updateReceivedData(data); 69 | } 70 | }); 71 | } 72 | }; 73 | 74 | @Override 75 | public void onCreate(Bundle savedInstanceState) { 76 | super.onCreate(savedInstanceState); 77 | setContentView(R.layout.main); 78 | mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); 79 | mTitleTextView = (TextView) findViewById(R.id.demoTitle); 80 | mDumpTextView = (TextView) findViewById(R.id.demoText); 81 | mScrollView = (ScrollView) findViewById(R.id.demoScroller); 82 | } 83 | 84 | @Override 85 | protected void onPause() { 86 | super.onPause(); 87 | stopIoManager(); 88 | if (mSerialDevice != null) { 89 | try { 90 | mSerialDevice.close(); 91 | } catch (IOException e) { 92 | // Ignore. 93 | } 94 | mSerialDevice = null; 95 | } 96 | } 97 | 98 | @Override 99 | protected void onResume() { 100 | super.onResume(); 101 | mSerialDevice = UsbSerialProber.acquire(mUsbManager); 102 | Log.d(TAG, "Resumed, mSerialDevice=" + mSerialDevice); 103 | if (mSerialDevice == null) { 104 | mTitleTextView.setText("No serial device."); 105 | } else { 106 | try { 107 | mSerialDevice.open(); 108 | } catch (IOException e) { 109 | Log.e(TAG, "Error setting up device: " + e.getMessage(), e); 110 | mTitleTextView.setText("Error opening device: " + e.getMessage()); 111 | try { 112 | mSerialDevice.close(); 113 | } catch (IOException e2) { 114 | // Ignore. 115 | } 116 | mSerialDevice = null; 117 | return; 118 | } 119 | mTitleTextView.setText("Serial device: " + mSerialDevice); 120 | } 121 | onDeviceStateChange(); 122 | } 123 | 124 | private void stopIoManager() { 125 | if (mSerialIoManager != null) { 126 | Log.i(TAG, "Stopping io manager .."); 127 | mSerialIoManager.stop(); 128 | mSerialIoManager = null; 129 | } 130 | } 131 | 132 | private void startIoManager() { 133 | if (mSerialDevice != null) { 134 | Log.i(TAG, "Starting io manager .."); 135 | mSerialIoManager = new SerialInputOutputManager(mSerialDevice, mListener); 136 | mExecutor.submit(mSerialIoManager); 137 | } 138 | } 139 | 140 | private void onDeviceStateChange() { 141 | stopIoManager(); 142 | startIoManager(); 143 | } 144 | 145 | private void updateReceivedData(byte[] data) { 146 | final String message = "Read " + data.length + " bytes: \n" 147 | + HexDump.dumpHexString(data) + "\n\n"; 148 | appendLog(HexDump.dumpHexString(data)); 149 | mDumpTextView.append(message); 150 | mScrollView.smoothScrollTo(0, mDumpTextView.getBottom()); 151 | } 152 | 153 | public void appendLog(String text) 154 | { 155 | File path = Environment.getExternalStoragePublicDirectory( 156 | Environment.DIRECTORY_DOWNLOADS); 157 | File logFile = new File(path, "arduino-serial.log"); 158 | 159 | if (!logFile.exists()) 160 | { 161 | try 162 | { 163 | logFile.createNewFile(); 164 | } 165 | catch (IOException e) 166 | { 167 | e.printStackTrace(); 168 | } 169 | } 170 | try 171 | { 172 | //BufferedWriter for performance, true to set append to file flag 173 | BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 174 | buf.append(text); 175 | buf.newLine(); 176 | buf.flush(); 177 | buf.close(); 178 | } 179 | catch (IOException e) 180 | { 181 | e.printStackTrace(); 182 | } 183 | } 184 | 185 | } --------------------------------------------------------------------------------