Nano as keyboard

Hi!

I know that this topic is well known on this forum - i've read old topics, but haven't found answers to my questions.

I know that it is impossible to use USB build-in port to act as HID and I know that it is possible to build hardware USB port.

My problem is, that I've built some shield for my nano that uses D2-D6 and A0 for something else.

So, I've found this tutorial: https://www.hackster.io/rayburne/arduino-to-excel-using-v-usb-cbf701 And it seems to 'do-the-job' for me, but... am i able to configure it to use other ports than D2-D6?

I'm not very good on programming, so I really need explanation for dummies ;)

Best regards!

e-San: ... impossible to use USB build-in port to act as HID...

Well, that may not be true, just get a board with the right processor.

If you're not very good on programming, I recommend you look into the Sparkfun Pro Micro, Arduino Micro, Leonardo or some other ATmega32U4-based board, so you can have native HID on the built-in USB and save yourself a lot of trouble.

Ray Burnette is a frequent contributor here - "mrburnette" http://forum.arduino.cc/index.php?action=profile;u=100837

I could be wrong, but since they're not declared in the sketch shown at his webpg, they're probably in the usbkeyboard.h (library code). If he doesn't find this post, he may join you here if you PM him.

[Leonardo prices are comparable to Unos. They're Uno-compatible, broadly if not universally (?), besides being HID-ready.]

There's "hoodloader", too. Haven't tried it. https://github.com/nicohood/hoodloader

dmjlambert: Well, that may not be true, just get a board with the right processor.

So it is impossible with nano ;).

I'm not THAT bad with programming and my shield is already made and working, so i'm looking for this solution.

[quote author=Runaway Pancake link=msg=2554498 date=1452215583] Ray Burnette is a frequent contributor here - "mrburnette" http://forum.arduino.cc/index.php?action=profile;u=100837

I could be wrong, but since they're not declared in the sketch shown at his webpg, they're probably in the usbkeyboard.h (library code). If he doesn't find this post, he may join you here if you PM him. [/quote]

Can not find anything in those libs - maybe here is my lackage of knowledge... I wrote to him.

Ok, it's pointless:

There are only two external interrupt pins on the ATmega168/328 (ie, in the Arduino Uno/Nano/Duemilanove)

as stated in: http://playground.arduino.cc/Code/Interrupts

Thanks for resposes.

Best regards.

e-San,

Regrets that it has taken a few days to catch your message, frequent is about once-per-week, often longer.

And it seems to ‘do-the-job’ for me, but… am i able to configure it to use other ports than D2-D6?

Yes. You will need to compile at 1.0.6 and need this library:

/* 
   Based upon UsbKeyboard.h: http://code.google.com/p/vusb-for-arduino/source/browse/libraries/UsbKeyboard/UsbKeyboard.h
   Based upon V-USB: http://www.obdev.at/products/vusb/license.html
*/

Which I think you already have.

The sketch changes need to be made in setup() for digital pins of interest:

pinMode( 3, INPUT);      //  sets the digital pin 3 as input
  pinMode( 6, INPUT);      //  sets the digital pin 6 as input
  pinMode( 7, INPUT);      //  sets the digital pin 7 as input
  pinMode( 8, INPUT);      //  sets the digital pin 8 as input
  pinMode( 9, INPUT);      //  sets the digital pin 9 as input
  pinMode(10, INPUT);      // sets the digital pin 10 as input
  pinMode(11, INPUT);      // sets the digital pin 11 as input
  pinMode(12, INPUT);      // sets the digital pin 12 as input

And in loop() the string of reads associated with digital reads:

    if (digitalRead(3) == HIGH){
      sOut.concat("3H ");
    } else {
        sOut.concat("3L ");
    }
    if (digitalRead(6) == HIGH){
      sOut.concat("6H ");
    } else {
        sOut.concat("6L ");
    }
    if (digitalRead(7) == HIGH){
      sOut.concat("7H ");
    } else {
        sOut.concat("7L ");
    }
    if (digitalRead(8) == HIGH){
      sOut.concat("8H ");
    } else {
        sOut.concat("8L ");
    }
    if (digitalRead(9) == HIGH){
      sOut.concat("9H ");
    } else {
        sOut.concat("9L ");
    }
    if (digitalRead(10) == HIGH){
      sOut.concat("10H ");
    } else {
        sOut.concat("10L ");
    }
    if (digitalRead(11) == HIGH){
      sOut.concat("11H ");
    } else {
        sOut.concat("11L ");
    }
    if (digitalRead(12) == HIGH){
      sOut.concat("12H");
    } else {
        sOut.concat("12L");
    }

The Analog stuff is in a loop, but digital is just an “if”() …

Now, while this works on an Atmega328P, I cannot attest to any other 16MHz 8-bit AVR. As stated previously, in today’s world there are far better HID options.

Good luck,

Ray

USB_HID_AnalogX6_D8.ino (8.67 KB)

Credits.h (198 Bytes)

Interesting, had not seen this previously.
I’m usually off in ESP8266 or STM32duino land but I do try and stay available here; but, even retired I am still married and I answer to an authority higher than myself.

Ray