Embed With Elliot: There Is No Arduino “Language”

This installment of Embed with Elliot begins with a crazy rant. If you want to read the next couple of paragraphs out loud to yourself with something like an American-accented Dave-Jones-of-EEVBlog whine, it probably won’t hurt. Because, for all the good Arduino has done for the Hackaday audience, there’s two aspects that really get our goat.

(Rant-mode on!)

First off is the “sketch” thing. Listen up, Arduino people, you’re not writing “sketches”! It’s code. You’re not sketching, you’re coding, even if you’re an artist. If you continue to call C++ code a “sketch”, we get to refer to our next watercolor sloppings as “writing buggy COBOL”.

And you’re not writing “in Arduino”. You’re writing in C/C++, using a library of functions with a fairly consistent API. There is no “Arduino language” and your “.ino” files are three lines away from being standard C++. And this obfuscation hurts you as an Arduino user and artificially blocks your progress into a “real” programmer.

(End of rant.)

Let’s take that second rant a little bit seriously and dig into the Arduino libraries to see if it’s Arduinos all the way down, or if there’s terra firma just beneath. If you started out with Arduino and you’re looking for the next steps to take to push your programming chops forward, this is a gentle way to break out of the Arduino confines. Or maybe just to peek inside the black box.

Arduino is C/C++

Click on the “What is Arduino” box on the front page of arduino.cc, and you’ll see the following sentence:

“ARDUINO SOFTWARE: You can tell your Arduino what to do by writing code in the Arduino programming language…”

Navigate to the FAQ, and you’ll see

“the Arduino language is merely a set of C/C++ functions that can be called from your code”.

Where we come from, a bunch of functions written in a programming language is called a library. So which is it, Arduino?

(The Language Reference page is a total mess, combining parts of standard C with functions defined in the Arduino core library.)

Maybe that’s not as sexy or revolutionary as claiming to have come up with a new programming language, but the difference matters and it’s a damn good thing that it’s just a set of libraries. Because the beauty about the Arduino libraries is that you don’t have to use them, and that you can pick and choose among them. And since the libraries are written in real programming languages (C/C++), they’re a totally useful document if you understand those languages.

C and Assembly language, on the other hand, are different languages. If you’re writing assembler, you can easily specify exactly which of the chip’s native instructions to use for any particular operation — not so in C. Storing data in particular registers in the CPU is normal in assembler, but heroic in C. So if you start out writing your code in C, and then find out that you need some of the features of assembler, you’re hosed. You stop writing in C and port all your code over to assembler. You have to switch languages. You don’t get to pick and choose.

(Yes, there is inline assembler in GCC.  That’s cheating.)

This is not at all the case with Arduino: it’s not a programming language at all, and that’s a darned good thing. You’re writing in C/C++ with some extra convenience libraries on top, so where the libraries suck, or they’re just plain inconvenient, you don’t have to use them. It’s that simple.

A prime example is digitalWrite() in the Arduino’s core library, found in the “wiring_digital.c” file. It’s madness to use the ridiculously slow digitalWrite() functions when speed or timing matters. Compared to flipping bits in the output registers directly, digitalWrite() is 20-40x slower.

scopes_blinkingThe scope shots here are from simply removing the delay statements from the Blink.ino example code that comes with Arduino — essentially toggling the LED pin at full speed. Upper left is using digitalWrite() to flip the pin state. Upper right is using direct bit manipulation in C: PORTB ^= (1 << LED_BIT); Because Arduino’s digitalWrite() command has a bunch of if...then statements in it that aren’t optimized away by the compiler, it runs 28 times slower.

(And worse, as you can see in the lower left, the Arduino code runs with occasional timing glitches, because an interrupt service routine gets periodically called to update the millisecond timer. That’s not a problem with digitalWrite() per se, but it’s a warning when attempting tight timing using the Arduino defaults.)

OK, so digitalWrite() is no good for timing-critical coding. If Arduino were a real language, and you were stuck with digitalWrite(), you wouldn’t be able to use the language for anything particularly sophisticated. But it’s just a convenience function. So you can feel free to use digitalWrite() in the setup() portion of your code where it’s not likely to be time critical. That doesn’t mean that you have to use it in the loop() portion when timing does matter.

And what this also means is that you’re no longer allowed to say “Arduino sucks”. Arduino is C/C++, and at least C doesn’t suck. (Zing! Take that, C++ lovers. De gustibus non disputandem est.) If you think that some of the Arduino libraries suck, you’re really going to have to specify which libraries in particular you mean, or we’ll call you out on it, because nobody’s forcing you to use them wholesale. Indeed, if you’re coding on an AVR-based Arduino, you’ve got the entire avr-libc project baked in. And it doesn’t suck.

The “.ino” is a Lie

So if Arduino is just C/C++, what’s up with the “.ino” filetype? Why is it not “.c” or “.cpp” like you’d expect? According to the Arduino build process documentation,

“The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler.”

True C/C++ style requires you to declare (prototype) all functions that you’re going to use before you define them, and this is usually done in a separate header “.h” file. When C compiles your code, it simply takes each function and turns it into machine code. In a philosophically (and often practically) distinct step, references to a function are linked up with the compiled machine code representing them. The linker, then, only needs to know the names of each function and what types of variables it needs and returns — exactly the data in the function declaration.

Long story short: functions need prior declaration in C, and your “.ino” code defines setup() and loop() but never declares them. So that’s one thing that the Arduino IDE does for you. It adds two (or more, if you define more functions in your “.inos”) function prototypes for you.

The other thing the IDE’s preprocessor does is to add #include "Arduino.h" to the top of your code, which pulls in the core Arduino libraries.

blink_loop

(And then, for some mysterious reason, it also deletes all comments from your code, making it harder to debug later on. Does anyone out there know why the Arduino IDE does this?)

So that’s it. Three lines (or maybe a few more) of very simple boilerplate separate a “sketch” from valid C/C++ code. This was presumably done in the interest of streamlining the coding experience for newbies, but given that almost every newb is going to start off with the template project anyway, it’s not clear that this buys much.

On the other hand, the harm done to the microcontroller newbie is reasonably large. The newb doesn’t know that it’s actually C/C++ underneath the covers and doesn’t learn anything about one of the most introductory, although mindless, requirements of the language(s): function declarations.

When the newb eventually does want to include outside code, the newb will need to learn about #include statements anyway, so hiding #include "Arduino.h" is inconsistent and sets up future confusion. In short, the newb is blinded from a couple of helpful learning opportunities, just to avoid some boilerplate that’s templated out anyway.

Write C++ Directly in the Arduino IDE

And if you don’t believe that Arduino is C/C++, try the following experiment:

  1. Save a copy of the example Blink project.
  2. Go into the “sketch’s” directory and copy Blink.ino to Blink.cpp.
  3. Re-open the project in Arduino and delete everything from Blink.ino
  4. Add the required boilerplate to Blink.cpp. (One include and two function declarations.)
  5. Verify, flash, and whatever else you want.

You’ve just learned to write C/C++ directly from within the Arduino IDE.

(Note: for some reason, the Arduino IDE requires a Blink.ino file to be present, even if it’s entirely empty. Don’t ask us.)

main.cpp

So if Blink.ino turns into Blink.cpp, what’s up with the setup() and loop() functions? When do they ever get called? And wait a minute, don’t all C and C++ programs need a main() function to start off? You are on the path to enlightenment.

Have a look at the main.cpp file in hardware/arduino/avr/cores/arduino.

maincpp3

There’s your main() function! And although we’ve streamlined the file a little bit for presentation, it’s just about this straightforward.

The init() function is called before any of your code runs. It is defined in “wiring.c” and sets up some of the microcontroller’s hardware peripherals. Included among these tasks on the AVR platform is configuring the hardware timers for the milliseconds tick and PWM (analogOut()) functions, and initializing the ADC section. Read through the init() function and the corresponding sections of the AVR datasheet if you’ve never done any low-level initializations of an AVR chip; that’s how it’s done without Arduino.

And then we get to the meat. The setup() function is called, and in an endless for loop, the loop() function is continually called. That’s it, and it’s the same code you’d write in C/C++ for any other microcontroller on the planet. That’s the magic Arduino setup() and loop(). The emperor has no clothes, and the Wizard of Oz is just a pathetic little man behind a curtain.

If you want to dig around more into the internals of the Arduino core library, search for “Arduino.h” on your local install, or hit up the core library on Github.

The Arduino Compile Phase

So we’ve got C/C++ code. Compiling it into an Arduino project is surprisingly straightforward, and it’s well-documented in the Arduino docs wiki. But if you just want to see for yourself, go into Preferences and enable verbose logging during compilation. Now the entire build process will flash by you in that little window when you click “Verify”.

It’s a lot to take in, but it’s almost all repetitive. The compiler isn’t doing anything strange or unique at all. It’s compiling all of the functions in the Arduino core files, and putting the resulting functions into a big (static) library file. Then it’s taking your code and this library and linking them all together. That’s all you’d do if you were writing your own C/C++ code. It’s just that you don’t know it’s happening because you’re pressing something that looks like a play button on an old Walkman. But it’s not rocket science.

There is one more detail here. If you include a library file through the menu, and it’s not part of the core Arduino libraries, the IDE locates its source code and compiles and links it in to the core library for you. It also types the #include line into your “.ino” file. That’s nice, but hardly a deal-breaker.

If you’d like to see this build process in the form of a Makefile, here’s (our) primitive version that’s more aimed at understanding, and this version is more appropriate for production use.

Next Steps

If the Arduino is the embedded electronics world’s gateway drug, what are the next steps that the Arduino programmer should take to become a “real” embedded programmer slash oil-burning heroin junkie? That depends on you.

Are you already good at coding in a lower-level language like C/C++? Then you need to focus on the microcontroller-specific side of things. You’re in great shape to just dive into the Arduino codebase. Try to take a few of the example pieces, or even some of your own “sketches” and look through the included Arduino library’s source code. Re-write some simple code outside the IDE and make sure that you can link to the Arduino core code. Then replace bits of the core with your own code and make sure it still works. You’ll spend half of your time looking into the relevant micro’s datasheet, but that’s good for you.

Are you comfy with electronics but bewildered by coding? You might spend a bit of time learning something like C. Learn C the Hard Way is phenomenal, and although it’s aimed at folks working on bigger computers, it’s got a lot of the background that you’ll need to progress through and beyond the Arduino codebase. You’re going to need to learn about the (relatively trivial) language conventions and boilerplatey stuff to get comfortable in straight C/C++, and then you can dig in to the Arduino source.

Wherever you are, remember that Arduino isn’t a language: it’s a set of libraries written in C/C++, some of them really quite good, and some of them (we’re looking at you EEPROM) simply C++ wrappers on the existant avr-libc EEPROM library. And that means that for every Arduino project you’ve written, you’ve got the equivalent source code sitting around in C/C++, ready for you to dig into. Thank goodness they didn’t invent their own programming language!

157 thoughts on “Embed With Elliot: There Is No Arduino “Language”

  1. /TIC
    NO, STOP !!!!!
    Is it too late to get this posting deleted !!!

    Don’t tell these people that they are coding, are you nuts !!

    Its like telling your brother he is a chef, just because he can boil water.

    Once people learn that they have been coding all this time, they will drop this hobby.

    WHY, you ask ?

    Because engineering is too hard for a Liberal Arts types.
    Girls can’t code, they have been taught this through out history !

    No, keep telling them all they are writing sketchs ( or what ever they call them).

    That way they won’t give up and say its just too hard for a poor kid like me.
    /TIC

  2. Great writeup. I find it to be the gateway drug, and look forward to learning more and getting down to the basics of microcontroller programming. I would expect that digging into the libraries and writing to raw c code streamlines the functionality….and the more streamlined the project is, the less problems you can expect.

    Thanks.

    1. Arduino was my gateway into programming :)
      but I did a bit more research then a normal person would do,
      and found it to be just c/c++ so I started learning that,
      and soon after started doing bare-metal programming on the avr’s :)
      I do Program using the Arduino libraries sometimes,
      cause it’s nice and easy, and sometimes handy to work out an idea.

  3. Yea, this is flat out wrong. You aren’t coding, these are sketches; to relate this to drawing, you aren’t creating the tools to make the art, you are just using pre-created tools to make the art, exact same situation with Arduino. I can see how Arduino isn’t a language, but you are barely writing in C++, so much to the point that writing Arduino sketches is basically another language. You are just using libraries and very simplified method calls.

    The atmosphere Arduino makes isn’t, “I have to learn about what I need and then implement it so I can use it”, it is, “Oh I need this? Hopefully somebody else has created a library for it!”

    Stop telling Arduino users that they are coding, it encourages a culture of writing crappy C++ code. There IS a right way and a wrong way and Arduino doesn’t do anything to help show the difference.

    1. I think the whole point of Elliot’s exploration is to get us out of the rut where we’re telling people that they’t not coding, they’re sketching. This is a different type of barrier where people then think “I can’t code, all I’ve ever done is screw around with Arduino”.

      Instead let them know that coding is easy. But great coding takes practice, study, talent, and interest.

      In closing, “crappy C++ code” will always be written. Hiding the fact that people are writing C++ won’t help that. But educating them to encourage learning more about the language might.

      1. I can’t agree more. I went to school, but struggled with a lot of C++ coding. I ran across AutoHotKey in the windows environment a while back which is essentially a macro writing “language” that is nothing more than some nicely simplified libraries for C++. It’s not the fastest or must efficient by far, but it does make putting together a program with menus and a GUI pretty easy for someone.

        I think Arduino is similar (except there s a more comprehensive IDE available for AHK) in that you are coding, but it simplified for people that don’t need the fastest or most efficient code.

        The problems I see is that a LOT of Arduino example sketches and libraries are poorly commented and documented. when you want to change things, it’s really hard to figure out the correct function call in a library to perform.

        Telling people they aren’t coding isn’t really a solution. Proper coding technique should always be used even if your comments are 10x the side of the code.

        1. AHK is great and was much more approachable for me too. I’ve saved countless hours of work (at work) because of it.
          C++ was a tougher nut to crack but with a class of it at uni and some time to let it sink in, it is now easy enough for me.

        2. Really? I see a similar problem on many of these… ahem sketches that I do with PHP as opposed to AHK. That many of the people don’t know HOW to write good code, period.

          Comments aside, I’ll see dumb little things like decrementing counters inside loops that have an incrementing (and unused) counter. Just use the same decrementing counter for the loop or rearrange your code to use the incrementing counter instead.

          Or a common problem with Ardurino fans, last I checked, is strings and string manipulation. A) they don’t realize how C manages strings B) they don’t know how to store immutable strings properly (hint, don’t bother copying them to RAM) and C) have absolutely no clue how to pack, reduce, or reuse their strings.

          The Analog functions are (were?) a mess. I was handed a sketch to fix and the Analog functions were so hard to unravel that I simply threw away the entire mess and rewrote it all.

          At least Arduino isn’t as bad as PHP. Arduino invites bad code and rarely punishes the user for it. PHP begs, pleads and demands bad code and punishes you to your face and stabs you in the back.

  4. Yea, this is flat out wrong. You aren’t coding, these are sketches; to relate this to drawing, you aren’t creating the tools to make the art, you are just using pre-created tools to make the art, exact same situation with Arduino. I can see how Arduino isn’t a language, but you are barely writing in C++, so much to the point that writing Arduino sketches is basically another language. You are just using libraries and very simplified method calls.

    The atmosphere Arduino makes isn’t, “I have to learn about what I need and then implement it so I can use it”, it is, “Oh I need this? Hopefully somebody else has created a library for it!”

    Stop telling Arduino users that they are coding, it encourages a culture of writing crappy C++ code. There IS a right way and a wrong way and Arduino doesn’t do anything to help show the difference.

    1. Every programmer uses pre-created tools all the time. The choice of what abstraction layer you work at is mostly arbitrary. Even Assembly (especially on x86, but really just about anywhere) should be considered a high-level language these days.

  5. I still have trouble calling sketches C++, C yes with some limited C++ functionality (objectality?). I know a few phrases in French but I don’t call myself bilingual.

    1. I simply must tell a joke at this point.

      Q: what do you call someone (in english) who speaks 3 languages? A: trilingual
      Q: what do you call someone who speaks 2 languages? A: bilingual
      Q: what do you call someone who speaks 1 language? A: an american

      (laugh. its funny. and a little bit true).

      1. Most people who take up a second language choose English – and there’s a reason for that. And it’s my observation that most people who say they speak another language really do not. They know enough to answer “Do you speak English?” with a smile and a bashful “Yes” and after that… Nada!

    2. I know right!? Arduino “C++” is really just like a stripped down C++, practically just C but with classes. It has no support whatsoever for anything like flexible declarations, new, delete, scoping, or even function overloading. Wait…is there a “g++” at the end of that “avr-“?

      1. “no support whatsoever for … even function overloading.” – Where did you get that idea? Overloading is implemented and is used pretty extensively by the Arduino core (in particular, by Print())

  6. I throw out the whole Arduino ide and library right into the thrash a few days after I bought my first arduino. Seriously, the ide is totally inconvenient and the functions in the library are messed up like hell. And for what? Nothing. It just calls gcc+avrdude and that’s all. Well I can also do that, thank you very much. Just download WinAVR, it’s the same thing, except it doesn’t take years to unzip. And for the editor, I like to use something that’s actually useful, and not slowing me down. (e.g. notepad++) I would rather program in vi on a 80*25 char monochrome screen than to use arduino ide.

    So the arduino ide is not, repeat, NOT coding. It’s just playing with electronics for 8-year-olds. If you want to code, write a makefile and a proper c code, open up a command line, and use normal tools.

    [ ok ] Transferring enormous rage…done

      1. +1 for contextual hardware and programmer selection.

        The IDE has driven me batty on a few different occasions. Just the find/replace tools are enough to pull your hair out. But, it is FOSS and improvements are a possibility.

      2. I’ve got cheap, used chipKIT Max32 with network shield. they use Arduino-based MPIDE. I ran it once and replaced it with UECIDE, just because I like my IDE to be more than fancy version of notepad.

  7. Say what you want it’s hella convienient. Doubtlessly the minor “white lies” it tells improve access to microcontrollers.

    Anyone who wants to will quickly move away from it and delve deeper.

  8. Thank you for this post– Though I always use C/ASM on PIC/ARM, for the ‘simpler’ projects on Arduino this is one of the questions I ‘highly expected’… But was just ‘too afraid to ask’.

  9. So, I’ve been into 8 bit AVR’s since the STK-500 days and I do have wicked love for AVR libc and avr-gcc. I don’t care for C++, I find (like most people) the Arduino IDE lacking.
    With that said, I think Arduino is absolutely wonderful anyway. Nano and mini clones are dirt cheap. You just dowload the IDE and install one thing and you’re off.
    This enables just about anyone who wants, to reflash my firmware replacement(s) for the STC-1000 thermostat, for just a few bucks and a few minutes of spare time and without a degree in CS.
    If this gets you exited, to after a few minutes of playing, being able to flash a LED, then read a sensor, control a motor or whatever. Then it is a good thing. You can eventually learn proper C/C++, if you want to, or just be satisfied with playing around.
    If a kid is exited about playing an instrument, would you rather not have him/her loose interest learning to read sheet music BEFORE allowed to try or would it be ok to not know the chord names and juat bang out a few three chord songs to get them up and running?

    1. Well said.

      I share your “genesis story” coming up with AVR’s before Arduino. AVRfreaks is a huge help in learning all the ins and outs of these chips. I’m always a bit suspicious of what hardware the Arduino code is using and how it might mess up my use of timers and interrupts. It’s hasn’t bitten me yet, and Elliot’s exploration of the back end of things is quite helpful.

    2. I agree. It does a good job of getting newcomers interested without overwhelming them.

      Also, I like your music analogy.

      “Stop telling {kids who bang out three chord songs} that they are {playing an instrument}, it encourages a culture of crappy {instrument playing}. There IS a right way and a wrong way and {banging out three chord songs} doesn’t do anything to help show the difference.”

    3. I guess the folks I was aiming the article at are the folks who are currently using Arduino and asking, “what’s next?” I think the Arduino docs/community/webstuff does a good enough job roping in the newbs.

      I’ve seen people who buy the hype that there’s something unique about Arduino, and that blocks them in moving forward because they think that writing code outside the Arduino libs is somehow different. “Oh, I could never learn C/C++, so I’ll just stick with Arduino.” Those are the ones I’m trying to get over the hump.

    4. I always thought what was written to the “Arduino” boards was different than what was written to an AVR. Is the code compiled down to the same hex file and just flashed to the chip? Or is there something different on an Arduino (bootloader?) that makes it easier to write to?

      I started with ATtiny’s and AVR-dude, and would have never thought it as easy to implement USB as it is with an Arduino pro-micro and using it as an HID board.

      1. Arduino boards have a (pretty standard) bootloader on them so you don’t need a separate ISP programmer, but otherwise they’re bog standard boards. Some of them (Uno) have USB interface ICs onboard, and some (Leonardo) have built in USB support.

      2. Trav, Please do not take offense to my comment.

        Here is a good example of a non-engineer making a guess on how microprocessor software development works.

        Yes, the code compiled down IS the same hex file that is flashed into an AVR chip.
        There is a step never discussed called “linking” that creates that hex file.
        If you check the directory that the source file live in, you will see said .hex file.

        There are added code to facilitate the ease of use that the Arduino environment brings to developing code.
        These “hidden” features, such as linking is required but has not been discussed here as its one of those magic steps that is just done by the IDE.

  10. I remember when I first started programming microcontrollers I was using Arduino. At the time it only supported the ATmega8 and ATmega168. My ATmega8 was running out of room and I figured out that all the Arduino core libraries were compiled in regardless of whether I used any functions in those libraries. I compiled my sketch directly with WinAVR, with the options enabled for dead code elimination, and suddenly I had a bunch of space. After that I started programming with WinAVR it gives you a lot more control and your codes runs faster, since it’s not slowed down by virtual pin mapping. It’s a shame more Arduino users don’t move past the Arduino IDE, you can still use the entire Arduino core or you can just use a single library. If you only use a single library without the core you’ll have to edit the library and replace the references to the virtual pin mapping with pin macros. Eclipse has an WinAVR plug-in, but personally I like editing my code and make files with notepad++ or programmers notepad and calling the compiler from the command line.

  11. I think there’s an audience of people who really don’t want to be coders. They just want to do some cool thing. Most of electronics these days is sensor–>processor–>UI, and most electro-mechanical is software driven, so that puts us in the unenviable position of having to code to get our projects to work.

    But we don’t want to have to learn the subtle intricacies of some new processor and some new compiler, we just want the thing to do what we want it to do. So for us Arduino is perfect – extract from a couple of samples, look up a few libraries, stitch it all together and bob’s your uncle.

    And the industry obviously sees this – how many low cost modules are coming out from name brand electronics manufacturers and how many multi-thousand dollar dev environments are now free. And remember when JTAG programmers cost $1500?

    Arduino is a revolution.

    DougM

    1. As a geek who’s been learning C since I could get a Slackware CD and an old computer to install it on, the Arduino was great! Sure, if you knew someone else with a chip flasher, you could build a parallel port chip programmer pretty cheap; but I didn’t know any one else and couldn’t find one. I went to university and learned C and C++ (and the difference between the two) and picked up C99 for embedded programming even though I had nothing to program on.

      Why didn’t I get a PICKit or AVRDude or something else before the Arduino? Do you remember what the prices on those were back in the 90s? If you could find one at the Shack it would be near $100, and if you were lucky enough to have a Digikey or Mouser catalog it was still over $50. If I had gotten into an embedded course, the boards used there were $300 or so. The $30 Arduino just broke the price point and told the old guard that the old ports weren’t needed for the bargain boards. And it’s changed the embedded chip landscape in relatively short time.

  12. Rants like this drive me nuts. Get over yourself. The Arduino platform wasn’t designed for hardcore embedded systems junkies. It was designed for students, artists, and hobbyists without a computer science or electrical engineering background. It is precisely for this reason that I used it to teach a beginners embedded systems class for three years when I was an undergrad.

    Yes, the “Arduino Language” is C/C++ and yes, you could program things JUST as effectively in another editor with the same compilers, libraries, ect. The reason Arduino has taken off the way it has is because it hides all the messy, confusing bits off to the side which prevents folks who have no prior programming background from getting overwhelmed and quitting. After folks play with the IDE and dev boards long enough, they start to find the drawbacks to using the stock libraries and the IDE as a whole and start finding forums and amateur white papers explaining how to do things more efficiently without libraries and such. They learn proper code and AVR tricks as they develop their projects and grow as engineers and coders.

    A bit of a side note, but don’t hate on the “sketch”. The Arduino environment is a development environment and not meant to be used in a final consumer product. The whole idea is to write a bit of code, slap it on a processor fast, and then test it out. If you don’t like it, tweak it, and try again. It is very much like sketching out ideas on an artist’s pad.

    1. It sounds like you had in mind a different audience than I did in writing the piece. This was not intended to be an article for beginners, and I’m presuming a kind of intermediate level of knowledge that I think a lot of our readership has. (I don’t see beginners reading a column with “Embed” in the title either, so I don’t think we’re deceiving anyone.)

      The idea behind the article was to help demystify the way “Arduino…hides all the messy, confusing bits” for people who are at the point where they _want_ to understand those particular bits.

    1. LOL Java amrite?
      LOL PHP amrite?
      LOL JS amrite?
      LOL Go amrite?
      LOL Swift amrite?
      LOL SCSS amrite?
      LOL DELPHI amrite?
      LOL {EOL} amrite?

      Can we please stop making fun of people, because {x} is the only language to be taken seriously. That is just stupid. Like you need to distance yourself from everything that is not {x} and cant be taken seriously because you work with {x} since 2-20Years and already lost the ability to look beyond one’s nose. What are you? 14? Can we please not stigmatize people because of the compiler they are using? Are you calling yourself an evangelist too? Because you sound bigoted when using that term.
      If your language is superiorin in every way, I wonder why it is not used as the main tool for the job. Maybe… just maybe you are not right that your language {x} is the soltution to every Problem. Try to comprehend that for a change…

      LOL PHP amrite?
      LOL PHP amrite?
      LOL PHP amrite?

    2. As much as I detest Java and Arduino, that argument holds virtually no merit.

      I wrote emulated hardware using Python connecting to an ARM controller simulating two Serial ports I wrote in C attached to an AVR running what I wrote in ASM to debug an Android App I wrote in a subset of Java. Oh yeah… I’m doing it all inside of Win8.1. :D

    1. Loved that article when it came out. And you are still right, four years later.

      I certainly hope that this article didn’t come across as my harshing on the Arduino libs. By pointing out that there’s nothing much to Arduino but libraries, I actually intended to dispell some of the Arduino bashing of exactly the ArnoldB variety.

      Using libraries to get coding done is what all professional programmers do all the time. Easier, clearer, better-debugged libraries are better than the opposite. And I think the (mostly community written?) libs are a huge part of why Arduino won. Using good code libs isn’t “baby talk”, it’s best practice.

      But exactly because Arduino “won” and got a lot of people into the hobby, there are a lot of people wondering “what’s next?” and feeling trapped by the slightly black-boxy presentation of the Arduino IDE from the outside. The article was meant to be a look into the black box, and an encouragement to look further.

      This is Hackaday, after all. About half of our readership use screwdrivers to turn screws and build things. The other half use them as ghetto pry-bars to get into sealed plastic cases and figure out how things work. I like to write for the latter.

      1. I really liked your article; it’s nice to know what’s going on under the hood. Several years back I was using an ATtiny micro and trying to get it to play nicely with a character LCD I bought off ebay. I used 3 Libraries I found on the internet that should have work but didn’t. The ATtiny wasn’t supported by the Arduino IDE, but the according to the Ebay description the LCD worked with Arduino LCD library. So I took the Arduino LCD Library deleted the references to wiring_digital.c used pin macros and compiled it in WinAVR. Everything worked perfectly and it made my life easier.

  13. Good article for the great unwashed. :-)

    A couple of minor points to add. Using the PIN register is the fastest way to toggle a pin. So instead of:
    PORTB ^= (1 << LED_BIT)
    use:
    PINB = (1 << LED_BIT)

    And to use the Arduino (Wiring) libraries but with a much faster digitalWrite, go with Wiring 1.x. Download it from wiring.org.co.

      1. Can you elaborate on what you mean about ARM bit banging?
        Do you mean the separate set and clear registers that some(most?) have? i.e. writing 0x11 to the set register sets bits 4 & 0 to 1 without clearing the rest.
        It is something I’ve wished the AVRs had when I’ve been writing bit-banged UART and SPI code.

        1. It’s bit-banding, not bit-banging. It’s where (for the special bit-band memory region) they map each individual bit to it’s own word in an “alias” region. This let’s you change a single bit by writing to the corresponding alias word.

          You can see a brief description beginning on page 15 of this PDF: http://infocenter.arm.com/help/topic/com.arm.doc.dai0179b/AppsNote179.pdf
          Or you can google it and maybe find a better description / example.

        2. Bit banding solves the “atomic bit access” problem in an arbitrary address space, so it works in RAM, or on peripherals (usually. It depends on vendor choices.) Most ARM chips aimed at replacing microcontrollers have also implemented Clear/Set/Toggle registers in their GPIO peripherals, which achieves about the same thing for most cases. (I guess bit-banding could save a conditional jump in an arduino digitalWrite() like function, iff you wanted to enforce that the “true” value for pin state had a 1 in the lsb…)

    1. The difference between the two operations is that you’ve totally clobbered the entire register with the simple assignment rather than the |= , ^= way where only one bit is modified. They’re different things, really.

      But yeah. That’s the “20-40x” faster in the text. The simple assignment is another factor of two faster than the read, write version.

      I didn’t know the the Wiring libraries had sped up digitalWrite. That’s good to know. Thanks!

      (Seems to me that digitalWrite() could be implemented in a pre-processor macro, and thus costless, for most cases except where you’re dynamically allocating pins based on user input. I wonder why they didn’t go that way?)

      1. Two reasons I’ve heard mentioned:

        1) Arduino uses an older version of GCC, which lacks some optimizations found in newer versions, and are needed to do that properly.

        2) Consider what happens with code that *relies* on digitalWrite() being slow. For example, if someone is bit-banging a serial protocol using digitalWrite(), chances are it already runs slowly enough that they’ve never needed to even consider the possibility that it might need to be slowed down. And even if they did, perhaps they deliberately omitted timing loops, since under normal circumstances it would make something already too slow even slower; if the timing loop finds it can immediately exit, there is still some overhead for the check. Should a new version of the environment be able to substitute a faster digitalWrite() under certain circumstances, it would break some existing code, make execution times unpredictable, etc.

        1. Seriously? Do this…
          FastDigitalWrite ()
          Done.

          Don’t like that? Then overload DigitalWrite() with an extra flag to force the newer code or default to the older code. C’mon guys, all the major languages figured it out…. except for maybe PHP….

      2. I should have been more careful about posting at 2am.

        DDRB |= (1<<PB5); evaluates to an sbi call, which takes two clocks.
        DDRB = (1<<PB5); evaluates to an ldi and an out, which also takes two clocks.

        "Potato, potatoe" as Dan Quayle used to say.

      3. “you’ve totally clobbered the entire register”… Nope; writing to PINX (which used to be an input only register, back in the Atmega8 days) atomically toggles ONLY the bits that are one in the byte you write. Just like the “xxxTOG” registers in some newer processors with lots of address space to throw away. It’s a bit un-elegant, re-using a register that way. But occasionally useful.

        pre-processor based digitalWriteFast() has been done, but it’s pretty gross. An inline function can do a good job, but it needs an extra copy of the pin abstraction data, since the compiler optimization doesn’t know about PROGMEM. (Hmm. Didn’t know about. I wonder how it does now, with the new “named address space” feature. (Which, alas, C++ doesn’t support.))

        I’ve been playing with an ARM recently, and one of the interesting observations is that the ratio of “optimized constant-based digitalWrite() to full variable-based digitalWrite is about 4:12 instructions, rather than 1:50 as for the AVR.

        1. OMG. He was writing to PIN in output mode. I didn’t even know about that trick. Learn something new every day! Talk about a way to produce unreadable code.

          Re: digitalWriteFast(). Yeah, I quickly read through that thread (linked, above) on arduino.cc. It looks like making the best of a bad situation, honestly. I wonder how many people know it’s there / care / use it. Half of the time, I think all the speed stuff is pointless for most people, and then you see something really simple like an IR receiver that needs more speed than digitalRead() has (according to https://learn.adafruit.com/ir-sensor/using-an-ir-sensor).

          But also, re: the whole darn thing. If the Arduino folks just labelled the pins PB3, etc on the board, there’s trivial macros that would make everything work. Trying to shoehorn the physical device into the abstraction rather than make an abstraction a convenient / simplified representation of the device is the problem, IMO. It’s always going to be leaky or clunky.

          Re: ARM. Is it the compiler?

          1. Let me try that again: I just figured out how to create a filter in gmail to send all emails with ‘There is no Arduino “Language”’ in the subject line to the trash. Isn’t technology wonderful?

          2. >> “emails with ‘There is no Arduino “Language”’ in the subject line”

            Or you could have clicked on the [ Unsubscribe from all follow-up comments ] link in those same emails.

            Isn’t reading wonderful.

          3. Re ARM: special “IO addreses” or instructions are anathema to RISC architectures, and I don’t think you can do a write (any value) to an arbitrary memory location in less than three instructions. (load (base)address into one register, load value into 2nd register, write value to (possibly)indexed address. The 4th byte is because Atmel (at least) made the gpio ports 32bits wide, and the “move immediate” instruction is limited to 8bits (in it’s 16bit version.)

    2. Wait… WHAT??? Since When?!
      Or, more importantly, I guess… who needs to *toggle* a single pin that often…? The only cases I can think of, off-hand, is for “blink” (which doesn’t need to be fast), a bit-banged serial-clock or maybe bit-banged NRZ-encoding?
      Regardless, of my lack of use-perception at the moment, handy trick for future-reference. Thanks.

  14. I believe the reason they called them ‘sketches’ and not ‘programs’ or ‘code’ is that they are trying to reduce the fear-factor of new folks getting into the controller scene. that’s a perfectly valid way, too; its less scary to think you are writing ‘sketches’ rather than programs.

    to us who are software people by education or trade, its just a word game. you are still writing code. it does not matter (should not matter) what you call it, for us. we are not timid about controllers or programming. why are so many of US so annoyed at the terminology that is meant to make things easier on the new folks?

    I do think that removing ‘main()’ was a mistake. this is not a hard concept to deal with. and if you are going to code in C, you do have to understand forward declarations; and when the system does too many things for you, its going to be THAT much harder to jump into (cough) real programming, later on.

    as for the IDE, its minimal functionality but that’s also an educational thing. first, its on all 3 platforms and that’s a bit of work as it is. its dumbed-down on purpose so that the basics can be done and there’s less scary stuff or clutter in the menus. I’ve been able to write 13k lines of C with the crappy IDE. its not fun, but its do-able. the lack of debugger is the bigger problem, not the editor/gui. then again, some so-called professional ARM tools don’t have debugges (I attended a company demo where they ‘only had printf’ as the debug tool; and this is a commercial vendor, not some maker-thing!)

    1. So we should call math “fuzzy-kitty-petting”? It won’t make the theorems any easier to prove. (I don’t think the “sketch” thing matters one way or another, honestly.)

      I’m not sure which of the Arduino conveniences are the key to its success, and I’ve thought about it a lot. My guess is that it’s the quality/range of the libs. Want an LCD? Lib. Want an SPI EEPROM? Lib. Oh, and the IDE / all-batteries-included toolchain in a box.

      I think that stuff matters a lot more than fuzzy kitty petting, but I could totally be wrong.

  15. What goes around …..

    Years before Arduino, I had helped some friends get started with an Atmega32, AVRISP and WINAVR.
    All command line driven.

    One of those friends told me a few years later, “you should have shown us the Arduino Compiler” !!

    :-D

    1. And before Arduino there was Basic Stamp and Basic52-based SBCs. Whose target audience was similar ,and whose performance was worse, and higher cost, for the same groups of people who didn’t want to have to learn too much. And they were both revolutionary game changers as well. But … a lot harder to break out of, going from an interpreted baby language to the assembler or bare C that was the alternative.

      In fact, for someone straining at boundries, Arduino might be a FINE starting place. If you were using Atmel ASF, or STMCube, or Tivaware, your implementation of “port_pin_set_output_level()” (the ASF equiv of digitalWrite()) might be a LOT harder to follow than the arduino code. Thanks to layers of abstraction that “real” coders put around things that they expect might have to work on several hundred different chips, rather than just “a few.” That’s sort-of sad.

  16. >Thank goodness they didn’t invent their own programming language!

    yeah, like apple, google and MS did?

    yup, ever single one of those have looked at C and said ‘thanks, but we’ll start all over from scratch and do our own thing’.

    really absurd when you think about it. you used to be able to know C and get software jobs. now, the language explosion is totally out of hand and its too wasteful to keep trying to be good at large numbers of languages.

    so, at least arduino is still basically C. they could have pulled an apple/ms/google on us and really full-retard.

  17. I started programming around 33 years ago. In that time I’ve programmed in Basic, Assembly, C, C++, FORTH, FORTRAN77, Java, JavaScript, PHP, PERL, Pascal, Delphi, ActiveX, ColdFusion, plus spinoffs like Allen Bradley ladder logic, R, SQL, bash, and probably a few more I’m forgetting. And wanna know something? I’m kinda tired of it.

    I like having high-level constructs in place so I can focus on my desired purpose and overall logic rather than worry about null pointers and other fiddly syntax gotchas.

    Yeah, maybe the current incarnation of “the Arduino Langauge” is a thin skin overtop of generic C/C++. Maybe it’s a little disingenuous to call it its own “language”. But I’ll say that even as someone with decades of programming experience, if Arduino was any closer to bare metal programming, I wouldn’t even be here. Right now I just want to dabble with blinky lights, and remote controls for my camera, and making tangible electronic things to play with. Having to write code to make them work is an unfortunately necessary evil and the simpler and more invisible that part is, the happier I’d be. I actually wish Arduino were even more abstracted from the C/C++ world and I’m quite happy to think in terms of “sketches” rather than gcc compiler flags and whatnot.

  18. As a fledgling “arduino programmer” I greatly appreciated this article. I had strongly suspected that it was all C/C++ under the hood but was somewhat discouraged from poking around because “I’m not a real programmer”. Looking at things this way makes me more apt to learn proper C/C++ coding conventions and work from there rather than following the standard blueprint of “what do i need to accomplish? has someone else done it? oh this guy did something similiar, can I adapt his code to suit my needs? Too bad its written in C and thats not compatible with the ‘arduino language'”

  19. So you want to blink an LED. How?

    First, refer to the data sheet for your specific chip to see which port/pin you need to use, then set up the port appropriately, and then use funky C notation which looks like line noise.

    Or just use digitalWrite from the Arduino domain specific language.

    Which is easier?

    Sure, to an experienced C programmer familiar with embedded systems and AVR in particular, this is all unsurprising stuff. People using Arduino are not C programmers and are not familiar with embedded system design.

    Arduino is not C. It is not intended for writing timing-critical control systems. It is a tool set for people wanting to build cool stuff quickly.

    1. You’re totally right! Using bitwise logical operations to turn on an LED is a huge barrier to newbies. A ton of “real” C programmers don’t ever do low-level bit manipulation, and it’s nearly as bad for them. In that sense, you totally can’t complain about digitalWrite().

      But, ummm, Arduino _is_ C (with some libraries). I think that’s even in the title of the article. :)

      Point is, you can choose, without giving either up. Direct port assignments if/when it counts, and digitalWrite() otherwise. Precisely because Arduino is C (libraries).

  20. Bravo for you! I wrote a medical billing database in C on Interactive Unix 386 boxen back in the mid 80s – early 90s. Learned C with K&R’s “The C Programming Language”. We started coding it BEFORE there was a C++, but took some of the object oriented ideas and used them by creating structures with references to functions.

    So… I’m an old guy.

    I started playing around with Arduino in the last couple of months, and was amazed how easy it was to get back onto the coding bicycle. I *was* curious about all the “Man-behind-the-curtain” stuff that’s obscured by the Arduino IDE.

    Thanks for clearing that up for me.

    Interestingly, about an hour before I read your article, I sent an email to another coder about one of my Arduino projects and was complaining about “Why in the HELL do they call it a “sketch” when it’s obviously C/C++ code?”.

    OooooooooOEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEOOOOOOOooooooooooo!

  21. I would also like to know if the gcc that comes with the package supports C++11 (yeah the compiler will probably be ok but what about the standard library?)

    Also, C/C++ does NOT require you to declare the functions before they are defined. They just need to be defined/declared before they are used.

    This is perfectly fine:

    void do_something() {
    // bla bla
    }

    int main() {
    do_something();
    return 0;
    }

      1. The only reason setup and main are declared is so that they can be referenced from main in a different source file. They’re both required: try taking the Arduino bare minimum sketch, removing setup(), and hitting compile. It will fail.

    1. There is essentially no libstdc++ for AVR, so you can only do things that don’t require library support.

      I don’t know if it’s a magic flag that AS sets, but my current ARM experiment spits out warnings if I don’t have a prototype before the definition…
      led_toggle.c(103,6): warning: no previous prototype for ‘digitalWrite’ [-Wmissing-prototypes]
      void digitalWrite(uint8_t pinno, uint8_t level)

  22. As .ino files have to be pre-process into .cpp before beeing compile by gcc one can’t say it is C/C++ code.

    here a surprise I had first time and only time I used Arduino:

    /*
    LED intensity variation by PWM
    board trinket pro
    */

    int pwmPin=3; // LED

    void setup(){
    }

    void loop(){
    byte i=0;
    cahr delta=1;

    i += delta;
    analogWrite(pwmPin,i);
    delay(5);
    if (i==255 || i==0)
    delta=-delta;
    }

    This doen’t worked when I tried it. I was thinking that once loop() is called the program stayed in loop(). It is not the case. So locales variables were reinitialized. So ‘byte’ and ‘i’ must be defined outside of loop(). Sketch don’t give you access to the actuel infinite loop inside main(). For me it disqualify it as C/C++ proper.

    1. Mismatch type is your problem. Why is byte being uses to identify a bit? You could have simply used a int identifier. Char variables tend to need the single quotes (‘1’) to identify a character. If you use a number, it will assign which ever character is represented by that number in accordance with ASCII (line break iirc). You then try to add a byte to a char with forces a type change. Now it’s a string (it won’t add them as number because concatenation takes precedence due to delta being an char), or it just added the number but shifted it due to the byte identifier. If you rework the way you did that, you would see that it does work without the variables needing to be initialized before executing the loop() function.

    2. That has nothing to do with whether the code is C/C++ or not. Did you expect the IDE to add an implicit loop inside loop()? That does also not happen with regular C/C++ – you would do something like

      int main()
      {
      byte i = 0; char delta = 1;
      while (1)
      {

      }
      }

    3. cahr delta = t;
      Miss-spelled “char”. Checks OK.

      What is scary is that “byte” must have been declared somewhere. Maybe it’s a reserved word. But “i”??? The Arduino system must be inserting global declarations for you somewhere.
      It’s good not to care about what you are doing. I notice on the Arduino forum there a lot of great people with the patience of a saint that will write most of your code for you. I guess your project gets done, but can you claim it as your own?

  23. First: Arduino’s “language” is a lie-to-children (https://en.wikipedia.org/wiki/Lie-to-children). Nothing wrong with that. It’s a proven way to introduce people (not just children) to subjects that may be perceived as complex.

    Secondly: No such thing as C/C++. Arduino’s language is C++ and if you don’t believe me, try to declare a variable called ‘class’. Luckily, C++ supports such a big subset of C that most C programmers don’t notice they’re using the language they love to hate.

    Stepping out of rant mode: OK, most people probably use that subset of the C++ language that overlaps with C, I get it.

    Thirdly: yes, Arduino’s digitalWrite() functions are slow. The writers of those functions have made some choices and I think they probably made the right ones given their audience. For one, there’s some extra checking needed because the pin used in the digitalWrite could previously have been used for an analogWrite() (another lie-to-children), which means the digitalwrite function must switch of pwm, but there are more big choices that end up slowing down digitalWrite.

    It is, by the way, possible to implement a digitalWrite() function that is exactly as fast as fiddling with bits (I’ve explored such an implementation and described it here: http://rurandom.org/justintime/index.php?title=Fast,_arduino_compatible_digital_pin_functions)

    Oh, and by all means I do support the message of this article: It is a good thing to make people aware that Arduino sketches are C++ programs. It’s just that at the same time I don’t think that it’s a bad thing to tell them they’re writing a “sketch” when they write their first piece of embedded software.

    1. Nice. I wrote the article to dispell the lie-to-children for the metaphorical adolescents in the audience. But I like that turn of phrase.

      C/C++: some of the Arduino core is written in C, some in C++, which is what I really meant. (And included within extern “C” brackets to get included into the C++ parts of the code.)

      Nice point about the digitalWrite functions. I’d always wondered why they didn’t write them to be faster, but hadn’t thought of the clash with PWM. (I could have actually looked at the code, I suppose. Taking my own medicine and all that.) I’ll look into your functions. Thanks.

      Anyway, you raise your kids your way. My son is going to know about electrons in kindergarten.

      1. This. So much this.

        Hell, I only started working with the arduino once someone told me that it’s “programming language” was just something gentle over C++ and I could use standard stuff (within limits) to my heart’s content. Otherwise, people would talk about wiring and I’d think, “Christ, another programming language?” And then the lie-to-children part happens and my friend who’s ecstatic about making LEDs blink finally gets that they’re coding in a real language and looks deeper.

        I’ve little interest in being an EE, and I’m trying very hard to stop being a coder while avoiding managing coders. That’s why I call my tiny mallot skills I have the audacity to call soldering a cheap hack even though I’m putting a lot of thought into it. And that’s why I come to Hackaday and stopped reading Spectrum and NANOG.

        I’ve never trusted people who talk about how a specific programming language is “ugly” or that something “isn’t really programming.” I’d always end up with something that would sacrifice maintainability or ease of use in the pursuit of some pure design concept.

        1. I understand but have to ask, have you ever tried to read a Perl program? Dealing with others code and the lack of documentation you can run across in even the most professional environments can make you cringe at the mention of some languages.
          Trying to standardize on just one language doesn’t work either. I had prototyped a project that used network sockets. Easy in the language I chose to work in. Then some executive decided it needed to be implemented in Cobol before it went into production. That project died a slow agonizing death.
          I’ve heard that the language you think in will effect how you solve problems. I think it’s similar with computer languages. Let the project dictate the language you use.

  24. First off, Arduino is an amazing way to get an easy first step into the world of embedded programming. It’s only natural that they hide a few things for the beginners, and any real programmer will quickly progress and eventually take off the training wheels.

    Second, and far more importantly, it’s “PER SE”, not “PER SAY”. “Per se” is latin for “in itself”. “Per say” means nothing and is stupid.

  25. [quote]So if you start out writing your code in C, and then find out that you need some of the features of assembler, you’re hosed. You stop writing in C and port all your code over to assembler.[/quote]

    Silly me writing my assembly in (dot)s files and just linking them with my C. I will have to go back and get all the mixed C/ASM I have done and port it all to pure ASM.

    Can’t believe I’ve been fooled for so long.

    1. Good point about including assembler routines with C. I’ve always gotten by with inline asm, as mentioned in the article, but I suppose for longer functions that makes sense.

      I should have picked more dissimilar languages for the example. Dang!

      1. You can ALWAYS call assembler subroutines from HLLs. At least, if you can’t, that’s a good sign that you should “run away.” I wrote an assembler subroutine for (original) IBMPC BASICA that implemented an H19 terminal emulator, one for pascal that did interprocess comm using shared code memory segments, and one for Fortran that compiled texual math expressions, and then allowed that to be called as another fortran subroutine.

  26. Someone needs to write un.arduino.me a program that takes a sketch and compiles is down into a directory (removed setup and loop by plopping them into main) and pulling the required includes into a standard directory structure. Auto spit out a generic makefile as well.

    That would truly help someone migrate from the Arduino IDE(cringe) and just hammering libraries together into learning whats going on behind the scenes.

    This would help migrate projects that started as Arduino “hash bang” into developer friendly products. Anybody try adding functionality to the Marlin reprap firmware before? If you need to debug something your totally up the creek.

    1. Speaking of entering data into IC’s with toggle switches, I have done something similar on a much smaller scale. A few months back I came up with a creative way to manually enter bits into a shift register to get around switch bounce issue. I used latching hall effect sensors and a magnet, to manually clock in bits. I still have it sitting on the desk

  27. Points well taken, but one good rant deserves another : Elliot wrote, “. . . there’s two aspects that really get *our* goat” (emphasis added). My rant is against the growing use of plural pronouns such as “we” or “our” by single individuals referring to themselves. This is rampant among my fellow ham-radio operators. In this particular case, if there are other C++ programmers who share Elliot’s grievances, he doesn’t say so or that he’s speaking for them.

    1. It is in “our” style guide here at HaD to do so.

      When I go out on a limb like that, it really gets my goat to have to incriminate the rest of the fine HaD crew. But I have my marching orders. (And I take liberties in the comments!)

  28. Though the Arduino IDE is mostly helpful when introducing newbies to programming, it is often hard to get them to later appreciate the difference between a microcontroller (atmel’s 8 bit atmega family and all the rest that keep being added) and a handy development platform called “Arduino” based on the “wiring” “language,” which is a layer on top of the open source C++ compiler behind the scenes, that some artsy people came up with to make projects easier…… and decided to call “Arduino” ….. sigh.

  29. Great article! Couldn’t agree more.

    If you’re on a Mac, I highly recommend embedXcode (http://embedxcode.weebly.com/). I have been using it for a long time, now. It’s excellent and you get to use Apple’s Xcode IDE.

    When I use it, however, I’ve undone the Arduino abstraction to make the very fine work the author has done more akin to Atmel’s AVR Studio. I prefer not to run Windoze on my Mac, so this solution is a great way to work with the AVR chips without Atmel Studio. AND, it’s an excellent way to work with dozens of other boards and frameworks:

    Atmel Cortex-M0+ SAMD and Cortex-M3 SAM, Microchip PIC32, Expressif SoC, MSP430, MSP432, C2000 and Cortex-M4 Tiva C MCUs, Maple boards with ARM Cortex-M3 STM32 F103RB, Teensy boards with Freescale ARM Cortex-M4 MK20, Spark Core with WiFi, RedBear boards with Nordic nRF51822 SoC, Nucleo and Freedom boards on mbed with ARM Cortex MCUs

    It’s amazing work and a great IDE. You get all the features you expect from a professional grade IDE (REAL syntax highlighting, version control integration, code reference, etc.) AND it’s a fully native and very powerful OS X app.

    I’ve written code for the AVRs and the Freescale Freedom embed boards with it. It’s an excellent experience. I’ve ordered some TI LaunchPad boards for my next project, which are also supported.

    I wrote a a very brief intro article about it on my blog, if anyone is interested in getting a quick tour: http://www.stuffandymakes.com/blog/2014/04/05/embedxcode-a-better-way-to-develop-for-arduino-on-the-mac-using-xcode/

  30. As a C developer, I got frustrated with the inadequacies with the runtime and “IDE” pretty early on, and ended up building a new performance runtime for AVR. I haven’t touched it for a while (moved on to Mbed), but for those in AVR land, Its an easy abstraction of the hardware, without the attached baggage of the Arduino runtime. Its BSD licensed, and encourages event driven programming. You can check it out here: https://infernoembedded.com/products/flame-runtime

  31. i was doing c/++ before i got into micros. recently the ‘arduino way’ was biting me in the ass.

    i wrote a struct to store a data frame that i wanted to pass over serial, then under that i wrote a function to fill out that struct with data from a couple analog channels and a couple digital pin readings. this was all above the setup() and loop() functions. the compiler then gives me a ‘function uses undefined struct’ error, which in unobfuscated c would have been totally valid, but in arduino is not.

    the way arduino sticks all the function prototypes at the top of the file was causing issues while writing things the c way. i even tried placing my own function declaration after the struct but it seems it was ignored while the one arduino placed was not. either structs need to have the same prototyping rules or there needs to be a way to override this behavior.

    ultimately i turned it into a class with a member function, which is totally fine to stick above setup() it seems. the other option was to stick the function and struct in another header file. all my ‘sketch’ did was calling the function in loop, and writing the data out with Serial.write(); followed by a delay(). having two files for such a simple job seemed rather overkill in my book.

  32. I wonder if they used to have “you’re not a programmer, you’re just a coder!” debates, back when programming, coding, keypunching, and computer operations, were all separate jobs…

  33. All of you people are an embarrassment to people on the autism spectrum.

    Use what tools you like and be mature enough to not disparage things you don’t like for your own superficial, childish reasons.

    “The Arduino IDE is limited, hurrr”

    Who gives a fuck?, man up!

    Just grow up for fuck’s sake, you’re not funny or entertaining at all, you’re just bitching about shit that doesn’t matter.

    1. Yes. Although I gather that Processing does a bit more in creating a friendly pre-built run-time environment as well; something that would have taken significant code in pure Java.

  34. “Yes, there is inline assembler in GCC. That’s cheating.”
    Maybe so, but this was one of the most fun thing we did as undergrads to outdo each other, performance-wise, (circa 1988) in all the classes where we could use C. Inline assembly saved you from popping parameters from the stack, pushing registers, then popping back the vales for the registers before exiting your functions, and pushing returned values. Also you could do fun things with the video memory and mess around with the registers of the VGA card…great times.

  35. I really don’t understand all this Arduino bashing. Programming an Arduino is programming, is coding. Does it matter it is not raw C/C++. Is driving a automatic car not really driving?

  36. I for one Consumed this article. Visiting hackday daily I seek the bias or perhaps knowledgeable comments aimed at every article, this is in fact atleast for me is one major reason I return daily. I Don’t want to be limited to tunnel vision. Tho people’s ideologies may not “currently” aline with my own. I always google-fu their alternatives In hopes of finding the light so to speak.

    I started “Sketching” (don’t wanna call it “coding” Due to Possible flares-up it not be prudent to my point) With arduino And It’s So-called IDE environment. Mostly due to the Large “friendly'” “Helpful” Community.

    I had to start somewhere And Like others Before me, At first needed to ask the stupid questions like which way is up (extreme over simplification) but, To do So in more Vet area’s like avr forums Your quickly flamed for Sucking. and If your lucky given the correct terms to google or pointed to a data sheet and hopefully atleast in some vague suggestion pointed to WTH your suppose to be looking for in it.

    Quickly becoming comfy In the Arduino’s IDE in the soon realized Kindergarten Version of the english language. I knew in order to complete real tasks with Atmega’s chips, I needed to dive into the back side of the libraries. As extensive as the options are their designed purposefully to be mostly cookie cutter and don’t fill specific needs. Like Space requirements, speed and additional options not foreseen by the author of said lib.

    This left me in aww realizing in the said IDE I wasn’t learning to coding per se’ but in fact was like ordering Apple’s Siri to do stuff but having little idea how it was finding where or how to get it done.

    So at this point I was like ok, Time to start figuring out how to programming these MCU’s the way the rest do.

    Right up front there’s little in the way of Tut’s that are (So You can use arduino HUH?, Here’s whats different in the real world compared to how arduino does it”)

    Just my two cents and tho It may upset those vets who learned c/c++ the hard way. The one who make’s a great video series on how to transition from arduino’s IDE to making and using Makefile’s and .cpp etc. Will rule!

    There are many out there like me starting and asking is this for me then wanting more. There are also many out there who will never progress past it. But both are equally important as the demand is high for the hardware for either case and that drives abundance of options and prices down for everyone..

    Greeks who grew up speaking greek believe it comes naturally. Others who learned to speak greek frown upon others who haven’t yet. Having a rosette stone can only help the Greek community grow!

  37. I can not agree more, that the IDE sucks in comparison to almost any other and that that .ino stuff is retarded, but the fact that “it just works” and is easy to use makes it possible for lots of beginners and non-programmers to use a microcontroller. If you give a person that has never programmed and has only basic electronics knowledge a PC without an IDE and the proper tools, I guess they will be much, much quicker to have their blinking LED (regardless of what OS they’re using) by installing Arduino IDE themselves, read an online tutorial, than by installing and using vim+GCC+avrdude…
    That said a proper IDE for Arduino would be nice…

    1. I’ve always used eclipse CDT with avr-eclipse, avr-gcc and avrdude. Open source, multi-platform, feature rich and fully integrated. I believe that some people have debugging working as well, but I never invested in the right programming hw.

  38. think about it this way:

    by removing complicated looking noise from embedded systems in harware and software the number of embedded projects exploded. arduino boards (that essentially are just plain old AVR-boards) have been sold in masses which dropped the price quite a lot. this is a benefit for every real embedded programmer who can still run plain C code on them. so at some point you could say this whole idea of arduino was just a way to enlarge the AVR-board market. personally, i don’t need to design development boards that cost me time and money.

    i find it rather irritating that whenever my friend spots electronics with some black chip he thinks it’s arduino. but who cares..

    1. My thoughts exactly … i use Arduino boards for prototyping and write code with commercial compiler. It costs money? Yup, but my computer is also not freeware, my Fluke, Rigol, … Compiler is just a tool you need and people should look at it that way. I have much respect for guys that made Arduino project possible, but when you’re beyond “use 16×2 and LM35 library to make thermometer” stuff … you need better tools.

    2. >> “with some black chip he thinks it’s arduino”

      This has to be the saddest part of the Arduino landscape.

      The non-engineers that have found embedded systems do not realize that Atmel is not the only “black chip” out there.
      Like what kind of car someone drives, there are many to choose from with their own strengths and weakness.

      I have used almost every 8-bit processor since 1978 on some project/product or another.
      Some I liked, some were too much of a hassle to get working properly.
      ( anybody remember the SCAMP: https://en.wikipedia.org/wiki/National_Semiconductor_SC/MP )

      So Arduino bashing may be fun in the short term, but knowing what’s on the market and understanding those strengths and weakness will help build a product that is both easy to build and profitable.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.