From Arduino to Atmel Studio - Page 1
Forum section: electronics / general

author: Tricka90
author_rank: Regular Contributor
timestamp: April 16, 2017, 08:12:19 am
content: I'm slowly moving from Arduino IDE to Atmel Studio to program the popular atmega328p. Since the Serial.print() Arduino function is very comfortable and useful, I'm looking for an easy way to display the values of the variables when using Atmel Studio. What is the best way in your opinion?Of course I could add a series of LEDs to the microcontroller in order to display the values in binary or I could even connect an LCD screen, but these solutions require the use of lots of ports. How can you easily check the variables without Arduino IDE (and without using expensive external tools) ?

author: picandmix
author_rank: Frequent Contributor
timestamp: April 16, 2017, 09:04:33 am
content: If you are stil wanting to use Arduino C++ then use the free Visual Micro add on.If not, then check out Ytube for some good tutorials on Studio6/7 and Debugging.http://www.visualmicro.com/page/Arduino-for-Atmel-Studio-7.aspx

author: bingo600
author_rank: Super Contributor
timestamp: April 16, 2017, 05:03:51 pm
content: I can recommend P.Fleury's uartib , from herehttp://homepage.hispeed.ch/peterfleury/avr-software.htmlAnd then just use the redirect section from here , now you have a fully working "printf"Redirecting STDIN and STDOUT to UARThttps://www.appelsiini.net/2011/simple-usart-with-avr-libcOhh remember the right lib , if you need to printf floatshttp://www.embedds.com/using-standard-io-streams-in-avr-gcc//Bingo

author: obiwanjacobi
author_rank: Super Contributor
timestamp: April 17, 2017, 06:06:18 am
content: I would suggest using a ring/circular buffer (and interrupts) for interacting with the usart and only block/wait when the buffer is full (when writing).This will minimize the (side)effect on you program when printing vars to the terminal.Atmel Studio 7 will also import Arduino projects - that may also be a valid starting point.My ATL library has facilities for setting up a buffered Serial connectioneasily, but I have no example code online. It is not a library for beginners though.

author: Tricka90
author_rank: Regular Contributor
timestamp: April 17, 2017, 08:48:13 am
content: Thanks for your valuable advices, I'll study and try your solutions. There's another thing which is not perfectly clear to me: lots of people say they don't like Arduino IDE because of the simplified high level libraries. But the truth is Arduino IDE doesn't force you to use libraries (like digitalWrite, analogRead etc.), in fact it allows you to program at low level if you want, setting bits on registers and so on, so what exactly is wrong with using Arduino IDE? Of course, it forces you to maintain setup() and loop() functions but are there other bad things?

author: Nusa
author_rank: Super Contributor
timestamp: April 17, 2017, 09:12:55 am
content: There's nothing wrong with any of the development environments, including the IDE. Some are easier for the non-programmer to get started in, others are easier for an experienced programmer to transition to. In the end, it's mostly about personal preference.(edit to fix spelling)

author: Tricka90
author_rank: Regular Contributor
timestamp: April 17, 2017, 09:23:01 am
content: So you're saying there's no reason an Arduino IDE user should move to Atmel Studio? He should only learn to program at low level in Arduino IDE and he'll obtain high performance without moving to Atmel Studio?

author: Nusa
author_rank: Super Contributor
timestamp: April 17, 2017, 10:06:18 am
content: "should"? All I said is you probably don't "need" to switch. If you "want" to, you don't need any further reason.Development environments are tools to make life easier, but they don't magically imbue you with the ability to design and program.Libraries are so you can accomplish things quickly by reusing tested code, not because they're inherently good or bad. You don't have to use them.You CAN accomplish everything with command line tools (which can be invoked directly, rather than having your tools do it for you), using whatever text editor you liked. I remember when that was the ONLY option to get things done, but then I go way back to punch cards and paper tape readers.

author: Tricka90
author_rank: Regular Contributor
timestamp: April 17, 2017, 10:36:57 am
content: Thank you for your help, now it is clearer. So that means if I write a low level C code in Atmel Studio and then I write the exact same code in Arduino IDE I will obtain the same result because the IDE won't alterate the code in any way?

author: HwAoRrDk
author_rank: Super Contributor
timestamp: April 17, 2017, 11:18:23 am
content: More or less, yes.There are some things to note, though. The Arduino IDE does some preprocessing of .ino code to add function declarations to turn it into proper C++ code, which under some circumstances has been known to mess things up. Also, even if you don't use it, the Arduino library code will still be compiled in, adding overhead. Plus there's the initialisation of stuff the library does before you even hit setup() - things like timers, etc. - that may not be what you want to happen, but can't avoid.It's also worth noting that if you have an appropriate programming device (like an AVR ISP MkII), the Arduino IDE will let you put your program on the chip without the bootloader, just like Atmel Studio.

author: Gibson486
author_rank: Frequent Contributor
timestamp: April 18, 2017, 01:18:48 pm
content: People who bash the Arduino IDE and library are hating for no reason. I agree, it is pretty simplified and little too abstract, but it works for its purpose. In fact, it worked so well, that manufactures like ST are sort of trying to emulate what they have done (for better or worse). People bash Arduino all the time, but you are correct, you do not have to use the libraries. In fact, you do direct register calls in the Arduino environment because all it is doing is wrapping around Atmel's code base.I have done what you are trying to do. There is plug in that allows you to use Atmel Studio with the Arduino code base. It is probably the easiest way to bridge between the two IDEs.

author: Gibson486
author_rank: Frequent Contributor
timestamp: April 18, 2017, 01:26:05 pm
content: Quote from: Tricka90 on April 17, 2017, 09:23:01 amMoving to Atmel Studio will not give you a performance boost. If anything, I would not be surprised if it even used the same compiler. The Arduino IDE is a crippled IDE with no features. However, lots of people do not need those features. It would be very easy to get lost and figuring what those features do as well. The biggest plus that I got from Atmel Studio was the fact that I could download the machine code from the micro and transfer it to another micro without having the source on my computer. You can do this with AVRdude with Linux as well.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: April 18, 2017, 02:16:50 pm
content: Quote from: Gibson486 on April 18, 2017, 01:26:05 pmThey do. Both use GCC.

author: Mechatrommer
author_rank: Super Contributor
timestamp: April 18, 2017, 04:16:12 pm
content: Quote from: Gibson486 on April 18, 2017, 01:18:48 pmits ok if your program is few lines doing led blinks. try develop a program consisting 10+ files, tens of thousands of lines in each file. you'll know how high is the sky.Quote from: Tricka90 on April 17, 2017, 08:48:13 amtrue. in fact some view the high level libraries as a positive, not negative.Quote from: Tricka90 on April 17, 2017, 08:48:13 amnot true. you can leave setup() empty and make your own loop in the loop()in other word, you can achieve code speed and structure efficiency of arduino the ide just as the atmel studio or any other C/C++ IDE.Quote from: Tricka90 on April 17, 2017, 08:48:13 amvery limited color aided text, auto indentation option. has some stupid notion that ino name must be the same as folder name, and some other minor things. of course you can argue this. but try to argue this... turtle slow compilation time, no extensive debug, step into, step through feature in PC before actually uploading the code and running it in the chip. but as i said, it doesnt matter if your code is just a led blinker logic. i sometime fired up arduino the ide just to make a slight upgrade modification to my 3d printer reprap firmware. the compilation and uploading took minutes, i just cant imagine how much time spent (wasted) by the original fw developer developing and testing such massive fw from scratch in arduino the ide.anyway, if i want to implement Serial.print() in atmel studio, i'll just go and dig how they do it in the arduino ide library...

author: Ian.M
author_rank: Super Contributor
timestamp: April 18, 2017, 04:52:22 pm
content: Actually you can totally scrap the setup() and loop() functions and the Arduino IDE's pre-compilation mangling. Just put a list of headers you need to use in the .ino file as #include directives with NO OTHER CODE. and put all the .c .cpp and .h files you want for the project in the sketch folder.Limitations:* You cannot have a source file with the same name as the sketch, as the pre-compilation mangler creates a .cpp file of that name* It will always attempt to link with all the default Arduino libraries. This means you have to avoid reusing Arduino function, variable and constant names for your own stuff.* The Arduino libraries seize the Timer 0 overflow interrupt vector. If you want it for your own use - tough luck!Seehttps://www.eevblog.com/forum/blog/adventures-in-avr-isp-programming/msg1149590/#msg1149590, where I also discussed this, and linked to the site that originally showed me this trick. A little later in that topic, I implement standard C printf() support to the UART of an ATmega328P *without* going through the Arduino libraries.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: April 18, 2017, 05:05:08 pm
content: The biggest reason to use Atmel Studio is its debugging capabilities. The Arduino IDE has no debugging capabilities.

author: retrolefty
author_rank: Super Contributor
timestamp: April 18, 2017, 05:39:48 pm
content: Quote from: Ian.M on April 18, 2017, 04:52:22 pmNot out of luck.Just as one does not have to utilize arduino timing (and other) functions, it's also simple to put a one-liner in the setup function to disable interrupts for Timer 0. One is then free to ignore or reuse Timer 0 as one wishes.

author: Ian.M
author_rank: Super Contributor
timestamp: April 18, 2017, 05:49:26 pm
content: The interrupt vector *will* be seized:wiring.c:44Code:#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)ISR(TIM0_OVF_vect)#elseISR(TIMER0_OVF_vect)#endif{// copy these to local variables so they can be stored in registers// (volatile variables must be read from memory on every access)unsigned long m = timer0_millis;unsigned char f = timer0_fract;m += MILLIS_INC;f += FRACT_INC;if (f >= FRACT_MAX) {f -= FRACT_MAX;m += 1;}timer0_fract = f;timer0_millis = m;timer0_overflow_count++;}There's no clean way to avoid it short of writing your own board support package that 'de-arduinos' the libraries.

author: MattSR
author_rank: Regular Contributor
timestamp: April 19, 2017, 11:27:39 pm
content: How are people finding the latest Atmel studio? Has it improved or gone downhill?

author: JoeN
author_rank: Frequent Contributor
timestamp: April 20, 2017, 05:12:26 am
content: Quote from: MattSR on April 19, 2017, 11:27:39 pmIt supports a lot of newer devices. I find it useful in that regard.

author: westfw
author_rank: Super Contributor
timestamp: April 20, 2017, 06:46:35 am
content: QuoteMost reports are that v5 (the first version based on Visual Studio) was a disaster, and things got a lot better with 6.I haven't heard much about 6 vs 7; it seems to be a wash. v7 doesn't run on WXP any more, which is unfortunate for me personally, since that's what I like to run as VMs on my Mac. (W8 and W10 dont' run nearly so well in a VM.)All of the VS-based Atmel Studios are hugh (3-5GB install) and slow to start up.

author: MattSR
author_rank: Regular Contributor
timestamp: April 21, 2017, 01:48:56 am
content: Bugger - I haven't been able to find a nice Linux or OSX based toolchain that's as easy to use as the older Atmel Studio...I guess I'll just have to keep plugging away with what I have!Cheers,Matt

author: macboy
author_rank: Super Contributor
timestamp: April 25, 2017, 04:58:21 pm
content: Quote from: Tricka90 on April 16, 2017, 08:12:19 amIf you really like Arduino print() then port it over. There is nothing at all that is proprietary or special about it. It (as all Arduino code) is just plain C++. Port it over. Look under hardware/arduino/avr/cores/arduino/Print.*The .print() functions are simply a series of overloaded functions with various different input parameters. The compiler determines which function with the name "print" should be called in each case based upon the parameters that you call it with. After all the conversions, the resulting string is eventually sent to the device (serial port or whatever) using the write() function. That is the key to porting this code, you need to implement a write() function that accepts a null terminated string (array of char) and delivers that string to you somehow (e.g. send to UART, or display on LCD, etc.).