Arduino being recognized as keyboard by android

纵然是瞬间 提交于 2019-12-13 04:59:59

问题


I wrote a simple firmware for arduino to replicate whatever incoming data it recieves on serial to the serial output. Something like this: int serialData = 0;

void setup()
{
  Serial.begin(9600);  
}

void loop()
{
  if (Serial.available() > 0)
  {
    serialData = Serial.read();
    Serial.println(serialData);
  }  
}

Now I wanted it connect to my Nexus 7 running on Android 4.3 using a microUSB->OTG cable + USB->microUSB cable. I installed a serial monitor app (https://play.google.com/store/apps/details?id=jp.ksksue.app.terminal&hl=en) and was expecting to write serial data over it.

Once I connected this to the tablet I ended up getting a keyboard notification. Android recognizes this connection as keyboard. This collapses the android keyboard as it has detected an external keyboard. however I get an option to paste on the input box. Which seems to work.

Is it possible

  • disable mounting of keyboards in android. Or
  • Making arduino being recognized as something other than keyboard.

回答1:


Edit /usr/share/arduino/hardware/arduino/cores/arduino/USBDesc.h, and comment out the line

#define HID_ENABLED

so that it reads instead:

/* #define HID_ENABLED */

This is part of the code that gets compiled into each sketch to enable USB support, and this change will prevent HID support from being compiled into future sketches. You will need to be root or use sudo in order to write your changes to the file. (Is it necessary to restart the Arduino IDE after making this change? Not sure.) On Windows or OS X, you will need to figure out where Arduino's support files are installed and edit the analogous file.

Keywords: Android soft keyboard disabled while Arduino is connected




回答2:


I think you have a Leonardo, right?

AFAIK you can not disable the KeyboardEmulation but you could try one of the following:

  • Use a USB -> Serial Cable and use the second Serial Port of your Leonardo
  • If you have a rooted Phone, try to disable the USB Keyboarddriver using adb or a Shell Emulator
  • Modify the Arduino Firmware and remove the Emulation Part (If you have another Arduino to reprogram your Leonardo)

I think thats all you can do.




回答3:


A workaround to this problem was to install another keyboard app like Go keyboard or swype. This leads to a notification upon connecting arduinp to the android device, from where you can turn off the external hardware and switch back on screen keyboard. Not persistent but works!



来源:https://stackoverflow.com/questions/19208731/arduino-being-recognized-as-keyboard-by-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!