PDA

View Full Version : Teensy 3.0 Keyboard compile troubles



galaxip
01-17-2013, 04:38 AM
I've been trying for a few days to get the usb keyboard example here http://www.pjrc.com/teensy/usb_keyboard.html to compile and run, mostly using arduino software.

I can get the basic examples to work, but when I try adding #include <usb_keyboard.h> in order to get the more functionality.. I get the error below. And when I move files around to get util/delay.h in the path, many more errors are encountered. Perhaps I am missing something basic.

C:\arduino-1.0.3\libraries\usb_keyboard\example.c:27:24: fatal error: util/delay.h: No such file or directory
compilation terminated.

I am a Windows user, and not too knowledgeable in C. I know basic C syntax, very little about compiling.
It is important to me to get the functionality of holding a key down.. So I'm determined to get this working.
Can anyone suggest next steps or tell what I am doing wrong?

Thanks, John

Nantonos
01-17-2013, 07:32 AM
I've been trying for a few days to get the usb keyboard example here http://www.pjrc.com/teensy/usb_keyboard.html to compile and run, mostly using arduino software.

First thing to check is that by 'Arduino software' you mean 'the beta Teensyduino environment for Teensy 3.0' and not, for example, 'the Teensyduino environment for Teensy 2.0 and ++ 2.0' or 'the stock Arduino environment, which doesn't support Teensy at all'.

If the answer to that question is 'oops' then head here:
http://forum.pjrc.com/threads/15773-Teensy-3-0-Beta11-Software



I can get the basic examples to work, but when I try adding #include <usb_keyboard.h> in order to get the more functionality.. I get the error below. And when I move files around to get util/delay.h in the path, many more errors are encountered. Perhaps I am missing something basic.

Unlike most libraries, the native USB function in Teensy is selected from the menu in the Teensyduino environment and does not require a #include. Also, the code is in the hardware directory and not on the usual include path.

So you should be able to compile and upload all of the provided Teensy MIDI examples (keyboard, mouse, MIDI etc) and none of them have a #include.


C:\arduino-1.0.3\libraries\usb_keyboard\example.c:27:24: fatal error: util/delay.h: No such file or directory
compilation terminated.

I am a Windows user, and not too knowledgeable in C. I know basic C syntax, very little about compiling.
It is important to me to get the functionality of holding a key down.. So I'm determined to get this working.
Can anyone suggest next steps or tell what I am doing wrong?

Thanks, John

I suggest that you first make sure that you can compile, upload and execute the provided example programs like Simple and LayoutTest (File menu > Examples > Teensy > USB_Keyboard). That will show that your environment is set up correctly and also give you some workig examples to start from and extend.

If the examples work but your code doesn't, post your code. Using code tags, like this:



your code goes here
to stop the forum eating square brackets

PaulStoffregen
01-17-2013, 02:56 PM
Nantonos is correct.


I've been trying for a few days to get the usb keyboard example here http://www.pjrc.com/teensy/usb_keyboard.html to compile and run, mostly using arduino software.


Even for Teensy 2.0, that code is meant to be used stand-alone, not in Arduino.

Teensyduino installs that same code (actually, a slightly modified copy) into Arduino in hardware/teensy/cores/usb_hid. So it's already there. All you do is select Keyboard from the menu: Tools > USB Type.

If you try to import that code into your program in Arduino, it won't work. Even for Teensy 2.0, you'll get all sorts of compile errors, because it's basically a duplicate of the code that's already in hardware/teensy/cores/usb_hid.

Of course, for Teensy 3.0, that code *really* won't work, because it's written for the completely different 2.0 hardware. But again, you don't need it, because code that works for Teensy 3.0 is already built in, in hardware/teensy/cores/teensy3. All you have to do is select an option with Keyboard from Tools > USB Type.

To get started quickly, you might try opening one of the examples from File > Examples > Teensy > USB_Keyboard. Make sure Tools > Board is set to Teensy 3.0, and Tools > USB_Type is set to an option that includes "Keyboard", and then click the upload button. It's really that easy.

If you want to see the actual USB code, it's all available in hardware/teensy/cores/teensy3 (on a mac, control-click on Arduino and choose "show package contents" and navigate a couple folders until you find Java/hardware... on linux and windows Arduino is ordinary directories)

galaxip
01-17-2013, 07:16 PM
Thank you to both Nantonos and Paul.
I am using 'the beta Teensyduino environment for Teensy 3.0' version beta11.

Yes, I was able to compile and run the provided example programs like Simple and LayoutTest.
Even so, I still thought I would need to call usb_init() and usb_configured() in order for usb_keyboard_send() to work.
But trying again, after removing the include statement as described.. (drum-roll please)
The sketch works!! So maybe I was overthinking it.

Thanks again!
Here's the sketch I ran.

int led = 13;

// the setup routine runs once when you press reset:
void setup() {
pinMode(led, OUTPUT);

// flash led for 10 seconds
for (int i=0; i < 10; i++) {
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}

// press q
keyboard_modifier_keys = 0;
keyboard_keys[0] = KEY_Q;
keyboard_keys[1] = 0;
keyboard_keys[2] = 0;
keyboard_keys[3] = 0;
keyboard_keys[4] = 0;
keyboard_keys[5] = 0;
usb_keyboard_send();
delay(50);

// press t
keyboard_modifier_keys = 0;
keyboard_keys[0] = KEY_T;
keyboard_keys[1] = 0;
keyboard_keys[2] = 0;
keyboard_keys[3] = 0;
keyboard_keys[4] = 0;
keyboard_keys[5] = 0;
usb_keyboard_send();
delay(50);

delay(5000);
// release all keys
keyboard_modifier_keys = 0;
keyboard_keys[0] = 0;
keyboard_keys[1] = 0;
keyboard_keys[2] = 0;
keyboard_keys[3] = 0;
keyboard_keys[4] = 0;
keyboard_keys[5] = 0;
usb_keyboard_send();
delay(50);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, LOW);
delay(1000);
digitalWrite(led, HIGH);
delay(1000);
}

galaxip
01-17-2013, 07:25 PM
I do have a related question..
As result of my crashing about while trying to mis-compile things, did I lose something?

Under the "Tools | USB Type:" menu options I only see these:
Serial
Keyboard + Mouse + Joystick
Serial + Keyboard + Mouse + Joystick
Midi

Nantonos
01-18-2013, 02:43 AM
I do have a related question..
As result of my crashing about while trying to mis-compile things, did I lose something?

No - but you will have seen a larger menu of USB options if you selected Teensy 2.0 or ++ 2.0.


Under the "Tools | USB Type:" menu options I only see these:
Serial
Keyboard + Mouse + Joystick
Serial + Keyboard + Mouse + Joystick
Midi

That is currently correct for Teensy 3.0.

PaulStoffregen
01-18-2013, 04:08 AM
Beta 12 will add RawHID and Flight Sim.

galaxip
01-24-2013, 03:09 AM
Awesome. That's what I saw then!

galaxip
01-24-2013, 03:13 AM
Beta 12 will add RawHID and Flight Sim.

Looking forward to that.. And I'm going to need another teensy! :D