Friday, December 9, 2011

Initial Review – Arduino v1.0 IDE

Hello Readers

Recently the Arduino team have released version 1.0 of the IDE (integrated development environment) that we all know and love. This is a significant milestone as the IDE has previously been in alpha release since 2005. For the platform to have survived and thrived this long is a credit to the community and especially to the Arduino team themselves. So moving forward, let’s have a look and see what has changed.

Installation is quite simple. As always, download the IDE from the Arduino website. Before installing the new version, copy and backup your sketchbook folder and the entire folder system of your current IDE installation. This shouldn’t take long as … I’m sure everyone does this on a regular basis. The move to v1.0 is a major one, and you will still need to use the older IDE – so don’t delete it from your computer.

Once installed, copy over the contents of your ../arduino-002x/libraries folder to the new ../arduino-1.0/libraries folder. When your operating systems pauses and asks what to do with duplicate folders, click “skip”. That is, don’t overwrite the new libraries with old ones.

Now run the new IDE, and you will be presented with the following (note we have already loaded the “blink” example):

The cosmetic changes in the design of the tool bar are slight yet refreshing. The buttons in order are: verify (we used to call this “compile”), upload sketch, file new, file open, file save and the serial monitor button has been moved across to the far right.

At the very bottom-right of the IDE window the board type and port connection is displayed – which is great if you are working with more than one Arduino board at once – a nifty feature. Furthermore when verifying and uploading a sketch, a progress bar appears at the top right of the message window, for example:

The last cosmetic change that became apparent is the automatic creating of hyperlinks in the sketch when the IDE detects a correctly-formatted URL, for example:

Cosmetic changes are all well and good, however that is only the tip of the iceberg. For starters, the file extension for sketches compatible with v1.0 is now .ino.

The next thing is to review the update release notes, also listed below with my own notes – where a lot of surprises can be found. As listed below, several functions and libraries have changed in behaviour or existence. Therefore some work may be required to convert sketches from v23 IDE to v1.0. At the current time I can’t see any reason to do this, and if you have any projects relying on existing libraries – make a backup copy of your existing environment in case the original source of the library disappears. The Arduino team have mentioned the idea of a centralised repository for libraries, however this has not been finalised at the time of writing this article.

[core / libraries]  * Serial transmission is now asynchronous - that is, calls to Serial.print(), etc. add data to an outgoing buffer which is transmitted in the background. Also, the Serial.flush() command has been repurposed to wait for outgoing data to be transmitted, rather than dropping received incoming data.  * The behavior of Serial.print() on a byte has been changed to align it with the other numeric data types. In particular, it will now print the digits of its argument as separate ASCII digits (e.g. '1', '2', '3') rather than a single byte. The BYTE keyword has been removed. To send a single byte of data, use Serial.write() (which is present in Arduino 0022 as well).

The new Serial.print() behaviour is interesting. Let’s compare the output of the following sketch:

void setup() { Serial.begin(9600); }
byte a=0;
void loop() { for (a=38; a<48; a++) { Serial.print(a); Serial.print(" "); } do {} while (1>0); }

Using IDE v23, the output from the serial monitor is:

However when we run the same sketch in IDE v1.0, the output is:

So if you need the actual ASCII characters represented by the BYTE variable, use Serial.write() not Serial.print().

* The Serial class (as well as other classes inheriting from Stream, like EthernetClient, SoftwareSerial, Wire and more) now contains functions for parsing incoming data, based on the TextFinder library by Michael Margolis. They include find() and findUntil() to search for data, parseInt() and parseFloat() for converting incoming characters into numeric values, and readBytes() and readBytesUntil() for reading multiple bytes into a buffer. They use a timeout that can be set with the new setTimeout().

Well this is interesting. The ability to parse incoming serial data will make using that nefarious GSM shield easier…

* The SoftwareSerial class has been reimplemented, using the code originally written for the NewSoftSerial library by Mikal Hart. This allows for multiple simultaneous instances, although only one can receive at a time.

One less library to worry about…

* Support has been added for printing strings stored in flash (program memory) rather than RAM. Wrap double-quoted strings in F() to indicate that they should be stored in flash, e.g. Serial.print(F("hello world")).

This should help us use memory more efficiently…

* The String class has been reimplemented as well, by Paul Stoffregen. This new version is more memory-efficient and robust. Some functions which previously returned new string instances (e.g. trim() and toUpperCase()) have been changed to instead modify strings in place.  * Support for DHCP and DNS has been added to the Ethernet library, thanks to integration by Adrian McEwen. Most classes in the Ethernet library have been renamed to add a "Ethernet" prefix and avoid conflicts with other networking libraries. In particular, "Client" is now "EthernetClient", "Server" is "EthernetServer", and "UDP" is "EthernetUDP". A new IPAddress class makes it easier to manipulate those values.

Frankly I’m not a genius when it comes to the Internet area, however clearer naming is a plus :)

* The UDP API has been changed to be more similar to other libraries. Outgoing packets are now constructed using calls to the standard write(), print(), and println() functions – bracketed by beginPacket() and endPacket(). The parsePacket() function checks for and parses an incoming packet, which can then be read using available(), read(), and peek(). The remoteIP() and remotePort() functions provide information about the packet’s origin. (Again, thanks to Adrian McEwen for the implementation.)  * The Wire library has also been modified to use the standard read() and write() functions instead of send() and receive(). You can also use print() and println() for outgoing data.

Looks like another mental note to make when working with I2C and v1.0

* The SD library now supports multiple simultaneous open files. It also provides the isDirectory(), openNextFile(), and rewindDirectory() functions for iterating through all the files in a directory. (Thanks to Limor Fried.)

Well this is a win, now multiple forms of data can be logged into separate files.

As mentioned at the start, this is an initial review and by all means not complete. Feel free to leave your comments or notes for others to review as well, and as always if you find any errors please let us know.

For now the new IDE is a juncture in the Arduino evolution that is welcome. For new sketches and development in general there wouldn’t be any reason not to use it, and you can happily run several versions of the IDE on a single computer. However at this time there wouldn’t be any reason not to convert older sketches to the new v1.0 standard.

Question – What does the acronym ASCII mean?

Have fun and keep checking into Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

No comments:

Post a Comment