How do I program Arduino in C ???

Does anyone know how to take actual C code and program directly to Arduino through the USB Serial Port? Do I need one of those programmers? I have downloaded AVR Studio 4 and WinAVR but need help on how to use them.

Also, will programming in C mess up the Arduino bootloader?

Thanks!

Out of the box, you program Arduino in C++. If you want to develop for Arduino in C, you have to use a different IDE and a hardware programmer. Most likely you'll overwrite the bootloader, so you won't be able to program via the Arduino IDE anymore (unless you re-burn the bootloader to the chip, of course).

My 2 cents.

Just program it using the command Arduino IDE uses to call avrdude.

Tip: Press shift while clicking upload to see the command used (will be in red).

Out of the box, you program Arduino in C++. If you want to develop for Arduino in C, you have to...

Since C++ is a superset of C, you don't have to do anything but fire up the IDE and start typing.

The IDE adds some code to your code, like function prototypes and a main() function. So, you can't have your own main. There are certain C objects that don't make sense on the Arduino, like FILE handles.

@iRagDoll What is the problem with the Arduino IDE that you are trying to use AVR Studio 4 and/or WinAVR to solve?

Yea I think I am just going to stay with the Arduino IDE so I dont have to reburn the bootloader every time I want to program in C....

Yea I think I am just going to stay with the Arduino IDE so I dont have to reburn the bootloader every time I want to program in C....

You dont have to reburn the bootloader to upload a C (or more specifically, a non-Arduino) program.

Just upload the hex file using the Arduino bootloader.

It is something like:

avrdude -cstk500v1 -p COM3 -U program.hex

That's interesting, thanks.

If you want to develop for Arduino in C, you have to use a different IDE and a hardware programmer.

This is not at all true, ANY C++ environment can be programmed in straight C as well. Just dont declare classes, start programming.

setup() and loop() are C functions, not C++. Libraries such as serial is implemented as a C++ class but you can call it from normal C.

You're right. Thanks for the correction.

With regard to bootloaders and hardware programmers:

You can flash with the IDE with the bootloader or with a hardware programmer. The same holds true if you flash without the IDE.

The main differences are: - Hardware: more expensive, higher speed, no flash consumption for the bootloader - Software/bootloader: cheap, less speed (except for the teensy of course) and flash consumption for the loader.

Udo