Why you don’t need your Arduino and how to use alternatives

First of all, don’t interpret this as some kind of anti-Arduino rant. I think the Arduino is a handy tool and, I think it’s great for introducing hoards of people to something they enjoy. I am not writing this because I don’t like the Arduino; I am writing this because there is no solution for every problem. Speed, flexibility, and cost would be the primary reasons not to use Arduino. There are times when you will need more than 8-bit microcontroller or a different peripheral set. If you are looking at production, even if the ATmega series does meet your needs in those areas, you may want something cheaper. The ATmega has its high points but as far as 8-bit micros go, price is not one of them.

I think that most Arduino users realize that the hardware is nothing particularly special. The part of Arduino that is usually lauded is the software environment. I have heard comments such as “It’s a lot like C but easier” or “It’s an easy to use language based on C”. Well, I have news for you. All of you have been HOODWINKED! It is not like C; it is not similar to C; IT IS C. Well, it’s actually even harder than C; it’s C++, which is a bit odd for the 8-bit space. The Arduino IDE is not even a preprocessor. When you compile an Arduino program, your code is taken completely unmodified and compiled directly with AVR-GCC (the open source AVR compiler). I know what you’re thinking; it’s like the Twilight Zone. Here you’ve been, shaking in your Nikes at the thought of the vast and scary world of big-boy microcontrollers, not knowing that the whole time you were already in it. You have already been using the standard open-source AVR tool suite, you just displaced AVR studio with the Arduino IDE. There is a tutorial about how to compile your project outside if the Arduino IDE on their website here.

So why does anyone care about Arduino? The magic of Arduino is in the library that comes with it. It is a set of source files that is included with your project when it is compiled. You are free to look at those files, they can be found inside the Arduino directory under hardware\arduino\cores\arduino. Essentially, these files contain a set of functions that hide special function register access from you. SFRs are locations in memory that do things in addition to just storing data. For example, the SFR register assigned to an I/O port would make the pins go high or low when you wrote to it. That’s it; writing to registers is everything that separates you from programming for any microcontroller you want.

Guess what else? The Arduino library, being high level and all, could just as easily be written for any other microcontroller. That means, assuming you didn’t access registers directly, that all of your existing Arduino code can be used as-is on any microcontroller you want. All you have to do is write the functions you used for the new platform. For example, on a PIC, the digitalWrite function might look something like this:

void digitalWrite(unsigned char pin, unsigned char val)
{
   if (pin < 8)
   {
     if (val)
         LATA |= (1 << pin);
     else
        LATA &= ~(1 << pin);
    }
}

There are times when you should think about accessing the SFRs yourself, even if you don’t need a different platform. Take, for example, this line of code that sets pin 1 of ATmega port D high:

PORTD |= 2;

Literally, that line includes at least three instructions: read the value of PORTD, do a logical OR with the result and the value 2 (10 in binary), then write that result back to the port. However, AVR-GCC knows what you want and it will compile that into a single instruction that takes two clock cycles to execute. You can learn something about that here. Now, let’s consider the Arduino alternative:

digitalWrite(1,1);

Assuming AVR-GCC does not automatically inline the digitalWrite function (it is not declared inline), that will take about 16 cycles. The Arduino library was written for usability and development time, not for performance. In this case, accessing the register directly results in a 8x performance improvement.

If you are already using Arduino but you decide you want to be able to program microcontrollers in C, you will need to learn two things, neither of which should take you very long. The first thing is some additional semantics of C. You’ll need some basic knowledge of includes, defines, etc. I think this tutorial is very good but there are many. The second thing is how to handle bit manipulation in C. For example, you’ll want to know how to set the fourth bit of a byte to 1. You can find a tutorial on that here.

Don’t throw out your Arduino. It’s a good thing to have. On the other hand, if you haven’t branched out, you are like a tourist who travels all the way to China just to see the airport. Sure, the airport is great but now that you’ve come all that way, you might as well step outside.

  1. One important point that you are missing out is that Arduino is not just the software library, its a complete standardized micro-controller board and development environment. It’s pretty easy for anyone to plugin any thirdparty library as well as module [called shield] into it. The ease of developing on it makes it a strong point for all the hobby projects, which is what it is aimed for. However, I do agree with your point that people should explore beyond Arduino. Of course, only when it makes sense for them.

      • cafeadmin
      • January 9th, 2011

      Sure, anytime a group of people agree on something it makes it easier for all of them. Therein lies the handicap though, lack of flexibility. I am aware of the extensibility. In fact, this post was prompted by my experience writing a third party library (S1D13700). My point was not to assert that the only thing good about Arduino is an AVR library. I wasn’t trying to asses the value of Arduino. I was trying to point out, to people that might otherwise not know, that it a short leap from Arduino to developing on any microcontoller platform.

    • Wilmotron
    • March 30th, 2011

    I just wanted to drop a comment here and note you’re right on all points, my friend. I have yet to step out into other microcontrollers, but I feel confident that it’s only a step away. In a project I’m writing that will go into production, I’ve replaced many of the Arduino library functions with my own to serve different needs. If nothing else, the source files for the Arduino environment are a great template for learning responsible microcontroller programming habits and which registers to look for when you’re scanning design documents, which I feel is by far the hardest part of programming directly for the microcontroller: coding is easy but deciphering design documents aimed at a specific, well-entrenched audience is tough.

    • Chris
    • March 28th, 2012

    Maybe you are right on all (detail) points, but you are also completely wrong in the message : actually, even Wilmotron above admits he has “yet to step out”. Maybe he never will. I’ll try to tell you why :

    The strength of Arduino is actually twofold : it’s the strength of Processing/Wiring, that makes both C and electronics available to everybody without any hassles of C or electronics, combined with the strength of a very open and very copied set of simple boards, available to everybody for a low enough price.

    Why does it matter ? Because this unique combination brings the threshold low enough for non-engineers to start playing with it like they would play on their mobile or PC.

    I bought a Pinguino and an ARM board, and those simply are much more difficult to use, because the documentation/support/package/library/community/reliability/website/… is vastly inferior. Only Arduino made me getting started in less than one hour.

    Sure, nothing is perfect, but thnik about it : DigitalWrite (13, ON) works everywhere, and who cares about number of cycles if you put a delay(2000) anyway.

    • Greg
    • December 29th, 2012

    I ordered it (uno) because it was the best device to get me out of the Athena series from Kronos robotics and teach me about c.

    • John Canty
    • June 30th, 2013

    I like the arduino, I dislike the IDE and I really dislike the IDE options for MAC. But Point taken, there is a short path from arduino to other microcontrollers. I myself have moved into attiny microcontrollers for the learning experience.

    • baron neat john
    • July 31st, 2013

    Very wise words!
    I liked it. I’m going outside the airport right now.

  2. HallÃ¥ – Du är ju hur kul som helt!Och visst är vi alla lik…aganska…Jag har taggat dig, hoppas Du vill vara med:)

  1. May 26th, 2014
  2. July 21st, 2014
    Trackback from : Promo Codes For Nordstroms
  3. September 30th, 2014
    Trackback from : web designer job outlook