Genuino 101 to control keyboard? [Solved but Contentions]

Discussion in 'UDOO X86' started by Ryan Lewkowicz, Aug 5, 2017.

  1. Ryan Lewkowicz

    Ryan Lewkowicz New Member

    Joined:
    Aug 4, 2017
    Messages:
    19
    Likes Received:
    8
  2. FirstGenGeek

    FirstGenGeek Member

    Joined:
    May 25, 2016
    Messages:
    66
    Likes Received:
    26
    Only Arduino boards using an ATmega32u4 microcontroller (Leonardo and Micro), and to some extent the Due and Zero, support a mouse and keyboard. The Arduino 101 MC does not.

    This is an article that describes how to use buttons to simulate keyboard-like functions with non-32u4 Arduinos that may help you: http://mitchtech.net/arduino-usb-hid-keyboard/ . This is a complex process, so proceed at your own risk.
     
    Last edited: Aug 5, 2017
  3. Ryan Lewkowicz

    Ryan Lewkowicz New Member

    Joined:
    Aug 4, 2017
    Messages:
    19
    Likes Received:
    8
    Man. That seems like massive oversight. I can still do some serial port monitoring or something like that, but that's rough. I should have done my homework better, but you'd think an embedded controller, could, well... control.
     
  4. FirstGenGeek

    FirstGenGeek Member

    Joined:
    May 25, 2016
    Messages:
    66
    Likes Received:
    26
    To be clear, this limitation is the result of the Arduino (Genuion) microcontroller spec., and not UDOO's implementation of the 101.
     
    Markus Laire likes this.
  5. Ryan Lewkowicz

    Ryan Lewkowicz New Member

    Joined:
    Aug 4, 2017
    Messages:
    19
    Likes Received:
    8
    Oh yea, I know. I wasn't trying to say nothing bad. I'm sure I can find a module or something too that I can connect. Now I just wish another one of those boards were integrated, but I imagine it's some sort of partnership.
     
  6. Toley

    Toley New Member

    Joined:
    Apr 27, 2016
    Messages:
    10
    Likes Received:
    3
  7. FirstGenGeek

    FirstGenGeek Member

    Joined:
    May 25, 2016
    Messages:
    66
    Likes Received:
    26
  8. Ryan Lewkowicz

    Ryan Lewkowicz New Member

    Joined:
    Aug 4, 2017
    Messages:
    19
    Likes Received:
    8
    I think I'm just going to code up a serial interface to run key presses. I been looking for a simple golang project to start on. Just something to get my feet wet. I think this will be perfect. I have a capacitive touch shield hooked up and what I'll do is just have the serial port spit out a letter which I can assign to a pin. There's already go libraries out there for reading serial input so it will be real simple just to have it read and then press whatever key the serial output says. Then I can just put out a simple executable that runs anywhere and then anyone can use it no fuss.
     
  9. Ryan Lewkowicz

    Ryan Lewkowicz New Member

    Joined:
    Aug 4, 2017
    Messages:
    19
    Likes Received:
    8
    [Solved but contentions]

    So I made it work, but I'm fairly astounded at how non trivial this was. I tried going the golang route, and it's very possible I was just overloading the buffer (which I resolved later, but the bash solution works nicely so I didn't bother checking), but It wasn't working like I needed it to. I was going to upload the file, but the forum won't let me. Regardless, I just used bash.

    First you need xdotool:
    Code:
    apt install xdotool
    
    Then you run this in a script:

    Code:
    stty -F /dev/ttyACM0 raw
    stty -F /dev/ttyACM0 -echo
    while read -rs -n 1 c
    do
      xdotool keydown key $c
    done < /dev/ttyACM0
    This is my sketch for the MPR121:

    Code:
    #include <Adafruit_MPR121.h>
    #include <Wire.h>
    
    
    // You can have up to 4 on one i2c bus but one is enough for testing!
    Adafruit_MPR121 cap = Adafruit_MPR121();
    
    // Keeps track of the last pins touched
    // so we know when buttons are 'released'
    uint16_t lasttouched = 0;
    uint16_t currtouched = 0;
    
    void setup() {
      Serial.begin(9600);
    
      while (!Serial) { // needed to keep leonardo/micro from starting too fast!
        delay(10);
      }
     
      Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
     
      // Default address is 0x5A, if tied to 3.3V its 0x5B
      // If tied to SDA its 0x5C and if SCL then 0x5D
      if (!cap.begin(0x5A)) {
        Serial.println("MPR121 not found, check wiring?");
        while (1);
      }
      Serial.println("MPR121 found!");
    }
    
    void loop() {
      // Get the currently touched pads
      currtouched = cap.touched();
    
      char doot[13] = "abcdefghijkl";
     
      for (uint8_t i=0; i<12; i++) {
        // it if *is* touched and *wasnt* touched before, alert!
        if ((currtouched & _BV(i))) {
          Serial.println(doot[i]);
          delay(100);
        }
      }
    }
    I'm actually very frustrated that a simple library for this is not provided. There's this:
    https://github.com/mo10/Curie-bluetooth-HID-library

    But I guess I don't feel like I should have to dig around in an undocumented library to use features I would expect out of the box. Had I known there was no outbound HID support (I'm not certain the shield would provide that support going outbound, or at the least in a trivial manner), I would have just bought a nuc and a more appropriate micro controller (the internet says I'm far from the first to make this mistake). This isn't on udoo, but if they have a partnership, and any modicum of leverage they should lean on the native provider to add a well maintained functional library
     
    FirstGenGeek likes this.
  10. FirstGenGeek

    FirstGenGeek Member

    Joined:
    May 25, 2016
    Messages:
    66
    Likes Received:
    26

Share This Page