极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 180644|回复: 77

【教程】Android手机通过OTG线连接Arduino,读写串口数据

  [复制链接]
发表于 2012-10-24 17:23:45 | 显示全部楼层 |阅读模式
本帖最后由 ninjiafan 于 2012-10-28 20:30 编辑

因为自己对电子电路是半桶水,复杂的单片机电路把我难倒了,幸好Arduino的出现,让一切都简化了不少。平时和朋友们就喜欢制作一些Arduino的小玩意儿来帮助生活和工作。

因为朋友单位需要采购一些数据采集和云台控制的设备,就定制了些,全是用UNO和Arduino Nano来做的。但是这些设备所在的位置很分散,在城市的周边地区(非常的偏远,甚至是人迹罕见的地方,那是爬山涉水翻山越岭啊)。

而数据采集的调试很麻烦,因为每部设备所在的位置和环境的不同,必须设置不同的参数,值得庆幸的是程序不需要修改了,只修改参数即可。于是我和朋友只需要带手机和外置电池就行了。

言归正传,UNO和Nano的USB串口通信被Android 4.0以上手机支持的,所以通过OTG线连接并使用软件可以直接读取和发送数据。并且Arduino串口波特率必须为9600!
这是我的手机对应的OTG线,有弯头和直头两种,我更喜欢弯头的。对了,提醒一点,OTG线让Android手机为Arduino供电的,所以无需外接电源。



Android手机需要下载谷歌电子市场中的Arduino Uno Communicat:(在谷歌的Play商店下载东西让人放心,不会有木马或者病毒之类的。其他的电子市场就不好说了。)


通过OTG线插入Arduino时会出现提示:


这是插上Arduino后的运行结果:也?回车怎么变成“.”了?


我们现在已经能够查看Arduino串口输出了,但是无法输入,而且回车也变成点了,不好看。不过查看程序工作日志已经够了。

那么我们有没有更好的软件呢?有的!!!
谷歌电子市场下载USB Serial Monitor Lite:


程序主界面


设置菜单,选择Setting


设置界面,有串口和显示设置


串口波特率改为9600


显示可以用默认,也可以自己定制


你需要显示字符、十进制、十六进制?


设置完成后连接好Arduino后,选择Open Device


运行结果:


应坛友要求提取电子市场的USB Serial Monitor Lite,请有条件的坛友测试下。
补充说明:有坛友说无法在电子市场找到,这个问题我觉得是谷歌电子市场分类导致的,可能是手机的系统版本太低无法支持,也可能是手机达不到这个程序的基本硬件需求所以被屏蔽,当然,我说的是谷歌的Play商店,不是第三方电子市场。我的手机是三星的Galaxy Nexus,系统是谷歌原版的Android 4.0.4。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +1 收起 理由
幻生幻灭 + 1 OTG线...Android2.2用户对此表示羡慕

查看全部评分

回复

使用道具 举报

发表于 2012-10-24 17:37:30 | 显示全部楼层
好贴顶一个。。。等线到了就试试,貌似很好玩
回复 支持 1 反对 0

使用道具 举报

发表于 2012-10-24 17:43:39 | 显示全部楼层
这个可以有
呵呵~~~~~~~~~~!
回复 支持 反对

使用道具 举报

发表于 2012-10-24 17:46:44 | 显示全部楼层
{:soso_e142:}
回复 支持 反对

使用道具 举报

发表于 2012-10-24 18:12:16 | 显示全部楼层
以前安卓手机和arduino通过蓝牙通讯,现在看来可以直接用OTG USB线通讯了,赞一个!

贴2段 andriod的代码,供各位参考。

  1. /*
  2. * Copyright (C) 2012 Mathias Jeppsson
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *      [url]http://www.apache.org/licenses/LICENSE-2.0[/url]
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */

  16. package com.primavera.arduino.listener;

  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.Iterator;

  20. import android.app.ListActivity;
  21. import android.app.PendingIntent;
  22. import android.content.BroadcastReceiver;
  23. import android.content.Context;
  24. import android.content.Intent;
  25. import android.content.IntentFilter;
  26. import android.hardware.usb.UsbDevice;
  27. import android.hardware.usb.UsbManager;
  28. import android.os.Bundle;
  29. import android.util.Log;
  30. import android.view.Menu;
  31. import android.view.MenuItem;
  32. import android.view.View;
  33. import android.widget.ArrayAdapter;
  34. import android.widget.ListView;
  35. import android.widget.Toast;

  36. public class ArduinoCommunicatorActivity extends ListActivity {

  37.     private static final int ARDUINO_USB_VENDOR_ID = 0x2341;
  38.     private static final int ARDUINO_UNO_USB_PRODUCT_ID = 0x01;
  39.     private static final int ARDUINO_MEGA_2560_USB_PRODUCT_ID = 0x10;
  40.     private static final int ARDUINO_MEGA_2560_R3_USB_PRODUCT_ID = 0x42;
  41.     private static final int ARDUINO_UNO_R3_USB_PRODUCT_ID = 0x43;

  42.     private final static String TAG = "ArduinoCommunicatorActivity";
  43.     private final static boolean DEBUG = false;
  44.    
  45.     private Boolean mIsReceiving;
  46.     private ArrayList<ByteArray> mTransferedDataList = new ArrayList<ByteArray>();
  47.     private ArrayAdapter<ByteArray> mDataAdapter;

  48.     private void findDevice() {
  49.         UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
  50.         UsbDevice usbDevice = null;
  51.         HashMap<String, UsbDevice> usbDeviceList = usbManager.getDeviceList();
  52.         if (DEBUG) Log.d(TAG, "length: " + usbDeviceList.size());
  53.         Iterator<UsbDevice> deviceIterator = usbDeviceList.values().iterator();
  54.         if (deviceIterator.hasNext()) {
  55.             UsbDevice tempUsbDevice = deviceIterator.next();

  56.             // Print device information. If you think your device should be able
  57.             // to communicate with this app, add it to accepted products below.
  58.             if (DEBUG) Log.d(TAG, "VendorId: " + tempUsbDevice.getVendorId());
  59.             if (DEBUG) Log.d(TAG, "ProductId: " + tempUsbDevice.getProductId());
  60.             if (DEBUG) Log.d(TAG, "DeviceName: " + tempUsbDevice.getDeviceName());
  61.             if (DEBUG) Log.d(TAG, "DeviceId: " + tempUsbDevice.getDeviceId());
  62.             if (DEBUG) Log.d(TAG, "DeviceClass: " + tempUsbDevice.getDeviceClass());
  63.             if (DEBUG) Log.d(TAG, "DeviceSubclass: " + tempUsbDevice.getDeviceSubclass());
  64.             if (DEBUG) Log.d(TAG, "InterfaceCount: " + tempUsbDevice.getInterfaceCount());
  65.             if (DEBUG) Log.d(TAG, "DeviceProtocol: " + tempUsbDevice.getDeviceProtocol());

  66.             if (tempUsbDevice.getVendorId() == ARDUINO_USB_VENDOR_ID) {
  67.                 if (DEBUG) Log.i(TAG, "Arduino device found!");

  68.                 switch (tempUsbDevice.getProductId()) {
  69.                 case ARDUINO_UNO_USB_PRODUCT_ID:
  70.                     Toast.makeText(getBaseContext(), "Arduino Uno " + getString(R.string.found), Toast.LENGTH_SHORT).show();
  71.                     usbDevice = tempUsbDevice;
  72.                     break;
  73.                 case ARDUINO_MEGA_2560_USB_PRODUCT_ID:
  74.                     Toast.makeText(getBaseContext(), "Arduino Mega 2560 " + getString(R.string.found), Toast.LENGTH_SHORT).show();
  75.                     usbDevice = tempUsbDevice;
  76.                     break;
  77.                 case ARDUINO_MEGA_2560_R3_USB_PRODUCT_ID:
  78.                     Toast.makeText(getBaseContext(), "Arduino Mega 2560 R3 " + getString(R.string.found), Toast.LENGTH_SHORT).show();
  79.                     usbDevice = tempUsbDevice;
  80.                     break;
  81.                 case ARDUINO_UNO_R3_USB_PRODUCT_ID:
  82.                     Toast.makeText(getBaseContext(), "Arduino Uno R3 " + getString(R.string.found), Toast.LENGTH_SHORT).show();
  83.                     usbDevice = tempUsbDevice;
  84.                     break;
  85.                 }
  86.             }
  87.         }

  88.         if (usbDevice == null) {
  89.             if (DEBUG) Log.i(TAG, "No device found!");
  90.             Toast.makeText(getBaseContext(), getString(R.string.no_device_found), Toast.LENGTH_LONG).show();
  91.         } else {
  92.             if (DEBUG) Log.i(TAG, "Device found!");
  93.             Intent startIntent = new Intent(getApplicationContext(), ArduinoCommunicatorService.class);
  94.             PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, startIntent, 0);
  95.             usbManager.requestPermission(usbDevice, pendingIntent);
  96.         }
  97.     }

  98.     @Override
  99.     public void onCreate(Bundle savedInstanceState) {
  100.         super.onCreate(savedInstanceState);
  101.         if (DEBUG) Log.d(TAG, "onCreate()");

  102.         IntentFilter filter = new IntentFilter();
  103.         filter.addAction(ArduinoCommunicatorService.DATA_RECEIVED_INTENT);
  104.         filter.addAction(ArduinoCommunicatorService.DATA_SENT_INTERNAL_INTENT);
  105.         registerReceiver(mReceiver, filter);

  106.         mDataAdapter = new ArrayAdapter<ByteArray>(this, android.R.layout.simple_list_item_1, mTransferedDataList);
  107.         setListAdapter(mDataAdapter);

  108.         findDevice();
  109.     }

  110.     @Override
  111.     protected void onListItemClick(ListView l, View v, int position, long id) {
  112.         super.onListItemClick(l, v, position, id);

  113.         if (DEBUG) Log.i(TAG, "onListItemClick() " + position + " " + id);
  114.         ByteArray transferedData = mTransferedDataList.get(position);
  115.         transferedData.toggleCoding();
  116.         mTransferedDataList.set(position, transferedData);
  117.         mDataAdapter.notifyDataSetChanged();
  118.     }

  119.     @Override
  120.     protected void onNewIntent(Intent intent) {
  121.         if (DEBUG) Log.d(TAG, "onNewIntent() " + intent);
  122.         super.onNewIntent(intent);

  123.         if (UsbManager.ACTION_USB_DEVICE_ATTACHED.contains(intent.getAction())) {
  124.             if (DEBUG) Log.d(TAG, "onNewIntent() " + intent);
  125.             findDevice();
  126.         }
  127.     }

  128.     @Override
  129.     protected void onDestroy() {
  130.         if (DEBUG) Log.d(TAG, "onDestroy()");
  131.         super.onDestroy();
  132.         unregisterReceiver(mReceiver);
  133.     }

  134.     @Override
  135.     public boolean onCreateOptionsMenu(Menu menu) {
  136.         getMenuInflater().inflate(R.menu.options, menu);
  137.         return true;
  138.     }

  139.     @Override
  140.     public boolean onOptionsItemSelected(MenuItem item) {
  141.         switch (item.getItemId()) {
  142.         case R.id.help:
  143.             startActivity(new Intent(this, Help.class));
  144.             return true;
  145.         default:
  146.             return super.onOptionsItemSelected(item);
  147.         }
  148.     }

  149.     BroadcastReceiver mReceiver = new BroadcastReceiver() {

  150.         private void handleTransferedData(Intent intent, boolean receiving) {
  151.             if (mIsReceiving == null || mIsReceiving != receiving) {
  152.                 mIsReceiving = receiving;
  153.                 mTransferedDataList.add(new ByteArray());
  154.             }

  155.             final byte[] newTransferedData = intent.getByteArrayExtra(ArduinoCommunicatorService.DATA_EXTRA);
  156.             if (DEBUG) Log.i(TAG, "data: " + newTransferedData.length + " "" + new String(newTransferedData) + """);

  157.             ByteArray transferedData = mTransferedDataList.get(mTransferedDataList.size() - 1);
  158.             transferedData.add(newTransferedData);
  159.             mTransferedDataList.set(mTransferedDataList.size() - 1, transferedData);
  160.             mDataAdapter.notifyDataSetChanged();
  161.         }

  162.         @Override
  163.         public void onReceive(Context context, Intent intent) {
  164.             final String action = intent.getAction();
  165.             if (DEBUG) Log.d(TAG, "onReceive() " + action);

  166.             if (ArduinoCommunicatorService.DATA_RECEIVED_INTENT.equals(action)) {
  167.                 handleTransferedData(intent, true);
  168.             } else if (ArduinoCommunicatorService.DATA_SENT_INTERNAL_INTENT.equals(action)) {
  169.                 handleTransferedData(intent, false);
  170.             }
  171.         }
  172.     };
  173. }
复制代码



  1. /*
  2. * Copyright (C) 2012 Mathias Jeppsson
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *      [url]http://www.apache.org/licenses/LICENSE-2.0[/url]
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */

  16. package com.primavera.arduino.listener;

  17. import android.app.Service;
  18. import android.content.BroadcastReceiver;
  19. import android.content.Context;
  20. import android.content.Intent;
  21. import android.content.IntentFilter;
  22. import android.hardware.usb.UsbConstants;
  23. import android.hardware.usb.UsbDevice;
  24. import android.hardware.usb.UsbDeviceConnection;
  25. import android.hardware.usb.UsbEndpoint;
  26. import android.hardware.usb.UsbInterface;
  27. import android.hardware.usb.UsbManager;
  28. import android.os.Handler;
  29. import android.os.IBinder;
  30. import android.os.Looper;
  31. import android.os.Message;
  32. import android.util.Log;
  33. import android.widget.Toast;

  34. public class ArduinoCommunicatorService extends Service {

  35.     private final static String TAG = "ArduinoCommunicatorService";
  36.     private final static boolean DEBUG = false;

  37.     private boolean mIsRunning = false;
  38.     private SenderThread mSenderThread;

  39.     private volatile UsbDevice mUsbDevice = null;
  40.     private volatile UsbDeviceConnection mUsbConnection = null;
  41.     private volatile UsbEndpoint mInUsbEndpoint = null;
  42.     private volatile UsbEndpoint mOutUsbEndpoint = null;

  43.     final static String DATA_RECEIVED_INTENT = "primavera.arduino.intent.action.DATA_RECEIVED";
  44.     final static String SEND_DATA_INTENT = "primavera.arduino.intent.action.SEND_DATA";
  45.     final static String DATA_SENT_INTERNAL_INTENT = "primavera.arduino.internal.intent.action.DATA_SENT";
  46.     final static String DATA_EXTRA = "primavera.arduino.intent.extra.DATA";

  47.     @Override
  48.     public IBinder onBind(Intent arg0) {
  49.         return null;
  50.     }

  51.     @Override
  52.     public void onCreate() {
  53.         if (DEBUG) Log.d(TAG, "onCreate()");
  54.         super.onCreate();
  55.         IntentFilter filter = new IntentFilter();
  56.         filter.addAction(SEND_DATA_INTENT);
  57.         filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
  58.         registerReceiver(mReceiver, filter);
  59.     }

  60.     @Override
  61.     public int onStartCommand(Intent intent, int flags, int startId) {
  62.         if (DEBUG) Log.d(TAG, "onStartCommand() " + intent + " " + flags + " " + startId);

  63.         if (mIsRunning) {
  64.             if (DEBUG) Log.i(TAG, "Service already running.");
  65.             return Service.START_REDELIVER_INTENT;
  66.         }

  67.         mIsRunning = true;

  68.         if (!intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
  69.             if (DEBUG) Log.i(TAG, "Permission denied");
  70.             Toast.makeText(getBaseContext(), getString(R.string.permission_denied), Toast.LENGTH_LONG).show();
  71.             stopSelf();
  72.             return Service.START_REDELIVER_INTENT;
  73.         }

  74.         if (DEBUG) Log.d(TAG, "Permission granted");
  75.         mUsbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
  76.         if (!initDevice()) {
  77.             if (DEBUG) Log.e(TAG, "Init of device failed!");
  78.             stopSelf();
  79.             return Service.START_REDELIVER_INTENT;
  80.         }

  81.         if (DEBUG) Log.i(TAG, "Receiving!");
  82.         Toast.makeText(getBaseContext(), getString(R.string.receiving), Toast.LENGTH_SHORT).show();
  83.         startReceiverThread();
  84.         startSenderThread();

  85.         return Service.START_REDELIVER_INTENT;
  86.     }

  87.     @Override
  88.     public void onDestroy() {
  89.         if (DEBUG) Log.i(TAG, "onDestroy()");
  90.         super.onDestroy();
  91.         unregisterReceiver(mReceiver);
  92.         mUsbDevice = null;
  93.         if (mUsbConnection != null) {
  94.             mUsbConnection.close();
  95.         }
  96.     }

  97.     private byte[] getLineEncoding(int baudRate) {
  98.         final byte[] lineEncodingRequest = { (byte) 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08 };
  99.         switch (baudRate) {
  100.         case 14400:
  101.             lineEncodingRequest[0] = 0x40;
  102.             lineEncodingRequest[1] = 0x38;
  103.             break;

  104.         case 19200:
  105.             lineEncodingRequest[0] = 0x00;
  106.             lineEncodingRequest[1] = 0x4B;
  107.             break;
  108.         }

  109.         return lineEncodingRequest;
  110.     }

  111.     private boolean initDevice() {
  112.         UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
  113.         mUsbConnection = usbManager.openDevice(mUsbDevice);
  114.         if (mUsbConnection == null) {
  115.             if (DEBUG) Log.e(TAG, "Opening USB device failed!");
  116.             Toast.makeText(getBaseContext(), getString(R.string.opening_device_failed), Toast.LENGTH_LONG).show();
  117.             return false;
  118.         }
  119.         UsbInterface usbInterface = mUsbDevice.getInterface(1);
  120.         if (!mUsbConnection.claimInterface(usbInterface, true)) {
  121.             if (DEBUG) Log.e(TAG, "Claiming interface failed!");
  122.             Toast.makeText(getBaseContext(), getString(R.string.claimning_interface_failed), Toast.LENGTH_LONG).show();
  123.             mUsbConnection.close();
  124.             return false;
  125.         }

  126.         // Arduino USB serial converter setup
  127.         // Set control line state
  128.         mUsbConnection.controlTransfer(0x21, 0x22, 0, 0, null, 0, 0);
  129.         // Set line encoding.
  130.         mUsbConnection.controlTransfer(0x21, 0x20, 0, 0, getLineEncoding(9600), 7, 0);

  131.         for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
  132.             if (usbInterface.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
  133.                 if (usbInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN) {
  134.                     mInUsbEndpoint = usbInterface.getEndpoint(i);
  135.                 } else if (usbInterface.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_OUT) {
  136.                     mOutUsbEndpoint = usbInterface.getEndpoint(i);
  137.                 }
  138.             }
  139.         }

  140.         if (mInUsbEndpoint == null) {
  141.             if (DEBUG) Log.e(TAG, "No in endpoint found!");
  142.             Toast.makeText(getBaseContext(), getString(R.string.no_in_endpoint_found), Toast.LENGTH_LONG).show();
  143.             mUsbConnection.close();
  144.             return false;
  145.         }

  146.         if (mOutUsbEndpoint == null) {
  147.             if (DEBUG) Log.e(TAG, "No out endpoint found!");
  148.             Toast.makeText(getBaseContext(), getString(R.string.no_out_endpoint_found), Toast.LENGTH_LONG).show();
  149.             mUsbConnection.close();
  150.             return false;
  151.         }

  152.         return true;
  153.     }

  154.     BroadcastReceiver mReceiver = new BroadcastReceiver() {
  155.         @Override
  156.         public void onReceive(Context context, Intent intent) {
  157.             final String action = intent.getAction();
  158.             if (DEBUG) Log.d(TAG, "onReceive() " + action);

  159.             if (SEND_DATA_INTENT.equals(action)) {
  160.                 final byte[] dataToSend = intent.getByteArrayExtra(DATA_EXTRA);
  161.                 if (dataToSend == null) {
  162.                     if (DEBUG) Log.i(TAG, "No " + DATA_EXTRA + " extra in intent!");
  163.                     String text = String.format(getResources().getString(R.string.no_extra_in_intent), DATA_EXTRA);
  164.                     Toast.makeText(context, text, Toast.LENGTH_LONG).show();
  165.                     return;
  166.                 }

  167.                 mSenderThread.mHandler.obtainMessage(10, dataToSend).sendToTarget();
  168.             } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
  169.                 Toast.makeText(context, getString(R.string.device_detaches), Toast.LENGTH_LONG).show();
  170.                 mSenderThread.mHandler.sendEmptyMessage(11);
  171.                 stopSelf();
  172.             }
  173.         }
  174.     };

  175.     private void startReceiverThread() {
  176.         new Thread("arduino_receiver") {
  177.             public void run() {
  178.                 byte[] inBuffer = new byte[4096];
  179.                 while(mUsbDevice != null ) {
  180.                     if (DEBUG) Log.d(TAG, "calling bulkTransfer() in");
  181.                     final int len = mUsbConnection.bulkTransfer(mInUsbEndpoint, inBuffer, inBuffer.length, 0);
  182.                     if (len > 0) {
  183.                         Intent intent = new Intent(DATA_RECEIVED_INTENT);
  184.                         byte[] buffer = new byte[len];
  185.                         System.arraycopy(inBuffer, 0, buffer, 0, len);
  186.                         intent.putExtra(DATA_EXTRA, buffer);
  187.                         sendBroadcast(intent);
  188.                     } else {
  189.                         if (DEBUG) Log.i(TAG, "zero data read!");
  190.                     }
  191.                 }

  192.                 if (DEBUG) Log.d(TAG, "receiver thread stopped.");
  193.             }
  194.         }.start();
  195.     }

  196.     private void startSenderThread() {
  197.         mSenderThread = new SenderThread("arduino_sender");
  198.         mSenderThread.start();
  199.     }

  200.     private class SenderThread extends Thread {
  201.         public Handler mHandler;

  202.         public SenderThread(String string) {
  203.             super(string);
  204.         }

  205.         public void run() {

  206.             Looper.prepare();

  207.             mHandler = new Handler() {
  208.                 public void handleMessage(Message msg) {
  209.                     if (DEBUG) Log.i(TAG, "handleMessage() " + msg.what);
  210.                     if (msg.what == 10) {
  211.                         final byte[] dataToSend = (byte[]) msg.obj;

  212.                         if (DEBUG) Log.d(TAG, "calling bulkTransfer() out");
  213.                         final int len = mUsbConnection.bulkTransfer(mOutUsbEndpoint, dataToSend, dataToSend.length, 0);
  214.                         if (DEBUG) Log.d(TAG, len + " of " + dataToSend.length + " sent.");
  215.                         Intent sendIntent = new Intent(DATA_SENT_INTERNAL_INTENT);
  216.                         sendIntent.putExtra(DATA_EXTRA, dataToSend);
  217.                         sendBroadcast(sendIntent);
  218.                     } else if (msg.what == 11) {
  219.                         Looper.myLooper().quit();
  220.                     }
  221.                 }
  222.             };

  223.             Looper.loop();
  224.             if (DEBUG) Log.i(TAG, "sender thread stopped");
  225.         }
  226.     }
  227. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2012-10-24 18:40:53 | 显示全部楼层
小辣椒。。。
回复 支持 反对

使用道具 举报

发表于 2012-10-24 22:00:54 | 显示全部楼层
OTG线,请问对安卓手机有限制吗?版本、型号等。。。被ADK弄怕了
回复 支持 反对

使用道具 举报

发表于 2012-10-24 22:13:35 | 显示全部楼层
2.3版的手机怕刷机有风险。对此只能羡慕!
回复 支持 反对

使用道具 举报

发表于 2012-10-24 23:59:33 | 显示全部楼层
其实可以集思广益,如果OTG支持(ARDUINO这类模块应该是被USB转COM口的),那么用蓝牙模块+arduino 应该也可以被安卓支持吧?毕竟蓝牙也会虚拟出一个COM口貌似。
哇卡卡 ,楼主 你打开了一个巨大的宝藏啊,我等有福了,不需要安卓4了
回复 支持 反对

使用道具 举报

发表于 2012-10-25 00:05:01 | 显示全部楼层
好文章啊 谢谢楼主
回复 支持 反对

使用道具 举报

发表于 2012-10-25 01:20:59 | 显示全部楼层
能用手机编译、下载,那就好了
回复 支持 反对

使用道具 举报

发表于 2012-10-25 06:14:26 | 显示全部楼层
能够支持OTG的手机实在太少了,大多数手机应该是取不到电。若可行请给出手机型号版本或刷机办法。
回复 支持 反对

使用道具 举报

发表于 2012-10-25 06:39:25 | 显示全部楼层
gaoshine 发表于 2012-10-24 18:12
以前安卓手机和arduino通过蓝牙通讯,现在看来可以直接用OTG USB线通讯了,赞一个!

贴2段 andriod的代 ...

要是使用OTG连接是不是需要在手机上安装驱动啊?!
回复 支持 反对

使用道具 举报

发表于 2012-10-25 09:58:46 | 显示全部楼层
AdmiralSoft 发表于 2012-10-25 06:39
要是使用OTG连接是不是需要在手机上安装驱动啊?!

理论上不用,OTG其实就是相当于让手机拥有电脑一样的USB口,可以接键盘、鼠标等等
安卓底层还是linux的,就如同arduino uno 接入 linux无需驱动一样,手机应该也不需要驱动(树莓派就是个例子啊)
回复 支持 反对

使用道具 举报

发表于 2012-10-25 22:14:18 | 显示全部楼层
蓝牙确实很早就有,但是你这个软件可以直接用安卓手机直接连接ARDUINO板。进行通讯和改数据成为可能。(甚至可能直接进行编程,因为LINUX内核的安卓手机貌似应该能支持LINUX版的ARDUINO编辑器。。。太强大了)
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-19 22:21 , Processed in 0.049217 second(s), 33 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表