Author Topic: From Arduino to Atmel Studio  (Read 8288 times)

0 Members and 1 Guest are viewing this topic.

Offline Tricka90Topic starter

  • Regular Contributor
  • *
  • Posts: 50
From Arduino to Atmel Studio
« on: April 16, 2017, 08:12:19 am »
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) ?
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: From Arduino to Atmel Studio
« Reply #1 on: April 16, 2017, 09:04:33 am »
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
 

Offline bingo600

  • Super Contributor
  • ***
  • Posts: 1988
  • Country: dk
Re: From Arduino to Atmel Studio
« Reply #2 on: April 16, 2017, 05:03:51 pm »
I can recommend P.Fleury's uartib , from here
http://homepage.hispeed.ch/peterfleury/avr-software.html


And then just use the redirect section from here , now you have a fully working "printf"

Redirecting STDIN and STDOUT to UART
https://www.appelsiini.net/2011/simple-usart-with-avr-libc


Ohh remember the right lib , if you need to printf floats
http://www.embedds.com/using-standard-io-streams-in-avr-gcc/


/Bingo
« Last Edit: April 16, 2017, 05:05:56 pm by bingo600 »
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: From Arduino to Atmel Studio
« Reply #3 on: April 17, 2017, 06:06:18 am »
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 connection easily, but I have no example code online. It is not a library for beginners though.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Tricka90Topic starter

  • Regular Contributor
  • *
  • Posts: 50
Re: From Arduino to Atmel Studio
« Reply #4 on: April 17, 2017, 08:48:13 am »
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?
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: From Arduino to Atmel Studio
« Reply #5 on: April 17, 2017, 09:12:55 am »
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)
« Last Edit: April 17, 2017, 10:11:47 am by Nusa »
 

Offline Tricka90Topic starter

  • Regular Contributor
  • *
  • Posts: 50
Re: From Arduino to Atmel Studio
« Reply #6 on: April 17, 2017, 09:23:01 am »
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?
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: From Arduino to Atmel Studio
« Reply #7 on: April 17, 2017, 10:06:18 am »
"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.
« Last Edit: April 17, 2017, 10:08:08 am by Nusa »
 

Offline Tricka90Topic starter

  • Regular Contributor
  • *
  • Posts: 50
Re: From Arduino to Atmel Studio
« Reply #8 on: April 17, 2017, 10:36:57 am »
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?
 

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: gb
Re: From Arduino to Atmel Studio
« Reply #9 on: April 17, 2017, 11:18:23 am »
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.
 

Offline Gibson486

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: From Arduino to Atmel Studio
« Reply #10 on: April 18, 2017, 01:18:48 pm »
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.
 

Offline Gibson486

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: From Arduino to Atmel Studio
« Reply #11 on: April 18, 2017, 01:26:05 pm »
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?

Moving 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.

   
 

Offline HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: gb
Re: From Arduino to Atmel Studio
« Reply #12 on: April 18, 2017, 02:16:50 pm »
Moving to Atmel Studio will not give you a performance boost. If anything, I would not be surprised if it even used the same compiler.

They do. Both use GCC.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: From Arduino to Atmel Studio
« Reply #13 on: April 18, 2017, 04:16:12 pm »
People who bash the Arduino IDE and library are hating for no reason.
its 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.

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,
true. in fact some view the high level libraries as a positive, not negative.

Of course, it forces you to maintain setup() and loop() functions
not 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.

so what exactly is wrong with using Arduino IDE?
very 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...
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: From Arduino to Atmel Studio
« Reply #14 on: April 18, 2017, 04:52:22 pm »
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!

See https://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.
« Last Edit: April 18, 2017, 04:55:10 pm by Ian.M »
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1668
  • Country: us
Re: From Arduino to Atmel Studio
« Reply #15 on: April 18, 2017, 05:05:08 pm »
The biggest reason to use Atmel Studio is its debugging capabilities. The Arduino IDE has no debugging capabilities.
Complexity is the number-one enemy of high-quality code.
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: From Arduino to Atmel Studio
« Reply #16 on: April 18, 2017, 05:39:48 pm »
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!
Not 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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: From Arduino to Atmel Studio
« Reply #17 on: April 18, 2017, 05:49:26 pm »
The interrupt vector *will* be seized:
wiring.c:44
Code: [Select]
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ISR(TIM0_OVF_vect)
#else
ISR(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.
 

Offline MattSR

  • Regular Contributor
  • *
  • Posts: 95
  • Country: au
Re: From Arduino to Atmel Studio
« Reply #18 on: April 19, 2017, 11:27:39 pm »
How are people finding the latest Atmel studio? Has it improved or gone downhill?
 

Offline JoeN

  • Frequent Contributor
  • **
  • Posts: 991
  • Country: us
  • We Buy Trannies By The Truckload
Re: From Arduino to Atmel Studio
« Reply #19 on: April 20, 2017, 05:12:26 am »
How are people finding the latest Atmel studio? Has it improved or gone downhill?

It supports a lot of newer devices.  I find it useful in that regard.
Have You Been Triggered Today?
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: From Arduino to Atmel Studio
« Reply #20 on: April 20, 2017, 06:46:35 am »
Quote
How are people finding the latest Atmel studio? Has it improved or gone downhill?
Most 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.
 

Offline MattSR

  • Regular Contributor
  • *
  • Posts: 95
  • Country: au
Re: From Arduino to Atmel Studio
« Reply #21 on: April 21, 2017, 01:48:56 am »
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
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ca
Re: From Arduino to Atmel Studio
« Reply #22 on: April 25, 2017, 04:58:21 pm »
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?
...

If 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.).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf