Programming the Arduino Uno Using Atmel Studio 7

Eshan Surendra
4 min readAug 20, 2024

--

If you’re an Arduino enthusiast but prefer using a more powerful IDE like Atmel Studio 7, you’re in the right place. Atmel Studio offers robust features, particularly useful if you plan to delve deeper into AVR programming. This guide will walk you through setting up Atmel Studio 7 to program the Arduino Uno. You’ll need the following:

Step 1: Upload an Example Code Using Arduino IDE

Before we dive into Atmel Studio, let’s start by uploading an example code to your Arduino Uno using the Arduino IDE. This step is crucial as it helps us generate the necessary configuration for Atmel Studio.

  1. Open the Arduino IDE and load an example sketch (e.g., Blink).
  2. Go to File > Preferences and enable Show verbose output during: upload.
  3. Upload the code to your Arduino Uno board. You’ll notice a lot of text scrolling in the console during the upload process.

Step 2: Extract Required Paths for Atmel Studio

Once the upload is complete, scroll up in the console to find a line similar to this:

C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM5" -b115200 -D "-Uflash:w:C:\Users\Januka\AppData\Local\Temp\arduino\sketches\B6651109F3656CC9865284A7A6FF8B52/Blink.ino.hex:i

This line is a command that the Arduino IDE uses to upload the code to your Arduino Uno. It includes the path to the upload tool (avrdude.exe), configuration file (avrdude.conf), and the various arguments needed for the upload process.

To extract the Command and Arguments parts from the given line, follow these steps:

01. Extracting the Command Part

The Command part is the path to the executable file avrdude.exe, which is responsible for uploading the code to the microcontroller.

  • Identify the executable: Look for the path ending with avrdude.exe.
  • Extract this path: The Command part in the given line is from the start of the line up to and including avrdude.exe.

So, from the line:

C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude

Add .exe to make it:

C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude.exe

This is your Command part.

02. Extracting the Arguments Part

The Arguments part consists of the parameters and options that are passed to avrdude.exe.

  • Find where the arguments start: After the executable path (avrdude.exe), the rest of the line contains the arguments.
  • Extract the arguments: Start from -C and continue until the end of the line.

From the given line:

"-CC:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM5" -b115200 -D "-Uflash:w:C:\Users\Januka\AppData\Local\Temp\arduino\sketches\B6651109F3656CC9865284A7A6FF8B52/Blink.ino.hex:i

Here’s what each part means:

  • -C"C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf": This specifies the configuration file.
  • -v -V: These are verbosity options.
  • -patmega328p: This specifies the microcontroller (ATmega328P, the chip on Arduino Uno).
  • -carduino: This specifies the type of programmer.
  • "-PCOM5": This specifies the COM port used for communication.
  • -b115200: This specifies the baud rate.
  • -D: This option disables auto-erase for flash memory.
  • "-Uflash:w:C:\Users\Januka\AppData\Local\Temp\arduino\sketches\B6651109F3656CC9865284A7A6FF8B52/Blink.ino.hex:i": This specifies the file to be uploaded and the operation to be performed.

Replace the hex file path with a placeholder that Atmel Studio understands:

  • $(ProjectDir)Debug\$(TargetName).hex: This placeholder will be replaced with the correct hex file generated by Atmel Studio during the build process.

So, the Arguments part becomes:

-C"C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM5" -b115200 -D "-Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i

Final command and augmented parts be like below:

  • Command part:
C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude.exe
  • Arguments part:
-C"C:\Users\Januka\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM5" -b115200 -D "-Uflash:w:"$(ProjectDir)Debug\$(TargetName).hex":i

By setting these in Atmel Studio, you allow it to use avrdude.exe to upload compiled code to your Arduino Uno.

Step 3: Configure Atmel Studio 7

Now, let’s configure Atmel Studio to use the extracted paths.

  1. Open Atmel Studio 7.
  2. Navigate to Tools > External Tools.
  3. In the dialog box:
  • Title: Give a name to the tool, e.g., Upload to Arduino.
  • Command: Paste the Command part.
  • Arguments: Paste the Arguments part.
  • Check the option: Use Output Window.

Click Apply to save the tool.

Step 4: Write Your AVR C Project

Create a new AVR C project in Atmel Studio and write your code. Here’s a simple example to blink an LED connected to PB0:

#include <avr/io.h>
#include <util/delay.h>

#define LED_PIN PB0 // Let the LED is connected to PB0

int main(void)
{
// Set the LED pin as an output
DDRB |= (1 << LED_PIN);

while (1)
{
// Turn the LED on
PORTB |= (1 << LED_PIN);
_delay_ms(1000);

// Turn the LED off
PORTB &= ~(1 << LED_PIN);
_delay_ms(1000);
}
}

Step 5: Upload the Code to Arduino Uno

After writing your code, build your project. Once done, navigate to Tools > Your Custom Tool (e.g., Upload to Arduino). This will upload the compiled code to your Arduino Uno board.

Conclusion

With this setup, you can now program your Arduino Uno directly from Atmel Studio 7. It’s a streamlined process that combines the power of Atmel Studio’s debugging capabilities with the simplicity of Arduino coding. Happy coding!

--

--