PCB

Arduino is a great way to start writing code for microcontrollers, like the venerable ATMega328P used in the Arduino Uno and Nano. With loads of easy to understand examples, organised into categories, it makes it easy to get started. Changing from an Arduino Uno to a Mega when you need more IO or resources is as easy as a drop down menu, even moving to an ARM based platform is pretty straight forward. I learnt embedded programming by using the Arduino IDE and environment, and this even helped me land my first engineering job.

Arduino is great for starting out, but can quickly become limiting. The most annoying thing I find with the Arduino IDE is the lack of autocomplete!

Autocomplete

What is autocomplete? Instead of having to remember or copy paste every variable or function you use, autocomplete allows you to just type the first 3 or 4 letters, then you get a drop down of all the options that match. This is very important for classes, where you may not remember all the members or methods, or their names.

Terrible search

Arduino search

Finding everywhere in your code where you have used a certain variable or function is very important for debugging, and understanding your own code the next day when you’ve forgotten everything! The search functionality in Arduino highlights each occurrence of your search term one by one. (Qt search slide) Most IDE’s search by showing a list of the occurrences of your search term, allowing you to go straight there by clicking the line, and easily seeing the context it’s used in and how many times.

Arduino teaches you bad habits

No classes

Arduino encourages you not to create classes, and instead to separate code out into multiple “tabs”, which Arduino just appends to one another. This can produce very hard to solve bugs, where one tab doesn’t know about the functions in another tab, and therefore can’t use them!

No structure

Human brains are great at solving problems, but not so great at holding lots of information all at once, or at least mine isn’t! In any moderately complex code project, it becomes important to structure your code well so that it is easy to break up the complexity into different functions and classes, each responsible for a specific job. As covered later, Arduino doesn’t encourage this important structure in your code.

Reliance on libraries

Arduino is great because of all the libraries that come with it, or that can be installed. This is great for quickly creating a project that uses an LCD, reads from a complex sensor, and saves that data to an SD card. The problem comes when you can’t find a library that does what you need, or that library has bugs or doesn’t do everything you need. Libraries are great, and I certainly don’t suggest you go and write your own FAT32 and SD card library, no matter how good you are! In industry, it can often be valuable to write your own libraries of code for common functions, or specific sensors that you use across multiple products.

Lack of debugging

The Arduino IDE does not support any kind of debugging, and using Serial.print statements is not debugging! A proper debugger, like GDB, allows you step through your code one line at a time, insert break points to stop the code execution at, and inspect variables, memory, and even registers. This can be critical for quickly debugging code.

Implicit variable sizes

Arduino encourages the use of variable types such as “int” and “long”. On an 8 bit platform, such as AVR based Uno, an “int” is a 16 bit signed (positive and negative) integer, however on a 32 bit platform, such as an ARM, an “int” is 32 bits! This can lead to very hard to find bugs when moving to a different platform. In industry, the use of “int” is highly discouraged for this reason. On an 8 bit platform, using a 16 or 32 bit integer has a performance penalty, so if you’re writing a “for” loop which only needs to iterate over 100 items, using an “int” is wasteful if a byte would suffice. Explicit variables such as uint8_t or uint16_t are better, as they are always 8 or 16 bits long as specified.

No easy way to make classes

When using C++, classes are essential to structure and isolate your code. Arduino makes it harder to create classes, and doesn’t provide a nice easy way to do so like most other IDEs do.

Difficult to collaborate

Most of the time that you’re using Arduino, you’re probably just writing code for yourself. If you want to collaborate with other engineers however, it can start to become a bit of a pain when you’re using libraries other than what come included with Arduino. This is because you have to manually install each library you want to use. When working with others, or in industry, this can quickly become a problem because each engineer has to manually install each library and make sure the versions are the same!

Difficult to navigate large projects

When working on larger projects, with lots of classes, it can be difficult to navigate around. The two main features that I miss compared to other IDE’s are the ability to control click on a function call, and be taken straight to the code for that function, and the left sidebar. Most IDE’s arrange the project by using a sidebar on the left of the screen showing all the source files, making it easy to open and navigate around.

Hard to automate building

Due to the difficulty of using third party libraries, and the complexity that Arduino hides from you, it can be difficult to automate building code. Why would you want to automate building code? Suppose that you’re working on a large project with other engineers. It can be advantageous to automatically build and maybe test the code every time someone commits a change to the code. This can be valuable to find and stop the age old “it works on my machine” problems!

Hides complexity

The great thing about Arduino is that it hides a lot of the complexity and lets you just get on and write code. The bad thing about Arduino is that it hides a lot of the complexity, so you don’t know whats going on under the hood, and therefore can’t easily learn about it! In industry, it is important to understand how all this works, to solve problems with the build process and to modify it for your needs, such as specifying where libraries are.

 

What a good IDE should provide

Autocomplete

A good IDE should provide a good autocomplete mechanism, saving the programmer remember the exact name of a function or variable.

Easy to create classes

Classes should be easy to create, usually from a menu option allowing you to specify the class name, the file name, and if the class inherits functionality from another class.

Good search

Qt Search

As mentioned earlier, a good IDE will allow you to search for instance of a variable or function easily, providing you with a list of occurrences, and to easily navigate that list, as well as easily rename instances of a variable or function.

Help to automate building

Making it easy to automate building code can be very useful for larger projects with multiple engineers working on it. This can be done by using command line utilities, and can be paired with an automated build system such as Jenkins or bitbuckets pipelines.

Easy to reproduce

To allow engineers to easily work on code, it is important that the exact same code is produced when different engineers on different computers, and even different operating systems, check out and try to build the code. To do this, any libraries used must be the exact same version, and downloading those libraries should be automated. Ideally, libraries should be handled by your source control systems (git or SVN), or a package manager.

Debugging

Using a debugger is sometimes the only way to find a bug, single stepping through the code or inspecting all the variables used. This requires integration with the IDE, as well as a hardware debugger, such as a JTAG interface.

Other options:

PlatformIO

PlatformIO is a great system for developing embedded code. I have used it myself in industry, and highly recommend it for both hobby and commercial development, and it’s free! Some of the features it provides are:

  • Unified debugger that works across multiple architectures
  • Cross platform build system, Mac, Linux, and Windows.
  • Intelligent autocomplete
  • Automatic download and version control of third party libraries
  • Automatic download of the tool chain for building code! First time building for ARM? PlatformIO will automatically download all the tools required!
  • Command line options and utilities for automated build systems
  • Works with most IDEs, but works best for VSCode and also Qt Creator (my favourite IDE ever!)
  • All configured from a text file

Atmel Studio

Atmel Studio is created by Atmel (now Microchip), and is specifically made for their 8 bit AVR and 32 bit ARM architectures. It has support for all the hardware debugging tools, a great AVR simulator, and lots of libraries to drive the hardware. Some of the features are:

  • Great debugging support
  • Great autocomplete
  • IDE based on Visual Studio, which is a good IDE, but Windows only unfortunately
  • Many example projects and libraries available
  • Simulation of lots of the hardware and how it works
  • Great documentation built in
  • Easy import of existing Arduino projects

Eclipse

Eclipse is a popular and widely used IDE, that can be configured to write and build code for just about any language, and pro and a con! Eclipse can be somewhat difficult to use however, due to all the options available. Plugins or IDEs based on Eclipse, such as Sloeber, can help the process, but I’ve found Sloeber to be unreliable, quite clunky, and does not provide much in the way of debugging or support for automated build systems.

Custom toolchain

If you really want, you can create your own build environment using pretty much any IDE you want, by using the free tool chains like AVR-GCC. Some really large projects may benefit from this approach, as it allows complete control over the whole process, but also means you have to do pretty much everything yourself! For the hobbyist, I would not recommend this approach, although it can be great to learn how it all works.

 

Arduino is great for getting started, but can quickly become limiting as you progress. I would highly recommend starting out with PlatformIO and VSCode as soon as possible, as it can be harder to convert or import projects once they get bigger. The time savings from using a good IDE will soon pay for themselves, in terms of the time to get setup with PlatformIO.

Please checkout the awesome PlatformIO project, and give it a try! https://platformio.org/