Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: How to get Teensy to send HID commands, controlled by another board?

  1. #1
    Junior Member
    Join Date
    Jun 2019
    Posts
    3

    How to get Teensy to send HID commands, controlled by another board?

    Hello all. This is my first post.

    I am trying to get the Jetson Nano (another IoT board running Ubuntu) to send HID signals out using a Teensy. The basic idea is this: (1) Python script on Nano --> (2) Teensy --> (3) a computer being controlled.

    I'm mainly interested in how to do (1) to (2). How can the Teensy be connected to another device so it can receive instructions and immediately pass them on as a HID?

    I'm sure people have posted about this before but I don't know where to start, or what article even applies in my situation. Any help would be much appreciated, thanks!

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,694
    Hi and welcome,

    I guess the first question would be, is what do you mean by HID commands?

    That is a Teensy can output HID data like several different HID devices, such as keyboard, mouse, joystick...

    There are several web pages up on the Teensy site that describe some of these, like for example Joystick: https://www.pjrc.com/teensy/td_joystick.html
    or USB Mouse: https://www.pjrc.com/teensy/usb_mouse.html

    In addition Teensy can output HID data in a raw format: More up on the page: https://www.pjrc.com/teensy/rawhid.html

    But again hard to give you any additional help without knowing what it is you are wanting to send to the PC...

  3. #3
    Junior Member
    Join Date
    Jun 2019
    Posts
    3
    Hi KurtE,

    My hope was to have keyboard+mouse functionality. So, my Python script sends commands via the Teensy, which implements them as some combination of those two.

    I think the Teensy cannot do both at the same time (appear as both a mouse and keyboard to the computer), so it's OK for now if it alternates whenever it has to.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,694
    Actually it can do multiple devices at same time: Again don't know which Teensy you are using: Hopefully a 3.x?

    Also don't know how you have Nano connected to Teensy? Maybe a hardware Serial port?

    But if your for example have a 3.2. Go into the Arduino IDE and choose that as the board type. Then look at the Tools->USB Type submenu and choose one of the options that has both:
    Example: Keyboard + Mouse + Touchscreen.

    You know can be setup to send both types of commands.

    I don't know if there is an example program up there for doing both, but there are ones for each:
    Menu: File-> Examples -> Teensy -> USB_Keyboard ->Simple

    And with this, an object exists Keyboard, where you can output to the host, with commands like Keyboard.print("Hello World");

    Likewise if you load the example: File -> Examples -> Teensy ->USB_Keyboard -> Buttons.

    There is an object Mouse, where you can do things like: Mouse.press(MOUSE_LEFT);
    or: Mouse.move(-moveDistance, 0);
    ...

  5. #5
    Junior Member
    Join Date
    Jun 2019
    Posts
    3
    I have an old Teensy at the moment but I'll buy a newer one for this project - whatever the least expensive option is that can accept instructions from the Nano.

    As to how to connect the Nano to the Teensy, here are the Nano's I/O options (please refer only to the 'Module Interfaces').
    Click image for larger version. 

Name:	1*S2we_BYBSQqbgYiAUmTLEw.jpg 
Views:	6 
Size:	136.8 KB 
ID:	16726

    First, which of the above methods should I use?

    If I connect them via your recommended method, how can I send signals over that connection to make the Teensy do things like Keyboard.print() commands?

    EDIT: I re-read this post - I'm sorry if I'm asking for too much information in this thread. I would be more than happy to refer to reference materials - I just don't know which direction to go in! Thanks.
    Last edited by sscirrus; 06-06-2019 at 01:22 AM.

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    4,694
    Sorry, many of the things I mentioned in my previous posting and questions in your last posting are things that probably only you can answer as only you know what your goals are, the form of the data, and the desired results.

    Some of my earlier questions like how are you going to connect the Nano? Was because I was thinking of Arduino Nano like: https://www.newegg.com/p/2S7-003Z-00...8383-_-Product

    I also wondered how it runs python scripts... Turns out from your last post it is a different beast. Which gives you several options on connections.

    Obviously probably won't hook up Teensy using USB as you need the USB to plug into your PC... But it looks like it support Serial, I2C(Wire), and SPI... Not sure of any of the details, example: 3 Uarts? What type of connection do you have here? TTL or RS232 or ? What voltages?

    Which Teensy to try? Personally I like the biggest and most powerful... But cheapest... Would be the Teensy LC, but personally I would start off with probably 3.2. Why? While it runs at 3.3v the IO pins are 5v tolerant. More memory, speed, faster Uart, ... If I were concerned that it did not have enough still maybe 3.5, but my guess is 3.2 would be a great starting place.

    What would I try first? I would probably try to hook up the Nano by Hardware Serial port. On Teensy probably Serial1 or Serial2. How? depends? If it has a compatible Uart with appropriate software (Linux?) I Would try hooking it up that way... But Quick and dirty, I would maybe just get some USB to Serial adapter, example an FTDI cable or breakout board... And connect up the appropriate pins to the Teensy. TX->RX, RX->TX, and common ground...

    Then on your Nano, you would need something in your Python script, I assume using PySerial, to output data in some format that decide on, from whatever inputs you are processing... On the Teensy side you would need to have code that reads in stuff from the Uart example Serial1... Where you do some code that receives the data (Serial1.read())... And then if your data says to do print something, it would then call Keyboard.print with that data...

    Again those types of details are something you will need to experiment with. You might start off simple, and for example only try to output everything you receive from Serial1 and send it directly to keyboard...

    Again something simple like:
    Code:
    void setup() {
      Serial1.begin(115200);
    }
    
    void loop() {
      while (Serial1.available()) {
        int ch = Serial1.read();
        Keyboard.write(ch);
      }
    }
    And see if it talks OK...

    Might try another similar simple test to see if I could talk like a mouse. It might be a little more complex as may need to encode information, like do you want a button press or release or do you want to move the mouse....

    Then once you have something like that working, would look to how to combine. Develop a communication data format that you need to setup. Probably something with an ID to say keyboard or Mouse and maybe count of data? Maybe some form of standard header and/or checksum...

    Again don't know you need or application. Things like how fast and/or how much... If too fast or much may need some form of handshaking, Which might be software and/or hardware...

    Hope that gets you started.

    Kurt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •