Arduino processing language versus AVR C language

Dear Arduino experts,

The Arduino processing language is so easy to use that I find it hard to think of good reasons to use AVR C language anymore. To be fair, I have never use AVR C before. Correct me if I am wrong. Some reasons I can think of;

Reasons for using AVR C

  • Faster.
  • Smaller code size.
  • Easier to debug? For Arduino IDE, seems like the only way to debug is println(). Cannot use breakpoint, watch windows. If AVR C compiler IDEis used, I think the debugging environment is superior.

Reasons for not using AVR C

  • Arduino developers accomplish in a day what AVR C developers accomplish in a week. I think this reason alone beats all else

Are the reasons raised valid? Did I miss out anything else?

Faster.

Don't know about that. It's the same avr-gcc compiler.

Smaller code size.

The code is pretty small, unless you use a lot of libraries. But you could same the same thing for AVR C.

Easier to debug?

There are other ways of debugging than using print statements. For example:

  • Blink an LED
  • Watch logic levels with a logic analyzer
  • Output debugging information via I2C or SPI

In fact, for situations where timing is critical (eg. generating sound, video, timing an event) putting in a breakpoint isn't particularly helpful.

  • Faster.
  • Smaller code size.

No.

  • Easier to debug?

Probably, but using spare pins and other IO is often better than a real JTAG debugger.


Rob

Faster? Don't know about that. It's the same avr-gcc compiler.

I think it is faster because in AVR C, the developer can directly manipulate the registers. So, it should be faster than working using wrapped-around APIs.

lightaiyee:
The Arduino processing language is so easy to use that I find it hard to think of good reasons to use AVR C language anymore.

The Arduino "language" is C with some very useful pre-defined functions, all written in C.

There is nothing stopping you from doing direct register access if speed was a concern. In fact, the source code for all Arduino functions are included in the IDE, so you could see how stuff gets done. The time savings comes from the fact these functions already exist, so you don't have to create something like analogRead() yourself.

As Nick says, both environments use avr-gcc.

lightaiyee:

  • Arduino developers accomplish in a day what AVR C developers accomplish in a week. I think this reason alone beats all else

bullshit

this is very subjective and completely dependant on the competence of the particular developer

Also you forgot, or probably didn't know, that Arduino breaks a lot of C++ rules so the code isn't immediantly portable. Somebody who is extremely experienced at real C++ will find it somewhat awkward to program in Arduino.

Another thing to note, if I remember right the 328 doesn't support JTAG debugging...

lightaiyee:
I think it is faster because in AVR C, the developer can directly manipulate the registers. So, it should be faster than working using wrapped-around APIs.

Here I output VGA signals to a monitor:

It is highly timing dependent and in a couple of places I directly access the registers. However it is written in the Arduino IDE.

Arduino breaks a lot of C++ rules ...

What rules? Bear in mind they both use the avr-gcc compiler.

cr0sh:
Another thing to note, if I remember right the 328 doesn't support JTAG debugging...

it does have debugWire, I have a AVR Dragon that supports it but I never sucked enough at programming to need it

Arduino's IDE implemented automatic function prototype generation, it sort of eliminated the need for header files in certain situations, it's harder to say what is public and what is private using Arduino, for functions that are not a part of a class

Yeah, that is hand-holding stuff a bit. But you can work around it. For example, make this your main sketch:

MySketch.ino

// main sketch

Then put your "real" code into another file, like this:

void foo ();

extern "C"
 {
  void setup ();
  void loop ();
 }
 
void setup ()
  {
    foo ();
  }
  
void loop ()
  {
  }

void foo ()
  {
  int a = 1;
  }

This file follows the C++ rules because it hasn't been pre-processed. So if you remove the function prototype for foo you get an error.

You still need to be aware of the way the IDE copies files into the temporary directory (ie. libraries) so you would probably need to put an include for each library into the main sketch. But that is not much different from having to edit a makefile.

Here I output VGA signals to a monitor:

Gammon Forum : Electronics : Microprocessors : Arduino Uno output to VGA monitor

It is highly timing dependent and in a couple of places I directly access the registers. However it is written in the Arduino IDE.

Thanks! I had the impression that one limitation of using Arduino IDE is that the developer loses the flexibility to access the registers directly. Now, I know that is wrong. This means that the Arduino code can run just as fast as AVR C because the developer can access the registers directly.

AAV C is much faster, reliable, and easier than Arduino at deapth level.

AAV C is much faster, reliable, and easier than Arduino at deapth level.

How do you figure that?


Rob

hayankata:
AAV C is much faster, reliable, and easier than Arduino at deapth level.

Your proof?