Author Topic: Programming tools for Arduino and Teensy  (Read 6806 times)

0 Members and 1 Guest are viewing this topic.

Offline raptor1956Topic starter

  • Frequent Contributor
  • **
  • Posts: 869
  • Country: us
Programming tools for Arduino and Teensy
« on: June 26, 2017, 05:37:35 am »
I'm just getting started with Arduino and have a Mega2560 as well as a Teensy 3.6 on the way but I have some questions about the various programming tools out there.  I know both controllers will take code generated with the Arduino IDE and plan to start with IDE, but what about other development tools like the Atmel Studio?  I have to believe most all the genuine Arduino controllers will work with Studio but what about the Teensy 3.6.  What other tools are useful for code generation?

I should mention that it's been quite a while since I did any serious programming, about 25 years in fact, and in that time I've only done a little Visual Basic.  The earlier programming was for Unimation then Staubli 760/762 robots using a Basic like language known as VAL/VAL2.

So, for the near term I'll be using the IDE but other tools like Studio and Processing seem to have some things that might make then better for some things -- I just don't know if the Teensy 3.6 series is compatible without jumping through unpleasant hoops.


Brian
 

Offline MosherIV

  • Super Contributor
  • ***
  • Posts: 1530
  • Country: gb
Re: Programming tools for Arduino and Teensy
« Reply #1 on: June 26, 2017, 07:01:39 am »
Hi, you just need the Arduino IDE. The Arduino come pre-programmed with what is called a 'bootloader' which communicates with the Arduino IDE. That is all you need.
There may be other programming tools that support the Arduino but i do not know what they are.

The Atmel Studio is for developing programs like the bootloader, it also need a special peice of hardware to programe the Atmel chip. I do not think Atmel studio allows Arduino code development. You need to know about the detail of the chip in order to use Atmel Studio.

Arduino was developed to allow simpler development with less equipment and less knowledge of the chip.

Hope this helps
 

Offline 3db

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: gb
Re: Programming tools for Arduino and Teensy
« Reply #2 on: June 26, 2017, 11:37:32 am »
The Arduino IDE also includes a sketch (ArduinoISP)  that turns your Arduino into an Atmel ISP programmer.
You can use this to program chips directly.
If you are using genuine Arduino's  (Uno and Mega) you can also use the Atmel Flip program to change the code in the micro controller into a programmer.

3DB

 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2601
  • Country: us
Re: Programming tools for Arduino and Teensy
« Reply #3 on: June 26, 2017, 11:52:08 am »
Atmel Studio isn't just for writing bootloaders, as a fully-featured IDE it has a lot of features and tools that are useful on any sort of project.  It's much better at organizing multi-file projects, has code completion and cross-referencing, has debugging support, etc.  The only real advantage Arduino has is the built-in library support and the way that it hides all of the low-level stuff for ease of use.


I know both controllers will take code generated with the Arduino IDE

It's more accurate to say that the Arduino IDE can generate binaries for both MCUs.  The Mega 2560 uses an 8-bit AVR, while the Teensy 3.6 uses a 32-bit ARM Cortex M4, both of which run completely different instruction sets and have different memory configurations.  The Arduino IDE incorporates toolchains for both architectures, and based on your selected board will invoke the appropriate one to build your program. 

Aside from Atmel Studio, which as the name suggests only supports Atmel parts, there are a number of other IDE options.  As far as free options go, most of them are based on Eclipse, which is a general-purpose IDE that can be used for any language or target if you hook up the right toolchain.  There are options like Atollic TrueStudio, which are basically Eclipse pre-configured to target a range of MCUs out of the box.  There are commercial tools like Keil and IAR, both of which I think still have free versions, that also support a wide range of targets.  Any of these options can be setup to work with a hardware debug probe, so you can directly load your program onto the MCU from the IDE, as well as see what's going on when the program is running, but if you don't have one, you can always use a bootloader just as you would with an Arduino board.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4034
  • Country: nz
Re: Programming tools for Arduino and Teensy
« Reply #4 on: June 26, 2017, 11:53:54 am »
I'm just getting started with Arduino and have a Mega2560 as well as a Teensy 3.6 on the way but I have some questions about the various programming tools out there.  I know both controllers will take code generated with the Arduino IDE

Note that the Arduino IDE doesn't generate any code. It's just a text editor and terminal emulator. It knows how to run a perfectly normal external toolchain usually consisting of gcc and as (assembler) and ld (linker) for the appropriate CPU, and a communications program such as avrdude or openocd to copy the generated binary file to the board for execution.

Anyone can make a package to support their own board using whatever compiler and programmer they want. They just need to tell you a URL to enter into settings in the Arduino IDE and everything is downloaded and installed automatically.

Once you have the toolchain for your Arduino IDE you can also use that toolchain directly without using the IDE if you want.

But you can also use the Arduino IDE to write programs that don't use the Arduino libraries, but set up and use CPU features directly. If you want. Your program may then be a bit more efficient, but it will cease to be portable. For example if you do that then you'll need very different code for an Arduino Uno, Arduino Mega2560, and Teensy as they have different CPUs -- very different in the case of the Teensy 3.6 as it uses an ARM Cortex M4.

Using the Arduino libraries has the advantage of (mostly) hiding the differences between the boards and CPUs.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Programming tools for Arduino and Teensy
« Reply #5 on: June 26, 2017, 12:58:06 pm »
For any experienced C/C++ programmer, the Arduino IDE sucks. Apart from its sucky editor, it hides the existence of the main() function and tries to eliminate forward declaration of function prototypes by auto-generating them from the sketch and in the process mangles your code.  There are workarounds but its a general PITA.   However it does do a good job of installing toolchains for your chosen boards, and as its GCC is better maintained than the version used by Atmel Studio, its probably worth installing under Windows just for the toolchains!   It can be used with an external editor, and there's also a no-GUI command line version that can be used to build and download sketches from an external IDE or editor

Atmel Studio is for Atmel MCUs only - if the chip on your Arduino board isn't on this list: http://www.atmel.com/tools/atmelstudio.aspx?tab=devices, forget about it.
Its Microsoft Visual Studio based so is a native Windows IDE, and is likely to perform better than competing IDEs written in Java.   If you have a supported Atmel hardware debugger for your MCU, its probably the best option.  N.B. on 'classic' AVR based Arduinos, you need to cut the  jumper to disconnect the USB serial port DTR or RTS from the AVR RESET pin before you can program/debug them from Atmel Studeo via the Arduino's AVR-ISP header.

The teensy 3.6 uses the NXP MK66FX1M0VMD18 MCU.   NXP provide an Eclipse based IDE that supports it using the GCC toolchain: http://www.nxp.com/products/software-and-tools/software-development-tools/kinetis-design-studio-integrated-development-environment-ide:KDS_IDE

Then there's third party IDEs - If you've got a favourite one, you've probably already got some idea how to configure it for a GCC based toolchain (i.e. to use the supplied Arduino toolchains) and maybe even how to configure it to use a GDB supported debugger for your chosen chip.
 

Offline MosherIV

  • Super Contributor
  • ***
  • Posts: 1530
  • Country: gb
Re: Programming tools for Arduino and Teensy
« Reply #6 on: June 26, 2017, 01:00:16 pm »
Quote
Atmel Studio isn't just for writing bootloaders, as a fully-featured IDE it has a lot of features and tools that are useful on any sort of project.
Agreed. I was trying to make the point that Atmel Studio is NOT a Arduino IDE and as far as I know it does not know how to communicate with the Arduino bootloader to download programs (correct me if I am wrong 8) )

Quote
As far as free options go, most of them are based on Eclipse,
Dear god NO. As a professional Embedded software developer with 20 years experience I have never come across anything as bad as Eclipse.
Avoid at all costs is my PROFESSIONAL OPINION
It is slow.
It fills/divides your screen with useless little windows obscuring your editing window
It forces you to work in a way that is un-intuatuive (A good IDE allows you to work in the way YOU WANT !! not force you to be a slave to the machine).
It does not handle windowed editor windows so is limiting in the number of files you can have open.
It randomly re-orders the editor window tabs
The list goes on and on and on

Stick to the Arduino IDE
 
The following users thanked this post: cdev

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4034
  • Country: nz
Re: Programming tools for Arduino and Teensy
« Reply #7 on: June 26, 2017, 02:38:38 pm »
For any experienced C/C++ programmer, the Arduino IDE sucks. Apart from its sucky editor,

I consider myself an experienced C/C++ programmer, having started with C in 1982 and Zortech C++ in 1988 and MPW C++ (rebadged AT&T cfront) in 1989 and used both continuously since. I also write compilers for C, C++ and other languages both professionally and as a hobby.

The Arduino IDE editor sucks compared to emacs, but to be honest it doesn't annoy me any more than Visual Studio, XCode or (God save us) Eclipse do.

Quote
it hides the existence of the main() function and tries to eliminate forward declaration of function prototypes by auto-generating them from the sketch and in the process mangles your code.

There's nothing sacred about main(). C compilers hide the existence of _start (or other entry point specified to the linker) and magically set up the stack, argc, argv and envp for you before calling main(). The gap to having an automagic main that says
Code: [Select]
void main(){ setup(); while(1) loop(); } is incredibly trivial.

Real men program directly in assembler without libcrt0.o. If not in hex.

It doesn't seem to be generally known that Wiring (which is the language that standard Arduino sketches are written in) is intended to let you use either a C++ or a Java compiler with exactly the same source code. To do that the IDE forward declares your functions for C++ or wraps your code with class declaration bullshit for Java.

Quote
However it does do a good job of installing toolchains for your chosen boards, and as its GCC is better maintained

This I agree with.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4034
  • Country: nz
Re: Programming tools for Arduino and Teensy
« Reply #8 on: June 26, 2017, 02:45:05 pm »
Quote
As far as free options go, most of them are based on Eclipse,
Dear god NO. As a professional Embedded software developer with 20 years experience I have never come across anything as bad as Eclipse.
Avoid at all costs is my PROFESSIONAL OPINION

Amen, brother.

Eclipse, as with Windows (and VS), tries to be too magic, and hide too much of what is really happening from you.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: Programming tools for Arduino and Teensy
« Reply #9 on: June 26, 2017, 02:50:02 pm »
it hides the existence of the main() function and tries to eliminate forward declaration of function prototypes by auto-generating them from the sketch and in the process mangles your code.

There's nothing sacred about main(). C compilers hide the existence of _start (or other entry point specified to the linker) and magically set up the stack, argc, argv and envp for you before calling main(). The gap to having an automagic main that says
Code: [Select]
void main(){ setup(); while(1) loop(); } is incredibly trivial.
Unfortunately that forces you to either use globals if you need to pass any information between setup() and loop() or put everything in setup() and leave loop() empty.   Neither are pretty . . . .

Fortunately the fix is fairly simple.  See Gammon.com.au: How to avoid the quirks of the IDE sketch file pre-preprocessing for details.    However the Arduino libraries still 'squat' on the Atmel AVR Timer 0 overflow interrupt vector, preventing you from linking your own handler for it.  I assume Arduinos with other makes of MCU may be similarly affected.
« Last Edit: June 26, 2017, 02:55:53 pm by Ian.M »
 

Offline IanJ

  • Supporter
  • ****
  • Posts: 1607
  • Country: scotland
  • Full time EE & Youtuber
    • IanJohnston.com
Re: Programming tools for Arduino and Teensy
« Reply #10 on: June 26, 2017, 04:10:58 pm »
I've tried a few different approaches to Arduino programming and the nearest I got to sticking with a system was Visualmicro  http://www.visualmicro.com/

However, I always ended up back at the IDE for one reason or another. So, if you do use the IDE then absolutely use an external editor, and I recommend Notepad++

Ian.
Ian Johnston - Original designer of the PDVS2mini || Author of the free WinGPIB app.
Website - www.ianjohnston.com
YT Channel (electronics repairs & projects): www.youtube.com/user/IanScottJohnston, Twitter (X): https://twitter.com/IanSJohnston
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Programming tools for Arduino and Teensy
« Reply #11 on: June 26, 2017, 05:15:45 pm »
The Arduino IDE will get you started and it works well with Arduinos, I don't know how to use it with the Teensy but it should work well.  But I don't like the IDE at all...

Microsoft Visual Studio is a much more elegant solution and there is an Arduino plug-in:
http://www.visualmicro.com/

I have the plug-in working with an Arduino Uno but I don't know what might be involved in setting it up for the Teensy.  Different toolchain...  I don't tend to use this very often so I have forgotten what was involved.

I disagree with all of the Eclipse detractors, I like it!  I especially like the Fortran plug-in.  I have been using Eclipse as the IDE for a number of different processors for the last 10 or 12 years.  It has improved a LOT over the years.

If you install the Arduino IDE for both devices, you will be well off to just use it for a while.  Later on when you think you understand what the underlying toolchain is doing, it might be time to try one of the others.
 

Offline DimitriP

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: us
  • "Best practices" are best not practiced.© Dimitri
Re: Programming tools for Arduino and Teensy
« Reply #12 on: June 26, 2017, 07:13:16 pm »
Quote
have a Mega2560 as well as a Teensy 3.6 on the way

Get also an Arduino UNO.  Depending on what you are trying to do, most examples available  are for the UNO.
They can be made t work on the Mega, but you end up spending time figuring out what the differences are.
   If three 100  Ohm resistors are connected in parallel, and in series with a 200 Ohm resistor, how many resistors do you have? 
 
The following users thanked this post: Ian.M

Offline raptor1956Topic starter

  • Frequent Contributor
  • **
  • Posts: 869
  • Country: us
Re: Programming tools for Arduino and Teensy
« Reply #13 on: June 26, 2017, 09:56:16 pm »
I appreciate all the replies and we'll see how things progress with my coding.  I'm comfortable using the Arduino IDE at this point and the point of the post in the first place was really as a look down the road.  One thing I didn't mention before but may have some relevance in a selection is that I can see the possibility of projects down the road that might make use of several  micro-controllers that are tied to a supervisor so having the ability to physically connect and communicate to/from supervisor/slave is something I'm thinking about but at this time that's more advanced than I need to worry about beyond having a sense as to the best approach when connecting several units together.  My sense is that SPI and I2C would be the connection types most likely to be used in that case but as this is all fairly new to me I have to admit to lacking the knowledge base to select anything at this point.  I mean, it's not just the editor/compiler but also the specific controllers that have that capability.

For the near term I'll be getting my hands dirty playing with the Mega2560 and Teensy 3.6 and since they are similar but not identical with the Teensy being much more powerful in terms of processing speed they should provide a good range to learn what is and what isn't needed.  Fun stuff...


Brian
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 16647
  • Country: 00
Re: Programming tools for Arduino and Teensy
« Reply #14 on: June 27, 2017, 08:27:20 am »
For any experienced C/C++ programmer, the Arduino IDE sucks. Apart from its sucky editor, it hides the existence of the main() function and tries to eliminate forward declaration of function prototypes by auto-generating them from the sketch and in the process mangles your code.  There are workarounds but its a general PITA. 

The workarounds aren't difficult, you mostly have to stop thinking like a C/C++ programmer. You can easily get main() back (just delete all the files in a special folder) and use an ISP programmer instead of the bootloader.

All that doesn't fix the crap editor or get you a debugger more sophisticated than printf() though.  >:(

OTOH Atmel studio is horrible in its own way. Choose your poison.

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Programming tools for Arduino and Teensy
« Reply #15 on: June 27, 2017, 01:39:49 pm »

One thing I didn't mention before but may have some relevance in a selection is that I can see the possibility of projects down the road that might make use of several  micro-controllers that are tied to a supervisor so having the ability to physically connect and communicate to/from supervisor/slave is something I'm thinking about but at this time that's more advanced than I need to worry about beyond having a sense as to the best approach when connecting several units together.  My sense is that SPI and I2C would be the connection types most likely to be used in that case but as this is all fairly new to me I have to admit to lacking the knowledge base to select anything at this point.  I mean, it's not just the editor/compiler but also the specific controllers that have that capability.


One of the nice features of Microsoft Visual Studio is that it will work with Makefiles.  In essence, it can use any underlying toolchain, not just the ones it comes with.

Some years back I was using a Teensy 2 (and a similar Digilent AVR board) to handle switches, knobs and dials as instrumentation of an aircraft for Microsoft Flight Simulator.  So, I am basically coding both ends of the deal.  On one end, AVR code and on the other PC code.  I could do this quite easily using just the Visual Studio IDE and this kept all the files together in one place.  Some setup required...

The AVR implemented a USB HID device as far as the PC was concerned and then used it's IO pins to talk to the physical world.  Pretty nice setup.

I suspect I could have done the same thing with Eclipse and gcc for both platforms, again using Makefiles to square away which toolchain.
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2881
  • Country: 00
Re: Programming tools for Arduino and Teensy
« Reply #16 on: June 27, 2017, 02:58:56 pm »
I suspect pretty much any decent IDE can use external makefiles over its internal build system. Getting all features like integrated debugging to work for multiple targets is a different matter. So you might just be using your IDE as a basic text editor.

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Programming tools for Arduino and Teensy
« Reply #17 on: June 27, 2017, 05:39:13 pm »
I suspect pretty much any decent IDE can use external makefiles over its internal build system. Getting all features like integrated debugging to work for multiple targets is a different matter. So you might just be using your IDE as a basic text editor.

Correct!  I have NEVER been able to get OpenOCD to work so I just don't bother.  True, it was 10 years ago the last time I tried but integrated debugging is only required if you put bugs in your code.  I try to avoid that!

I do have a nice JTAG debugging solution with Rowley Crossworks and it actually works but I kind of burned out on single stepping way back in the days of CP/M and DDT (late '70s).

I can get more relevant information with printf().  So, the very first thing I do with a new platform is to get the serial port working.  Then I borrow a bunch of string related conversion code from "The C Programming Manual" and I'm good to go.  I don't actually use printf() until much later in the project - if at all.  I don't generally want to implement a heap.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4034
  • Country: nz
Re: Programming tools for Arduino and Teensy
« Reply #18 on: June 27, 2017, 10:44:51 pm »
I do have a nice JTAG debugging solution with Rowley Crossworks and it actually works but I kind of burned out on single stepping way back in the days of CP/M and DDT (late '70s).

I can get more relevant information with printf()

Ditto.

A debugger can be useful to work on code you completely don't understand -- don't even know what function calls what, etc. I try to avoid that.

Single-stepping got old for me back when CPUs ran at 1 MHz and took several cycles per instruction as well. Now that PCs run 4 - 10 BILLION instructions per second per core and even embedded stuff is up in the tens to hundreds of millions .. it's completely useless.

And single stepping, breakpoints, and watchpoints just totally don't make sense in anything real-time, dealing with multiple communicating systems, external inputs, external outputs that are going to break something real if they don't get a signal from you

Adding a printf may slow some critical code section down by a us and that might not be acceptable in some places ... but there are plenty of places than can handle a us but sure as heck will die horribly if it's a ms, a second, or a minute.

printf also lets you gather a lot of evidence (tens of MB to a GB or two even) and then make up ways to analyse it *after* the fact. Perl/Python/Ruby are often wonderful for that
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2881
  • Country: 00
Re: Programming tools for Arduino and Teensy
« Reply #19 on: June 27, 2017, 11:50:27 pm »
Yes, if only the micro/debugger designers would have thought of something like printf, but with less performance impact and better integration with the source code. They could add hardware to the micro to accelerate this. How about they would call this real-time tracing?

I find interactive debugging occasionally useful. Sure, many bugs can be found by examining the code, or by inserting printf statements. But depending on how long the modify/compile/run cycle is (some bugs may need some external events to trigger them), it may be quicker to use an interactive debugger than to keep adding printf statements as you get closer to the problem area. Especially early when you have no idea where the problem is. Also for data structures that are not trivial to present in a readable format, like structures involving lots of pointers. Sure, you could write another problem to interpret it, but why not use the debugger to do that? Although I rarely single step, more likely run until breakpoint, examine variables, set new breakpoint, continue.

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4034
  • Country: nz
Re: Programming tools for Arduino and Teensy
« Reply #20 on: June 28, 2017, 11:32:15 am »
Yes, if only the micro/debugger designers would have thought of something like printf, but with less performance impact and better integration with the source code. They could add hardware to the micro to accelerate this. How about they would call this real-time tracing?

:-) :-)

By "printf" I don't necessary mean actually formatting the output into text on the embedded device.

As it happens, I'm implementing printf() for OpenCL for a GPU at the moment. I'm having the code on the GPU just shove the id of a printf format string into a buffer, followed by the integer or fp or vector data in binary. Quick and easy. When the kernel finishes the driver on the host computer retrieves the buffers, looks up the printf format strings, and formats the output to stdout.

It is, however, important that the programmer selects the most useful points at which tracing data is sent. Sending, say, the PC (and/or opcode) and result of every instruction is both overwhelming and unnecessary. Watchpoint registers are useful but always limited and expensive, so I tend to prefer explicitly inserting code into the program if the timing requirements are not ridiculous and program build/load turnaround is not too long.
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2881
  • Country: 00
Re: Programming tools for Arduino and Teensy
« Reply #21 on: June 28, 2017, 11:57:11 am »
100% agree. Real-time tracing (e.g. ETM) is only worth it if the timing or throughput requirements are strict. Due to the dedicated hardware they can offer less of a performance hit and higher throughput (I think some can do up to a few hundred MB/s). It is typically something only supported by the $$$ versions of debuggers and IDEs. I think the free OpenOCD/Eclipe stack at best supports dumping the raw data from SWO (the lowest end version of the ARM tracing block), using it as a faster printf that does not require a UART/CDC.



Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf