PDA

View Full Version : How do I load an example from the outside of Arduino example code library?



vt91
06-07-2013, 06:21 AM
I am fairly new to microcontrollers and I bought Teensy v3 after a long time spent messing with PIC controller - based educational modules.
I have a question:
How would I open files of an example project for Teesny (with all Teensy programs installed to the Arduino root)
None of those files want to open. How do I load an example from the outside of Arduino example code library?

552551

el_supremo
06-07-2013, 05:32 PM
Each Teensy/Arduino sketch must have a file with the extension .ino
The directory in your example image does not have a .ino file, so the IDE can't open it. If it is PIC code, you would have to edit the code to make it conform to the Arduino sketch structure.

Pete

PaulStoffregen
06-07-2013, 07:24 PM
From that first screenshot, it looks like you're trying to open the (very old) USB examples meant for WinAVR.

Teensyduino includes a newer version of that code which is automatically built into your program when you click the Verify or Upload button in Arduino. Even if you manage to open the code in Ardiuno, it can not work because there is a nearly identical copy already present in the core library. You'll get a massive number of conflicts from all the duplicated stuff. That code is all part of Teensyduino. Select the USB device you want from the Tools > USB Type menu!

Also, that very old USB example code for WinAVR only works on AVR-based Teensy 2.0 boards. You can not use it with Teensy 3.0.

If you want to build programs for Teensy 3.0without Arduino, there is a sample makefile in hardware/teensy/cores/teensy3. See the comments in the makefile for more info. Generally you'd run "make" on the command line. It's also possible to use Eclipse, Visual Micro, or X-code (mac), with plugins people have developed.

If you want to use Arduino to build the code, but you're looking to import code that is in a .c file, there are a few ways to do it. Probably the simplest is to just copy and paste functions right into the Arduino editor (open the files with a text editor or word processor to copy their text to the clipboard).

Arduino can import .c, .cpp and .h files. You can not do that by clicking them in Windows Explorer. On the right hand side of the toolbar in Arduino is a "new tab" button. You can create .c, .cpp and .h files. You can also quit Arduino and just copy the files into the directory Arduino put your program into. When you restart Arduino, you'll see them as tabs in the editor.

But whatever you do, those .c and .h files in the first screenshot will not work. They're designed for the AVR chip on Teensy 2.0, so they can't possibly work on Teensy 3.0. Even with Teensy 2.0, that code is already inside the core library, so if you put a copy into your own program, the result will be a lot of conflicts from duplicated variables.

I hope this helped answer your question. To be honest, I'm not quite sure what you really needed here. From the screenshot, it looks like you're trying to import the USB code, so maybe the actual answer is to just select the one you need from the Tools > USB Type menu?

vt91
06-10-2013, 03:12 AM
I was asking about this example. Is it still relevant with today's technology and Teensy 3?
Should I look inside examples in Arduino shell from now on?
Do Teensy examples update themselves in the Arduino IDE as their number is increasing?

PaulStoffregen
06-10-2013, 10:02 AM
Is it still relevant with today's technology and Teensy 3?

Thay example is for Teensy2.



Should I look inside examples in Arduino shell from now on?


Yes, the code in Teensyduino is the official support for Teensy3.

Most people use it with Arduino, but it can also be used stand-alone. See the example makefile for details.



Do Teensy examples update themselves in the Arduino IDE as their number is increasing?

There's nothing like an automatic internet connection made by Teensyduino to update the code. To update, when a new version is available you need to download and run the new installer. Usually it's possible to install over the top of an old version (the "Next" button will not enable if it's incompatible and requires a fresh copy of Arduino).

vt91
06-10-2013, 01:13 PM
http://www.pjrc.com/teensy/usb_keyboard.html
This example. I am sorry the link got lost.

So I download those two archives and than and then I cannot load files from them.



Download Source Files

* USB Keyboard, Version 1.1.
* USB Keyboard with Debug Channel, Version 1.1.

PaulStoffregen
06-10-2013, 06:00 PM
That example is for Teensy2.