Questions: header files Key.h and Keyboard.h

// edited subject name

Hi people, New guy here :slight_smile:

Im building my first project (custom game controller with a Teensy 3.2)
What i read in the instructable is first i need to input:

#include <Key.h>
#include <Keypad.h>

I did find the <keypad.h> file on this site (somewhere) but i cannot for the life of me figure out where to get the <key.h> files..

So yeah, that is really my big problem right now.. all in all i have ordered about 120 bucks worth of hardware confident in the fact ill figure it out, but so far i havent :frowning:

As a reference, this is the thing im trying to build, and the part where im stuck is right there..

Instructable custom controller

To be honest, this is my first project, hoping to learn more about all this, but so far the Teensy is happily blinking at me while im slowly (quicker than ususal) going grey with despair :slight_smile:

So PLEASE,

can anyone point me towards the <key.h> file?
Cause when i try to run the code in the Arduino program i get the same message day after day

controller\FH34SN1IZ6CKITI\FH34SN1IZ6CKITI.ino:10:17: fatal error: Key.h: No such file or directory

#include <Key.h>

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This one?

You, sir, are a lifesaver! Thank you so much for the quick reply

So do i copy the whole code into the whole... arduino 1.6.8 script thing?

I also have that <keypad.h> downloaded but im not sure where to put this..

The files i placed in the same folder as the .ino file are

key,h (h file)
keypad.cpp (cpp file)
keypad.h (h file)

so looking at that, do i already have the file?

Looking at the link you just gave me, is that the script the guy on the site tells me to include with the #include <Key.h>
#include <Keypad.h>
?

To be honest, 99% of this goes over my head, the remaining 1% is.... you know what i mean..

So when i run/test this script it tells me:

fatal error: Keypad.h: No such file or directory

#include <Keypad.h>

---so does this mean im missing a file still, or that its not in the folder it should be in?

If the files are in the same folder as your sketch, use this format instead:
#include "key.h"

Use < > when the files are in your /libraries folder.

This is what my folder looks like so id say it should be all there right?

in map.PNG

sitting83duck:
This is what my folder looks like so id say it should be all there right?

It looks like you have two copies of the library in that folder, not really a good idea.

If you're going to put the library in the sketch folder then you need to use the:

#include "Keypad.h"

syntax, as Crossroads said. Some libraries use incorrect include syntax and thus would also need you to make this change in the library source in order to use them from the library folder. The library Crossroads linked above has this bug. If you don't want to do that then you could just follow the instructions found in that Instructable, which refers you to this Arduino Playground page for the Keypad library:
http://playground.arduino.cc/Code/Keypad
That page contains installation instructions for the library:
http://playground.arduino.cc/Code/Keypad#Download

This library is now available via the Arduino IDE library manager. If you are using a modern IDE (1.6.2 or above), you can simply use the menu:

Sketch->Include Library->Manage Libraries... Then search for Keypad.

Once found, click on its entry and the install button will appear. The zip file below is for the retro IDE's (not recommended for use, upgrade!).

Super easy! You're making this way more complicated than it needs to be by not reading the instructions.

pert:
Super easy! You're making this way more complicated than it needs to be by not reading the instructions.

Lol i have no idea what im doing, i think thats why nothing i do makes sense yet..
I have been reading and youtubing as how to "include header files into C++"
Im glad i did, cause now at least i learned what a header file is for. Sort of..

So, one one hand i have the Keypad.zip extracted to the folder that my .ino file is in, which gives me

.ino file
keypad.zip, which extracts to a folder containing:

Examples folder
Utility folder
Keypad.ccp
Keypad.h
keywords.txt

So, do i copy the .ccp and .h into the folder above {where my .ino file is)?
I did that but reading above replies, that makes no sense?

On the other hand, as the instructable page says, theres also Key.h

CrossRoads' kind reply points me towards the Key.h code, but do i need to copy this into somewhere so i can save it as an .h file into that same folder?

Im really trying not to annoy people with my noobness, but as iver said this is my first ever project and i so want to make it work...

So ive copypasted the code into a notepadfile, saved as key.h, put that in the same folder as the .ino is in, changed

#include <Key.h>
#include <Keypad.h>

to

#include "Key.h"
#include "Keypad.h"

but still gives me the same error:

C:\Arduino\FH34SN1IZ6CKITI\FH34SN1IZ6CKITI.ino:10:17: fatal error: Key.h: No such file or directory

#include "Key.h"

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.


I tried leaving the brackets instead of quotationmarks but same error..

Im busting my head over this stuff :wink:

Please follow these instructions:

  • Delete all the files and folders you added to the sketch folder except FH34SN1IZ6CKITI.ino.
  • Restart the Arduino IDE
  • Sketch > Include Library > Manage Libraries...
  • Wait for downloads to finish
  • Type "keypad" in the "Filter your search..." box
  • Click on the "Keypad by Mark Stanley, Alexader Brevig" entry.
  • Click the "Install" button
  • Wait for installation to complete
  • Click the "Close" button.

After doing that the sketch should compile but I can't be certain of this because I don't have Teensyduino installed. At the least it should get you to the next error, which we can also help you with.

Hello Pert, thanks for your reply, i followed all steps above and the error is gone; it has however been replaced by a "fresh" one though :slight_smile:

But the method you listed was totally new to me, much like the rest of this stuff..
When i said i was a noob, i meant "noob" noob, as in: jumping into the deep end, all tied up, finding there are alligators in the deep end with guns..
So the most basic of things like what file should be in which folder is something im hoping to pick up along the way. Thats why im reading and youtubing about it.. a lot!

So, the new error says:

Multiple libraries were found for "Keyboard.h"
Used: C:\Users\Duck\Documents\Arduino\libraries\Keyboard
Not used: C:\Arduino\Arduino IDE\Arduino\libraries\Keyboard
Using library Keyboard at version 1.0.0 in folder: C:\Users\Duck\Documents\Arduino\libraries\Keyboard
Using library HID at version 1.0 in folder: C:\Arduino\Arduino IDE\Arduino\hardware\arduino\avr\libraries\HID
Using library Keypad at version 3.1.1 in folder: C:\Users\Duck\Documents\Arduino\libraries\Keypad
exit status 1
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?


That last line caught my eye, so i went and installed the Keyboard library called
Keyboard Built-in by Arduino version 1.0.1.

Also: Does your sketch include the line '#include <Keyboard.h>'?

I did put that in at the top where the #include <Key.h> and #include <Keypad.h> are, but that didnt seem to work.. .

Update: i did actually get the Teensyinstaller program installed.. that didnt work either but thats installed now.. :slight_smile:

Im really appreciating you lot taking the time to look into this with me.. getting the confidence back a bit that this whole thing might actually some day work :slight_smile:

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags (</> button on the toolbar).

Hopefully that will provide some more information I can use to find a solution to the new error.

Arduino: 1.8.2 (Windows 10), TD: 1.36, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"
               ^

FH34SN1IZ6CKITI:626: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEY_8);

               ^

FH34SN1IZ6CKITI:643: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEYPAD_9);

               ^

FH34SN1IZ6CKITI:660: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEYPAD_7);

               ^

FH34SN1IZ6CKITI:677: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEYPAD_8);

               ^

FH34SN1IZ6CKITI:694: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEYPAD_6);

               ^

FH34SN1IZ6CKITI:711: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEY_9);

               ^

FH34SN1IZ6CKITI:728: error: 'Keyboard' was not declared in this scope
To make a USB Keyboard, use the Tools > USB Type menu
               Keyboard.press(KEY_0);

               ^

Using library Keypad at version 3.1.1 in folder: C:\Users\Duck\Documents\Arduino\libraries\Keypad 
'Keyboard' was not declared in this scope

Ok... so thats a bit longer than i expected so ill just include the bottom ones? Forum says max length 9000 chars

I don't know what's wrong. Usually if your sketch has the line:

#include <Keyboard.h>

and you still get the error:

exit status 1
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

it means you're compiling for a board that doesn't have HID support, such as Uno. However, it's my understanding that Teensy 3.2 does have HID support. I'm prevented from trying to reproduce this problem by not having Teensyduino installed. Unfortunately it messes with the IDE installation in unknown ways so I don't like to install it as I don't own a Teensy. Hopefully someone else with Teensy experience can provide some help. If that fails you might try searching on the Teensyduino forum for information and if none is found post there. If you do so please add links here and there to the other post so people can see what has happened in the other thread to avoid wasting time due to duplicated efforts.

This error message tells exactly what to do:

To make a USB Keyboard, use the Tools > USB Type menu

Do you know what just happened..??

I selected "keyboard" as you said, ran verification again and..

NO ERRORISTS!!!
This for me is such a massive step cause this probably means the code im using is working!
Cant thank you guys enough for helping me out here!

So i loaded the program onto the teensy.. time for a little testing!

Im using the teensy on a breadboard, have a pushbotton (soldered the wires onto Common and NormallyClosed connections) and i have common connected to the 0 port and the NormallyClosed to port 14

Seeing as this teensy will be used as a sort of custom keyboard, what im aiming for is when i push the button, it translates into a real keyboard input, so therefore im expecting the button to give an output like a letter, a number or a symbol repsctively.
I opened a notepad file expecting to see some input when the button is pressed but theres nothing..

Am i a massive idiot thinking this would and should work?

The att is a picture of my wiring diagram (made in Fritzing) the OP checked this and said everything seems to be in the right place
For the test, i only connected Row 1 and Column A

Normally I'd recommend you to open Serial Monitor to view the debug output that sketch has but I'm not sure whether you get serial while the the Tools > USB Type menu is set to Keyboard. It's worth a try anyway. You will want to set the Serial Monitor baud rate menu to 9600 and then you should see things like "Key x Pressed" printed when you press the buttons on the keypad.

Thanks to oqibidipo for straightening us out on the last problem! I should have spotted that in the error.

I did some youtube searching about the serial monitor, and took the code from there to keep it basic for testing just one button.

My wires are connected to port 0 and 14 and ive typed this script and uploaded to the Teensy

int pushButton =2;

void setup() {

  Serial.begin(9600);

  pinMode(pushButton, INPUT);
}

void loop() {

int buttonState = digitalRead(pushButton);

Serial.println(buttonState);

delay(1);

}

To be specific, the video on youtube was an Arduino, not a Teensy.. im thinking, shouldnt i specify pins in the script somehow? So that the teensy knows where to expect input?

Further settings i have set in Tools are
-Board: Teensy 2.3 (cause its a 2.3
-USB Type: Keyboard, Mouse, Joystick
-Port: Emulated Serial (i cant change that as the option is greyed out)

What on earth am i missing here?
I know my soldering game is up to standard, not to big myself up in any way but all pins are connected properly, then the teensy is inserted in a breadboard, on my pushbutton ive soldered the wires which go directly to the breadboard

Attatched is a pic of the wiring as it is at the moment...

I also see the option "Get board info" but its saying "Native serial port, can't obtain info"

sitting83duck:
shouldnt i specify pins in the script somehow? So that the teensy knows where to expect input?

You did, right here:

sitting83duck:

int pushButton =2;

sitting83duck:
What on earth am i missing here?

sitting83duck:
I did some youtube searching about the serial monitor, and took the
-USB Type: Keyboard, Mouse, Joystick

Try setting USB Type to Serial.

sitting83duck:
-Board: Teensy 2.3 (cause its a 2.3

sitting83duck:
Im building my first project (custom game controller with a Teensy 3.2)

Which is it?

sitting83duck:
Attatched is a pic of the wiring as it is at the moment...

Your instincts about making things as simple as possible were good but there is still an unnecessary complication, the button. Instead just use a wire connected from digital pin 2 on your Teensy to ground as a button. You can pull one end of the wire out of the breadboard to simulate the button being released and put it back in to simulate a button press.

sitting83duck:

  pinMode(pushButton, INPUT);

That would only work if you had an external pull-up or pull-down resistor. Change it to:

  pinMode(pushButton, INPUT_PULLUP);

for explanation see:
https://www.arduino.cc/en/Tutorial/DigitalPins

After those changes, do this:

  • Select the correct port from Tools > Port menu
  • Tools > Serial Monitor
  • Select 9600 from the menu at the bottom right corner of the Serial Monitor window

You should see a line of 0s printing down the screen when you have the wire connected between pin 2 and ground.

You should see a line of 1s printing down the screen when you have the wire not connected to ground.

Ok.. guys...

Im preheating the oven and getting out the cookbook..
Tonight im baking a humble pie..

Pert, i read your reply while at work and came home to try this out..

For some reason i wanted to check my current setup again and i made a rather embarissing discovery..
I was connecting the teensy (2.3 by the way, sorry for the confusion) again and ran the monitor with the button.

Suddenly i saw
Key 0 PRESSED.

Key 0 RELEASED.

Key 0 IDLE.

Im thinking what the hell is going on now?? How is it working this time.. then it hit me like a hammer..
I was looking at the card... upside down!!! Am i a muppet or am i a muppet?

I cant believe how i made this stupid mistake, maybe for the last week ive been so focussed on the code itself and the setttings for the monitor that i completely overlooked the whole upside down thing..
Im blaming this all on the fact im trying to cut down on the daily intake of coffee, but i think id better blame my own stupidity :smiley:
But i take a bit of solace in the fact im probably not the first noob that made an error like this..

So i went and uploaded the whole code made by MattRHale which im using for this whole project and this works as well!
So yeah, the button is pressed, and the button registers!
When i connect it to the next ports over, the button registers!

One thing i dont get is when i use the pushbutton it works, but then i have a flipswitch, which will only register when i have the positive on say port 14 and the negative AND the illumination in port 0

just = and - wont work, itll only register if i also put the "light" connector in with the ground (on port 0)

I worked that out when i was holding the button and actually made that contact with my fingers, so yeah it was a bit confusing to get my head around that..


Long embarissing story short, its working now!

Now, i need to figure out how to connect the Voltage Steup-up module.
The Instructable made it clear i need this since all buttons im using (21 in total) are illuminated.

Its a 2A Max DC-DC Boost Step Up Conversion Module 2V-24V to 5V-28V Output
The guy posting the instructable has a few more buttons than im about to use so that should work!

On a side note, i again want to thank you guys and give you some digital cookies for helping me out here. I hope you dont feel i wasted your time with the whole upside down thinking, cause i still learned a whole lot from all of you.. This is forum at its best!!

Glad to hear it's working!