keyboard firmware help

Status
Not open for further replies.

baddog

Member
I am a old guy trying something new. I have no coding experience. I'm a handy guy and I have a idea about something I want to build. What I want to build is a mini keyboard with a joystick. I have found a source for switched (digital) joysticks. I have built a few different prototypes. I haven't been completely happy with any of them.

One of the biggest hurdles is what am I going to use for a key encoder. I have tried a few different options. First thing I tried was taking circuit board out of a commercial keyboard, and making a pcb break out board. That worked but its not a very elegant solution. My second attempt was to use a MAX Keyboard, Falcon-8 keyboard pcb. it looks good but its not a perfect solution. The falcon-8 does not offer enough keys.

I have a just a little experience loading sketches on to a Arduino board. What I am after here is some one to tell me which of these board would work with my project and point me to some reliable keyboard firmware code.

Any help with this project would be appreciated.


IMG_9445.jpgIMG_9446.jpgIMG_9447.jpgIMG_9448.jpg
 
Last edited:
A teensy can emulate a keyboard and/or joystick over USB. If you haven't brought any hardware yet suggest going through the Teensyduino install steps:

http://www.pjrc.com/teensy/td_download.html

And then have a look in file->examples->Teensy->USB keyboard

See also https://www.pjrc.com/teensy/td_keyboard.html

To get them to compile you need to go into the boards menu and also select a Teensy and then under type select 'keyboard' so things get automagically configured

If you think that you can abuse the example code enough to do what you want then pick a Teensy. Any of the ones currently on sale will do what you want, as would some of the current generation Arduino branded boards that also support USB keyboard emulation so there are a fair number of choices given you are not trying to use heaps of keys. The Teensy3.2 is probably the most flexible but LC is cheaper and the Teensy2 or it's relatives will also work. Be aware atmega 32u4 boards labelled as Teensy or Arduino at attractive prices online are often counterfeit. They normally still work but often have 'features' so would suggest paying the premium and getting a branded board from a normal supplier for your first project to avoid pulling hair out trying make code run on a dodgy board.
 
Thanks for your help. I did manage to buy a teensy 2.0 and get it to run the blink sketch. The following link is precisely what I would like to build. https://www.pjrc.com/teensy/usb_keyboard.html When I tried to run the sketch for this project I received this error " Error compiling for board teensy 2.0" Any help in modifying this code or creating a new code with be very much appreciated " Screenshot (6).jpg


"CODE REMOVED BY baddog"
 
Last edited:
First up, when you post code if you put it in code tags, or us the 'go advanced' button and select that option. you get a scrolling code window where indenting works which makes things easier.

Can you scroll up the error window in Arduino when you compile and check if there is anything more useful being produced there?

Can you also try using the other USB keyboard examples under file->examples->teensy->USBkeyboard, starting with simple? I think you have got some parts of the library in your code itself which will be making a mess of things.

General idea when asking for help is make the smallest possible code example that doesn't work to make it easier for people to run it themselves and/or sift through.
 
Without seeing the error report, I'm just guessing that you haven't changed the "USB Type" (in the Tools menu) to something that includes Keyboard.

When trying examples, forgetting to change the USB Type is not so uncommon mistake...
 
Screen shot does show T2 with USB keyboard, which looking at the code means there are two lots of USB keyboard setup going on. Which may explain the compiler having a fit.
 
Thanks for your help. I'm apologize for posting such a long code. I can see how a code like that would be of limited use.
When I get more time I plan on diving deeper in to these little boards.
For now I appreciate the help I get in these forums. That really helps me just dive in and build the things I want to build.

I found some CODE on a web site Brainy Bits. It looks like something I can use. https://brainy-bits.com/tutorials/leonardo-arcade-controller/

However I am still having issues loading it on to my board. listed bellow is the error code



Arduino: 1.6.11 (Windows 10), TD: 1.30, Board: "Teensy 2.0, Keyboard + Mouse + Joystick, 16 MHz, US English"

Build options changed, rebuilding all
sketch_oct21a_persue: In function 'void setup()':
sketch_oct21a_persue:3: error: 'class usb_keyboard_class' has no member named 'h'
Keyboard.h>

^

'class usb_keyboard_class' has no member named 'h'
Invalid library found in C:\Users\chris\Documents\Arduino\libraries\sketch_oct19a: C:\Users\chris\Documents\Arduino\libraries\sketch_oct19a
Invalid library found in C:\Users\chris\Documents\Arduino\libraries\sketch_oct19a: C:\Users\chris\Documents\Arduino\libraries\sketch_oct19a

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.



Code:
void setup() {

Keyboard.h>

//Joystick and button connections
pinMode(2, INPUT_PULLUP); //Joystick Left Switch
pinMode(3, INPUT_PULLUP); //Joystick Right Switch
pinMode(4, INPUT_PULLUP); //Fire Button
}

void loop() {
  
// Check the switches:
int buttonState2 = digitalRead(2);
int buttonState3 = digitalRead(3);
int buttonState4 = digitalRead(4);

// Joystick Left = Arrow Left Key
if (buttonState2 == LOW) {
Keyboard.press(216);
}
else {
Keyboard.release(216);
}

// Joystick Right = Arrow Right Key
if (buttonState3 == LOW) {
Keyboard.press(215);
}
else{
Keyboard.release(215);
}

// Fire Button = Left Ctrl key
if(buttonState4 == LOW) {
Keyboard.press(128);
}
else{
Keyboard.release(128);
}
}





For anyone interested, I attached a few photos of my home built CNC router. I built his from scratch. I didn't know anything about CNC machines when I started the project. As a mater of fact I didn't even see a professionally built machine until years after I built my own.

I have a issue (bad or good, I don't know). I get a idea in my head about something I want to build. I then become obsessed with it. Even if I don't have the necessary skills to actually build my project. That becomes a problem because I often have to learn things the hard way. Not only that its eats a lot of my free time (Just ask my wife).

IMG_9452.jpgIMG_9458.jpg


The idea I'm working on now came from a computer game I like playing "World of Tanks". I play the game on laptop sitting on my couch. I had a hard time keeping my fingers on the WASD keys sitting in this position. I thought what would be nice for this situation, is a little joystick to operate the WASD keys. So here I am obsessed with another idea. I posted a few photos of previous attempts. I received a different switched joystick in the mail Friday and decided to try another mock up. Here are some new photos of what I did Saturday morning.

IMG_9453.jpgIMG_9454.jpgIMG_9455.jpgIMG_9456.jpgIMG_9457.jpg
 
Last edited:
- Choose USB-Type "Keyboard" from the Menu.
- Remove the line
Keyboard.h>

from the sketch.
 
Last edited:
Frank B

Thanks for your response.

I will give it try as soon as I get a chance
 

Attachments

  • Screenshot (11).jpg
    Screenshot (11).jpg
    104 KB · Views: 130
  • error 1.jpg
    error 1.jpg
    30.8 KB · Views: 115
  • error 1.1.jpg
    error 1.1.jpg
    25.4 KB · Views: 83
Last edited:
Ooops. teensy 2. I don't know anything about it - others can help better, in this case.

BUT: The line
Code:
Keyboard.h>

is definately wrong - just remove it.
 
- Choose USB-Type "Keyboard" from the Menu.
There is no option "Keyboard" for Teensy 2.0. There is "Keyboard + Mouse + Joystick" and "Serial + Keyboard + Mouse + Joystick".

Baddog: I tried your code with "Keyboard + Mouse + Joystick" and it works, when the Keyboard.h> is removed. I didn't get any errors. But those key-scancodes do not do anything on my computer. I replaced them with KEY_LEFT, KEY_RIGHT etc and then it works. You might also want to use debouncing: http://pjrc.com/teensy/td_libs_Bounce.html
 
Pazi thanks a lot.

I removed the "keyboard.h" and wrote in KEY_RIGHT...... that seamed to work. I hope to find time in the up coming week to play around with this. Again thanks to all who responded to my post.
 
I am also an old guy who refuses to learn except by doing it himself and making mistakes. My current project is to add buttons to a racing wheel for sim racing. I started by cannibalizing a numeric keypad, but that didn't have enough buttons. Then I switched to repurposing the controller from a keyboard. I had mixed results with this based on how solid the connector pads were on the board. I eventually got one from a Logitech keyboard to work. But this still wasn't good enough, so I am working now with a Teensy 3.2. the Teensy is much better than using a keyboard controller board. First, it's easier to work with than a repurposed card from a keyboard. Secondly, because it's programmable, I can build macros on keys so pressing the "D" key, for example, actually sends the keycodes for down, right, right, etc. With the board from a keyboard, I couldn't do macros without using another program (I found that G-hotkeys...free worked very well but had a limitation on the number of macros). I used the stock programming in the examples that use keyboard.set_key and keyboard.send_now. I have the send the keycodes because the game only recognizes DirectX/DirectInput scan codes. If I still don't have enough buttons, I know I could program one to be a modifier (aka Shift key) and the pressing the button alone would send one thing while pressing it while holding down the modifier key could do something entirely different. That effectively doubles the number of available keys/macros. Having done the projects with both a numeric keypad and a keyboard, I would recommend a Teensy. Here's a look at what prototype #5 looks like.
V55nhr0.jpg
 
Status
Not open for further replies.
Back
Top