1

We are using a teensy 2.0 on an Android 4.4 or Android 5.x device. We want the teensy to emulate a keyboard.

When a push-button is pressed a small letter should be send. After releasing a button, a capital letter should be send.

We have used teensyduino to write the necessary code. It's super simple to do like:

    Keyboard.print(char('A'));
    ....
    Keyboard.print(char('a'));
    ....

Somehow on windows machines it works fine, on Android, we see that the "keys" got jammed and a letter is send multiple times or it's even stuck in a loop.

When using the C code example (like shown here https://www.pjrc.com/teensy/usb_keyboard.html) it works on Android.

Any ideas what could cause this problem? Seems like the USB library when using teensyduino is different.

Any guidance is appreciated.

Chris
  • 2,296
  • 4
  • 27
  • 46
  • It would help if you provided the full extent of your source code.. also, what do you think `Keyboard.print(char('A' + channel));` should do? – Patrick Trentin Feb 18 '17 at 16:40
  • @PatrickTrentin I've edited my post, you can reproduce it with these lines of code. There is no setup required, you can find the full code here: http://pastebin.com/2bVwg6QC It does a lot more, like reading A/D. Once a certain threshold is exceeded, it should print via keyboard. – Chris Feb 18 '17 at 16:53
  • Ok, more than enough. Now the next piece of useful information would be *given the same Arduino output*, what is what you see on *Windows* and what is what you see on *Android*: *could you provide precise examples?*. What code do you use to read the output on *Android*? – Patrick Trentin Feb 18 '17 at 17:21
  • The teensy acts like a regular HID keyboard. The keypresses that we send from the teensy are percieved by Windows/Android as regular keypresses from a keyboard. For testing we open any texteditor and play with the connected inputs on the teensy. We have 7 sensors connected to the teensy. When a sensor is activated, a character "is pressed" Channel A sends an a, Channel B a b etc. When you deactivate the sensor, again a character is send. This time a capital letter. So A,B,.. etc. When we test all the sensors we should recevied an output on Windows/Android like this : aAbBcCdDeEfFgG. – Chris Feb 18 '17 at 17:29
  • on Windows this works fine, on Android it's like aBBccccDefg so it's not getting all keypresses and sometimes it's stuck and we get aAbBBBBBBBBBBBBBBBBB... indefinetly – Chris Feb 18 '17 at 17:30
  • Thanks for the explanation, it confirmed what I understood from the source code. What I am suggesting is that if the *Arduino* code works for Windows then it must necessarily work for *Android*, unless the *Android* library implementation is *buggy* or there are other *OS differences*. That is why I suggested adding the code you use on *Android* to receive the data: to try narrow down the problem and identify it. – Patrick Trentin Feb 18 '17 at 19:15
  • Thanks @PatrickTrentin for taking the time to understand the issue! Thing is, there is no code that receives data on Android. You can take the URL field of the chrome browser, you can select any form of input field in any Android application to test this. It's seems as if there is a very small bug in the teensy / USB HID library that causes this. Timinig issue or something else. Thing is, sending a capital letter, requires to send two keycodes. One for CAP and one for the key. This might cause the problem – Chris Feb 18 '17 at 19:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136043/discussion-between-chris-and-patrick-trentin). – Chris Feb 18 '17 at 19:25

0 Answers0