Help with making a hid based cnc pendant

Hi everyone.

i need some help with my project.
iam trying to make a cnc pedant that work with the hid function with mach3.

I found a code that i like to use and from there to expand it to my needs.
the code use the basic futures.
a mpg handwheel to jog and one 3 position switch to select the X or Y Or Z axis.

this is the code i find:

// bCNC Pendant
// https://github.com/mprochnow/CNC-Engraver
// Original author: Martin J. Prochnow <email@martin-prochnow.de>
// License: CC BY-SA 4.0 (Attribution-ShareAlike 4.0 International, http://creativecommons.org/licenses/by-sa/4.0/)

#include <Keyboard.h>

#define pinA  2  // Arduino Pin 2 => ATmega32u4 PD1
#define pinB  3  // Arduino Pin 3 => ATmega32u4 PD0
#define pinX  4
#define pinY  5
#define pinZ  6
#define debounceThreshold  700 // microseconds

volatile unsigned long debounceLast = 0;
volatile char step = 0;

void setup() {
  pinMode(pinA, INPUT);
  pinMode(pinB, INPUT);

  pinMode(pinX, INPUT_PULLUP);
  pinMode(pinY, INPUT_PULLUP);
  pinMode(pinZ, INPUT_PULLUP);

  attachInterrupt(1, readEncoder, RISING);

  Keyboard.begin();
}

void loop() {
  if (step == -1) {
    if (digitalRead(pinX) == LOW) {
      Keyboard.press(KEY_LEFT_ARROW);
      Keyboard.release(KEY_LEFT_ARROW);
    } else if (digitalRead(pinY) == LOW) {
      Keyboard.press(KEY_DOWN_ARROW);
      Keyboard.release(KEY_DOWN_ARROW);
    } else if (digitalRead(pinZ) == LOW) {
      Keyboard.press(KEY_PAGE_DOWN);
      Keyboard.release(KEY_PAGE_DOWN);
    }

    step = 0;
  } else if (step == 1) {
    if (digitalRead(pinX) == LOW) {
      Keyboard.press(KEY_RIGHT_ARROW);
      Keyboard.release(KEY_RIGHT_ARROW);
    } else if (digitalRead(pinY) == LOW) {
      Keyboard.press(KEY_UP_ARROW);
      Keyboard.release(KEY_UP_ARROW);
    } else if (digitalRead(pinZ) == LOW) {
      Keyboard.press(KEY_PAGE_UP);
      Keyboard.release(KEY_PAGE_UP);
    }
    step = 0;
  }
}

void readEncoder() {
  if (micros() - debounceLast > debounceThreshold) {
    debounceLast = micros();

    // PIND = Port D Input Pins Address
    // Check if PD1 is set
    if (PIND & B00000010) {
      // Check if PD0 is set
      if (PIND & B00000001) {
        step = -1; // CCW
      }
      else {
        step = 1; // CW
      }
    }
  }
}

but it give me some faults but i think i have all the libraries that i need.

i try to copy past the error readings i get from my IDE

C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino: In function 'void setup()':
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:28:3: error: 'Keyboard' was not declared in this scope
Keyboard.begin();
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino: In function 'void loop()':
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:34:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_LEFT_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:34:22: error: 'KEY_LEFT_ARROW' was not declared in this scope
Keyboard.press(KEY_LEFT_ARROW);
^~~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:37:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_DOWN_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:37:22: error: 'KEY_DOWN_ARROW' was not declared in this scope
Keyboard.press(KEY_DOWN_ARROW);
^~~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:40:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_PAGE_DOWN);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:40:22: error: 'KEY_PAGE_DOWN' was not declared in this scope
Keyboard.press(KEY_PAGE_DOWN);
^~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:47:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_RIGHT_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:47:22: error: 'KEY_RIGHT_ARROW' was not declared in this scope
Keyboard.press(KEY_RIGHT_ARROW);
^~~~~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:50:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_UP_ARROW);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:50:22: error: 'KEY_UP_ARROW' was not declared in this scope
Keyboard.press(KEY_UP_ARROW);
^~~~~~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:53:7: error: 'Keyboard' was not declared in this scope
Keyboard.press(KEY_PAGE_UP);
^~~~~~~~
C:\Users\Trial\Documents\Arduino\bCNC_Pendant\bCNC_Pendant.ino:53:22: error: 'KEY_PAGE_UP' was not declared in this scope
Keyboard.press(KEY_PAGE_UP);
^~~~~~~~~~~
Multiple libraries were found for "Keyboard.h"
Used: C:\Users\Trial\Documents\Arduino\libraries\Keyboard
Not used: C:\Users\Trial\AppData\Local\Arduino15\libraries\Keyboard
exit status 1

Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

hope i missing something why i cant upload it to my arduino and can go further with the project.

Rolf Koedam

That usually means that your using a board that does not have native USB (e.g. Uno, Mega, Pro Mini, classic Nano). Boards with native SB are most modern boards as well as Leonardo, Micro, and Pro Micro.

Why did you post in a category that clearly stated "do not use"? Please pay attention to where you post. Your topic has been moved to a more suitable location on the forum.

image

and

Sorry for posting in the wrong category.

iam using the arduino nano.
the told m i can use this for hid.

I'm not sure who "they" are, but that information is incorrect.

If you're set on a a board with the Nano footprint, get one of the Nano 33 models. Or a Arduino Micro (different footprint).

you where right the nano dont support hid function.

i now have the arduino pro mini and the sketch was uploaded to the board.
i have everything hook up but i cant see it working.
how can i reed the outputs when trying ?
serial monitor dont work
anyone a idea how to do this so i can control if the buttons do what i like them to do ?

Please be accurate; a Pro Mini does not have native USB support, a Pro Micro however does.

Which outputs? The Keyboard.press() in your code?

What do you mean exactly? "Dont work" is a vague description.

If there is no text in the serial monitor, navigation using cursor keys will not be possible. It's the same as with an empty IDE sketch (or any editor); you can't move left or right if it does not contain text. If that is your problem, first write some text with e.g. Keyboard.print(). After that you should be able to move left and right.

Alternatively, use a text editor, type some text in it and test your sketch.

After looking on internet i see i made some faults.
The Nano board can't use as a hid you right about that.
I made me a little experiment board with al the stuf i like be on it.
i bought a Arduino pro micro that can be used as a hid device .
i like to put a display in it but first i use a simple 40x4 lcd display.
If everything work how i like i am going to flip it with a smal amoled display.

i have made some projects with arduino but iam stil a beginner.
i try to put my code here on the forum and build it up from the biginning.
and hope that with the help of u it wil be a working project so more people can learn from it and use it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.