Hello World – Arduino UNO with Atmel Studio Elecrom February 18, 2017; Updated On: February 19th, 2017 11 Overview In the last post we got introduced to the Arduino Uno. In this post let us see how to use Arduino Uno (with ATmega328P device) outside of the Arduino software environment. We will use Atmel Studio 7 for programming the Arduino Uno in C. The use of Atmel Studio gives you complete flexibility and control over microcontroller and will help you to create interesting Arduino Uno Projects. The board used in this tutorial is Arduino Uno R3. In this post, we will see how to create a new Project in Atmel Studio from scratch, and write a program to display “Hello World” text on the serial port! Let’s say “Hello world” to the Uno 🙂 Creating a New Solution Launch Atmel Studio 7 Click File > New > Atmel Start Project This will open the Atmel Start Wizard, you will see Create New Project page. Type 328P-PU in the device filter box and select ATmega328P-PU from the list and click on CREATE NEW PROJECT button Now you will see the DASHBOARD On this page we will have to add software libraries which we are planning to use for our project. These software libraries are referred to as Software Components in Atmel Studio Environment. Under MY SOFTWARE COMPONENTS section, click on Add Software Component button. You will see the list of available Middleware and Driver components for the device that you have selected. Type USART in the Filter text box, select USART driver from the list of displayed drivers and click Add component(s) You can repeat this process multiple times to add more software components You will see a software component USART_0 has got added in the project. Click on the USART_0 This opens the USART configuration pane. In the USART_0 configuration pane, select the following settings : Component Settings Mode: UART We need asynchronous operation without flow control to keep things simple. This is how most of the people will use UART on any microcontroller. SIGNALS Ensure both RXD and TXD have been selected. The RXD signal is on PD0, and TXD signal is on PD1 pin of the microcontroller CONFIGURATION RXEN: Receiver Enable should be selected TXEN: Transmitter Enable should be selected Baud rate should be set to 115200 Ensure that your settings match the figure shown below Similarly, click on click on Add Software Component button to add STDIO Redirect middleware component. This component is required to configure standard input / output streams such that the printf() and scanf() functions can use the serial port of the microcontroller. You will notice that the new component STDIO_REDIRECT_0 has been automatically placed above the USART_0 component. It means, it will use UART to redirect the standard input output streams. If you click on this component, to open its configuration pane, you will notice that it has selected USART_0 as a target IO for the I/O streams. As Uno board has a 16 MHz crystal we need to change the clock frequency from 8 MHz to 16 MHz. This number will be used to calculate correct register values required to produce given Serial port baud rate. Click on the Clocks tab to open CLOCK CONFIGURATOR pane. In this pane click on the Input clock settings icon. Set the Input clock frequency to 16 MHz as shown. This is important because Arduino UNO board has a 16 MHz crystal. Now we are all set. We have added all the software components required and ready to generate the project. The only problem with Atmel Start is, you can re-configure the project once it is generated. You will have start from fresh project. I think, it is a minor inconvenience and can be forgiven 🙂 Click on GENERATE PROJECT to generate the project. You will need active internet connection for this. Provide the Project Name and location, and click OK. Note that, the atmel studio project becomes a part of the Solution. One solution can have multiple projects. It is always better to create a new solution for the new project. If you receive a warning about the component versions, just click YES. Wait for few seconds to let Atmel Studio create your project. Writing Hello World Program From the Solution Explorer, expand the Solution, and Hello_world_uno project and open c file. Note: If Solution Explorer is not visible to you, then click Window > Reset Window Layout to see this pane. Add the MY_DELAY macro, and printf statement to print Hello World text as shown in the following code snippet in your main.c file #include #define MY_DELAY for(unsigned long int i = 0; i<5000000; i++); int main(void) { /* Initializes MCU, drivers and middleware */ atmel_start_init(); /* Replace with your application code */ while (1) { printf("Hello World !!\n\r"); MY_DELAY; } } Click Build > Build Solution to build the project. After few seconds, output window should show the success message. Downloading the code If you do not have UNO programmer configured in your Atmel Studio. Follow instructions given in the post to understand how to Program / Flash Arduino Uno with Atmel Studio. Click on Tools > UNO avrdude (Ensure that you have correct COM port specified for this programmer. Refer to tutorial mentioned in the above step.) Open your favourite terminal client (say Tera Term) and configure the serial port for 115200 baud rate, 8 data bits, 1 stop bit, and no parity bits. Observe the “Hello world” output 🙂 #arduino #hello-world #atmel-studio #uno