I Feel The Need. The Need for… C. (Arduino Uno Programming in C)

I read a great post from Balau’s blog related to programming in C with Arduino. It was very helpful, however, as a Windows 8 user I had to make a few tweaks.

Download the windows version of the AVR compiler, here http://sourceforge.net/projects/winavr/files/latest/download?source=files and run the exe.

Download this copy of avrdude http://download.savannah.gnu.org/releases/avrdude/avrdude-6.1.tar.gz unzip and then save to your root, i.e. “C:”

I cut and paste his code:


#include
#include

enum {
BLINK_DELAY_MS = 1000,
};

int main (void)
{
/* set pin 5 of PORTB for output*/
DDRB |= _BV(DDB5);

while(1) {
/* set pin 5 high to turn led on */
PORTB |= _BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);

/* set pin 5 low to turn led off */
PORTB &= ~_BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);
}

return 0;


into a notepad++ file, called “led.c” and saved at the root was well.

I ran his commands verbatim in my Windows 8 command prompt, with the exception of the last line which I modified as follows.

Balau’s command: C:\> $ avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:led.hex

My command: C:\> $ avrdude -F -V -c arduino -p ATMEGA328P -P COM5 -b 115200 -U flash:w:led.hex

I had to identify the port (USB) that my Arduino Uno was plugged into, in my case COM5. You can discover which port to use by opening your control panel and going into your device manager. The COM will be displayed next to your device as demonstrated below.

My Arduino Com Port
My Arduino Com Port

After all that, your bragging rights will look a little like this… a blinking light…