As a guy who earns his living writing software in the corporate world, I’ve always felt a little out of place in the Arduino world.
The Arduino platform hardware and software is, to quote the Arduino home page, “intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments“.
Good artists borrow code, great artists steal code, but no artist should have to write code.
And yet most do, or at least try to. Coding is hard for beginners, and coding in C is not a great place to start. Case sensitive names, mismatched parentheses, strongly typed variables: these are the things that trip up every newcomer, and there is no getting around them. The minimalist Arduino IDE hides these issues, but it doesn’t solve them.
In fact, I feel that the Arduino IDE undermines the software side of Arduino projects by pretty much guaranteeing that beginners will quickly learn to hate programming. Writing and debugging code in the Arduino IDE is time-consuming and frustrating: a drudgery of trial and error.
It doesn’t have to be this way! Artists, designers, hobbyists: throw down your primitive tools and join the technological revolution! Behold… Arduino for Microsoft Visual Studio!!
The Reason Not to Switch
OK, let’s get this over with. Your reaction to this is probably one of 3 things:
1. Oh great, Microsoft. How much is that going to cost me?
2. Oh great, Microsoft. How long is that going to take me to learn?
3. #@*&! Microsoft!!!! You expect me to use a closed-source, over-engineered hairball sold by a shameless monopolist to cubicle-dwelling corporate drones??
The answers are:
1. Probably nothing
2. Less than you think
3. Bah, occupy this, hippy.
Clearly, I don’t have a good answer to the 3rd issue. Yes, Microsoft makes tons of money, Visual Studio is never going to be open source, and it only runs on Windows. If that’s a dealbreaker for you, then you can stop reading. You may not want to know what you’re missing.
Cost and the Learning Curve
Visual Micro’s Arduino add-on requires Visual Studio Professional, not Visual Studio Express. Back in the day, Microsoft targeted Visual Studio at large corporations, and it was priced accordingly.
Fortunately, that’s no longer true. Visual Micro’s web page has details on how you can legally get a copy of Visual Studio for free. Another option for young whippersnappers is Microsoft’s Dreamspark program for students.
Don’t worry — it’s not a trick. Over the last 10+ years, Microsoft has increasingly lowered the barrier to developers acquiring their development tools. Microsoft is not being purely altruistic here. Their motivation is to attract new developers to the
cult platform — come over to the dark side, we have candy — but the end result is that Visual Studio is a lot easier to get than it used to be.
As for the learning curve, Visual Micro has done a good job at reducing to 3 steps the process of loading/creating a sketch and uploading it to your Arduino. (I should mention that Visual Micro’s documentation is extensive — you don’t have to rely on blogs and forums to figure out how to use their product.)
Yes, Visual Studio is bristling with menus, toolbars and windows, but you can safely ignore 95% of them, just like you already do in Microsoft Word. The remaining 5% of these features will, on the other hand, save you a ton of time.
Not convinced? Let’s get into what I feel are the 6 coolest features in Arduino for Visual Studio. Most of these will be familiar to anyone who’s used Visual Studio with other languages: the cool thing is that Visual Micro has brought them to the Arduino world.
1. Code Completion
Do you ever have trouble remembering what the exact syntax of an Arduino statement is? Is it Serial.Print, or Serial.print, or Serial.Write? What are the parameters.
Yeah, us professionals have the same problem. A dirty little secret of our profession is that we tend not to memorize things unless we have to, and thanks to Code Completion in Visual Studio (and to Google), we rarely have to.
As you begin to type in a statement in Visual Studio, a pop-up list of options for completing the statement will appear. Rather than typing the whole thing, just use the arrow keys to select the one you want, then click the Tab key to fill in the rest.
When you aren’t sure which one you want, just pause at one of the options and a tooltip will appear listing the parameters that the methods takes.
2. Error Highlighting
The process of correcting typos in the Arduino IDE is a tedious grind: build, decipher the error message, figure out what line of code its referring to, take a stab at fixing the error, build, repeat….
That’s the way we professionals coded software too, 20 years ago. Then we smartened up, and put some effort into building better tools.
One result of this is on-the-fly error highlighting. Each new version of Visual Studio has got better at this, and it’s now at a point that you can fix 90% of your errors before you get to the build stage.
And, of course, it’s a lot easier to figure out which line of code is wrong when it’s underlined for you.
3. Intelligent Search
The one-result-at-a-time search feature is another area where the Arduino IDE is about 15 years behind the state of the art. Given that we’ve all learned to leverage search engines when looking for all sorts of answers, it’s puzzling that this hasn’t been improved.
There are lots of different ways to search for information in Visual Studio:
- Need to quickly review the code that uses a variable? This happens all the time: you aren’t sure whether its a string or number, or you aren’t sure what value you initialized it to, or you aren’t sure where its being read or updated in your program. In Visual Studio, just right-click and select Find All References. A window will open listing all the code that uses that variable.
- Forgotten what a variable is called? If you know part of the name, Visual Studio’s Find feature will list all the lines of code that contain a particular search string. Wildcards are supported. Double-clicking on one of the search results will bring you directly to that line of code
- You know that cool “search as you type” feature when searching for text on a web page, where the cursor automatically jumps to the first match as you type in your search term? Visual Studio has that too: just type Ctrl-I to search.
4. Libraries: My God, it’s full of code!
Libraries are the Arduino’s greatest strength. Brilliant coders have created packaged libraries to handle all the complicated stuff: reading and writing to devices, handling Strings, connecting to web sites, and so on. You don’t know how they work, and you don’t care. They just work.
Except when they don’t. When you call a library function, and it hangs, returns a generic error message, or does nothing, you’re left high and dry. What’d I do wrong? Wrong parameter? Wrong settings? Google?!!
In Visual Studio, there are a few different ways to pull back the curtain and have a good look at the library you’re using.
If you right-click on a class or function and select Find Declaration, Visual Studio will automatically load it into the editor. Often, the comments added by the coder will give you the information you’re missing. If not, have a look at the code. Don’t be intimidated: if you can write it, you can read it. Open source isn’t just a buzzword, you know?
In the Visual Studio Find In Files dialog, it you change the “Look In” field to “Current Project”, it will list all occurrences of a variables, including ones that appear in libraries. This is useful when you’re searching for a particular constant: you have an idea what you want, but you’re not sure what the exact spelling is.
Lastly, when you want to pull back and have a look at the bigger picture, the Object Browser lists everything about a library in one convenient place. The left hand pane lists all classes in the libraries that are included in your project. Selecting a class lists the functions in that class in the upper right pane. Double-clicking on a function opens the library source code and takes you to the function definition
If you really want to blow your mind, turn on the “Show All Arduino Files” option, then check the Solution Explorer. Yikes, where did all those files come from? Those have all been in your project all along, covered by Arduino’s invisibility cloak. You’ll probably want to leave the “Show All Arduino Files” setting off most of the time (I do), but it’s handy to be able to easily look through that code on the few occasions when you need to.
5. Serial Console: Not Just an Afterthought
The Arduino Serial Console has also seemed to me like something reluctantly tacked on to the software. Arduino code is supposed to “just work”. Who needs a debugger? Why bother to put work into something that nobody’s going to use?
Visual Micro did put some work into their’s, and it has several nice features that Arduino’s lacks.
First and foremost, they’ve done away with that silly limitation of having to close the Console every time you upload code to the Arduino. Debugging using print statements is hard enough: taking away that information every time you run your code is just nasty. In Visual Studio, you don’t have to close the Console, ever. When you transfer your code to the Arduino, the Serial Console quietly and automatically frees up the serial port, then reconnects when the transfer is done.
When you select some text in the Serial Console and right-click, a context menu lists all of your options: Select All, Copy, Cut, etc.. It’s a small thing, but a timesaver that any text window should have.
Another timesaver is the ability to quickly re-enter text by selecting it from a pull-down menu. Trial-and-error debugging is always a pain, but being able to enter input in one click makes the trials less painful.
6. No Java
Java is beginning to rival Internet Explorer as software that is more trouble than it’s worth. The passive aggressive auto-updater is bad enough, but malware authors are increasingly targeting Java as a means of sneaking their software onto PCs. The only Java software I run is Arduino, so replacing the Arduino IDE has a major side benefit.
A lot of newcomers to Arduino get the impression that Java is central to Arduinos; some think that the Arduino programming language is Java. In actual fact, Java and the Arduino are an odd couple. Arduinos are coded in C++, the same language Visual Studio is written in, and a language that the Visual Studio IDE has supported for 15 years . Visual Studio gets C++ in a way that a Java-based IDE cannot. Visual Micro has done an amazing job at leveraging Visual Studio’s rich support for C++ development.
Arduino for Visual Studio has actually been around for awhile now, and I’d intended to write about it back in the spring. It drifted off my radar when I stopped using the Arduino in my projects.
My main problem with the Arduino is the lack of debugger. Trial-and-error debugging is a major time-waster.
Arduino for Visual Studio popped back up on my radar recently when Visual Micro released an Arduino Debugger for beta testing. If you thought “Visual Studio for Arduino” was an odd-looking phrase, how about “Arduino Debugger”? This is a software debugger, with no need for JTAG or other hardware add-ons, something I had previously thought impossible. It’s not such a crazy notion, though. Like I said earlier, Visual Studio is closely integrated with C++, and its debugger has been connected to various C++ runtimes. Visual Micro has figured out how to connect the Arduino to it.
An Arduino debugger, integrated into Visual Studio, is a potential game-changer, something that will make it possible to do a lot more ambitious coding projects in a lot less time. I’m eager to give it a try. If you are too, head over to Visual Micro’s web site and read all about it.