Programming tools for Arduino and Teensy - Page 1
Forum section: electronics / projects

author: raptor1956
author_rank: Frequent Contributor
timestamp: June 26, 2017, 05:37:35 am
content: 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

author: MosherIV
author_rank: Super Contributor
timestamp: June 26, 2017, 07:01:39 am
content: 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

author: 3db
author_rank: Frequent Contributor
timestamp: June 26, 2017, 11:37:32 am
content: 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

author: ajb
author_rank: Super Contributor
timestamp: June 26, 2017, 11:52:08 am
content: 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.Quote from: raptor1956 on June 26, 2017, 05:37:35 amIt'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.

author: brucehoult
author_rank: Super Contributor
timestamp: June 26, 2017, 11:53:54 am
content: Quote from: raptor1956 on June 26, 2017, 05:37:35 amNote 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.

author: Ian.M
author_rank: Super Contributor
timestamp: June 26, 2017, 12:58:06 pm
content: 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 editorAtmel 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_IDEThen 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.

author: MosherIV
author_rank: Super Contributor
timestamp: June 26, 2017, 01:00:16 pm
content: QuoteAgreed. 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)QuoteDear 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 OPINIONIt is slow.It fills/divides your screen with useless little windows obscuring your editing windowItforcesyou 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 tabsThe list goes on and on and onStick to the Arduino IDE

author: brucehoult
author_rank: Super Contributor
timestamp: June 26, 2017, 02:38:38 pm
content: Quote from: Ian.M on June 26, 2017, 12:58:06 pmI 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.QuoteThere'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 saysCode: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.QuoteThis I agree with.

author: brucehoult
author_rank: Super Contributor
timestamp: June 26, 2017, 02:45:05 pm
content: Quote from: MosherIV on June 26, 2017, 01:00:16 pmAmen, brother.Eclipse, as with Windows (and VS), tries to be too magic, and hide too much of what is really happening from you.

author: Ian.M
author_rank: Super Contributor
timestamp: June 26, 2017, 02:50:02 pm
content: Quote from: brucehoult on June 26, 2017, 02:38:38 pmUnfortunately 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. SeeGammon.com.au: How to avoid the quirks of the IDE sketch file pre-preprocessingfor 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.

author: IanJ
author_rank: Unknown
timestamp: June 26, 2017, 04:10:58 pm
content: I've tried a few different approaches to Arduino programming and the nearest I got to sticking with a system was Visualmicrohttp://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.

author: rstofer
author_rank: Super Contributor
timestamp: June 26, 2017, 05:15:45 pm
content: 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.

author: DimitriP
author_rank: Super Contributor
timestamp: June 26, 2017, 07:13:16 pm
content: QuoteGet 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.

author: raptor1956
author_rank: Frequent Contributor
timestamp: June 26, 2017, 09:56:16 pm
content: 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

author: Fungus
author_rank: Super Contributor
timestamp: June 27, 2017, 08:27:20 am
content: Quote from: Ian.M on June 26, 2017, 12:58:06 pmThe 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.

author: rstofer
author_rank: Super Contributor
timestamp: June 27, 2017, 01:39:49 pm
content: Quote from: raptor1956 on June 26, 2017, 09:56:16 pmOne 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.

author: alm
author_rank: Super Contributor
timestamp: June 27, 2017, 02:58:56 pm
content: 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.

author: rstofer
author_rank: Super Contributor
timestamp: June 27, 2017, 05:39:13 pm
content: Quote from: alm on June 27, 2017, 02:58:56 pmCorrect! 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.

author: brucehoult
author_rank: Super Contributor
timestamp: June 27, 2017, 10:44:51 pm
content: Quote from: rstofer on June 27, 2017, 05:39:13 pmDitto.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 youAdding 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

author: alm
author_rank: Super Contributor
timestamp: June 27, 2017, 11:50:27 pm
content: 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.

author: brucehoult
author_rank: Super Contributor
timestamp: June 28, 2017, 11:32:15 am
content: Quote from: alm on June 27, 2017, 11:50:27 pm:-) :-)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.

author: alm
author_rank: Super Contributor
timestamp: June 28, 2017, 11:57:11 am
content: 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.