The standard Arudino IDE is great for testing small programs and exploring examples from the Arduino ecosystem, but as programs get bigger and start spanning multiple source files you might want something that handles this a bit more effectively.
Atmel Studio is a *free* IDE built on Microsoft Visual Studio 2010 by the same company who build the microprocessor inside the Arduino development boards. In this tutorial we demonstrate how you can use Atmel Studio to build Arduino programs with exactly the same tools used by the Arduino IDE. This gives you the best of both worlds: full compatibility with all the Arduino libraries and a powerful IDE with auto-completion, project management, class browsing and more.
Using this along side MegunoLink’s unique serial monkey, monitor, logger, and plotter will provide the best development environment possible.
For more information see our MegunoLink information page.
- Install Atmel Studio
- Setup Atmel Studio project, define a project name, path, and select a device.
- Set up external makefile and point Atmel Studio to it.
- Modify source file with the Blink code and build project.
- Setup MegunoLink properties pointing at the HEX file.
- Program the arduino and utilize MegunoLinks unique features.
- Download a copy of the Blink project files here. They are also included in the MegunoLink installer (Open MegunoLink, click on the help icon, and click on Examples).
Open up Atmel Studio and go to File-New-Project on the main menu toolbar (ctrl-shift-N). A dialog will pop up with various settings that need changing. To begin with select GCC C++ Executable Project, enter an appropiate project name suitable to the project you’re working on, specify a path where you want the project to be saved (default is the Atmel Studio folder in My Documents), and finally click OK to move on to the next stage.
This page will ask you to specify a device you want to use. Because we want to use Atmel Studio with the Arduino ecosystem this setting is not actually used so feel free to select any device you want from the list. For clarity when looking back at the project in the future it could be a good idea to select the actual chip used on the Arduino board. Once you’re done click OK, the project setup is now complete.
For us to stay in the Arduino ecosystem and utilize all the libraries it comes with, we need to use a custom makefile. Atmel Studio by default creates it’s own Makefile but we want to use an external one. The first step is to get the Makefiles and copy them into your project directory. Open up MegunoLink and click on the help icon (far right), select Makefile. A folder will open up that contains four files. Copy these files and paste them into your project directory. While you have your project folder open drag the file called Makefile (Not Makefile.mk) on to the project solution. This will add the Makefile to the project so you can easily open and edit it.
Now we want to edit the makefile. After dragging it into the project you can double click to open it. It should resemble the code you see below. Adjust the paths, libraries, board types, microcontroller types and variant to the settings that match your development board.
Please note the current version of example code distributed with MegunoLink has backslashes used for the paths. This causes problems. Change to forward slashes as seen below to solve the issue.
# Path to the standard arduino tools (NOTE - there can be no spaces in the path)
ARDUINO_DIR = C:/arduino-1.0
# Give target a logical name to suit your project
TARGET = Blink
# By default this includes all the standard libraries
# (You can remove the ones you dont need)
# (To add third party libraries just put the .cpp and
# .h file in the project directory, dont forget #include statement)
ARDUINO_LIBS = EEPROM Ethernet Ethernet/Utility wire wire/utility Firmata LiquidCrystal SD Servo SPI SoftwareSerial Stepper
# Name of the board you're using - uno | mega2560 | mega1280
BOARD_TAG = uno
# Type of microcontroller - atmega328p | atmega2560 | atmega1280
MCU = atmega328p
# Clock Speed (don't change this unless you know what you're doing)
F_CPU = 16000000L
# Variant type - eithganaloginputs | leonardo | mega | micro | standard
VARIANT = standard
# Note - if it fails to compile then make sure
# there are no rogue spaces after any of these declarations.
The final step is to tell Atmel Studio that you want to use the custom Makefile. Right click on the project inside the solution explorer. Click on solution properties, tick the box that says use external makefile, and enter a path that points towards the makefile you just modified. The path is relative to your project folder so if you have followed this tutorial you just need to write “Makefile” in this box.
Now let’s get to some actual programming.
We want to edit the automatically generated source file. It will appear in the solution explorer and have the same name as your project but with a “.cpp” extension. Double click to open this file and copy the code from the code box below. Paste it into the project. An important thing to note is that in Atmel Studio you need to use function prototypes. An example of this can be seen for the function called “serialMessage()”, notice its prototype at the top of the code example. The project is now ready to build. Go to Build in the main menu and click build solution. Alternatively you could use the shortcut key F7. If you have any problems carefully check your Makefile paths.
Turns on an LED on for one second,
then off for one second, repeatedly.
This example code is in the public domain.
Modified - MegunoLink 2012
//Function Prototypes (In Atmel Studio you need to have function prototypes)
// set digital pin as an output.
// Pin 13 has an LED connected on most Arduino's:
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
This section is currently targeted towards MegunoLink Lite, as time permits we will update this for MegunoLink Pro. MegunoLink Pro has more advanced programming features, details can be found in the Program Device visualiser.
The first thing we want to do is open megunolink and save a MegunoLink project (this assumes you have already followed the installation guide setting the correct paths for avrdude.exe). Open MegunoLink using the start menu icon and click on the save project icon. I recommend saving the megunolink project file inside the Atmel Studio project folder because it makes relative paths possible.
Once the megunolink project has been saved click on the project properties icon and point it towards your compiled HEX file. Te HEX file is located in the Atmel Studio project folder, inside another folder called build-cli. This path is relative to the MegunoLink project file so you can easily copy this to another computer without breaking anything.
Connect your Arduino board (if it’s the first time you may need to install the drivers following our driver installation guide) and select the correct serial port in MegunoLink. Double check that the correct development board is selected from the dropdown menu. Click the green program button. If you’re on the upload tab you should see the programming progress taking place. If all goes well you should see a similar screenshot to the one below. Your Arduino has now been programmed! Hope you enjoyed the MegunoLink approach.