Transitioning from Arduino IDE 2 to Microchip Studio - Page 1
Forum section: electronics / general

author: mvno_subscriber
author_rank: Regular Contributor
timestamp: April 15, 2023, 08:27:55 pm
content: Hi,I'm trying to move away from Arduino and thus adapt my code and make it work in Microchip Studio.I'm having a few issues. First, Microchip Studio has a "Create project from Arduino Sketch" option when creating a new project. I tried this, it complained about a missing "Arduino.exe" in the Arduino application folder. Renamed "Arduino IDE.exe" to "Arduino.exe", it halted along but only imported my main sketch file. I had to manually copy over header files.Also, it seems to not have properly imported the arduino libraries. For example, "Arduino.h" is missing.So, I thought I should perhaps start a new "native" project, import my files and adapt accordingly. However, I have no idea whether I should use AVR XC8 or GCC, or what this even means in practice.Is all this hassle because I have too new a version of Arduino IDE? I understand version 2 has made some radical changes to file locations and so forth.What is the best way for me to move forward with this? My codebase is currently not very large, and apart fromanalogRead(),delay()and some register constants (likePORTD,DDRDetc) I'm not heavily dependent on the Arduino libraries as far as I can tell.I will be getting an Xplained Mini board in the near future, but being able to use the Arduino Uno in the meantime would be very practical.

author: barshatriplee
author_rank: Regular Contributor
timestamp: April 16, 2023, 02:25:06 am
content: You can create a new "native" Microchip Studio project and manually import your files. This will give you more control over the project and allow you to remove any unnecessary Arduino libraries and code that you're not using.

author: james_s
author_rank: Super Contributor
timestamp: April 16, 2023, 03:57:59 am
content: It might be expecting an older version of the Arduino IDE. Isn't 2.0 quite a bit different? I've run into several challenges with Arduino caused by having the wrong version of the IDE.

author: Lindley
author_rank: Regular Contributor
timestamp: April 16, 2023, 08:45:51 am
content: You want to add in vMicro to Studio, which allows you use run your existing and new Arduino ide projects, as Studio with Vmicro will automatically save your files in the Arduino folder, uless you specify differently.You can still load Studio sketches back into the Arduino ide.This link shows how to do it with Microchip studio, which is , as far as we know, identical to the older Atmel studio we use with vMicro.https://www.visualmicro.com/page/Arduino-for-Atmel-Studio-7.aspxSuggest you keep your Arduino IDE as it handy for loading in new libraries and quiclky viewing other sketches etc etc

author: westfw
author_rank: Super Contributor
timestamp: April 16, 2023, 07:57:49 pm
content: QuoteAFAIK, Microchip has never done (nor claimed) anything specific to allow Studio to import sketches from the IDE 2.0.That said, there isn't that much that has changed in 2.0 WRT locations of files and cores and such. (Hmm. I think in 1.x, there was still a copy of the AVR core and tools in the Programs Files directory of the IDE, but in 2.x, everything has moved to the AppData location.)It's not entirely clear that Studio ever got past the 1.5ish "revised 3rd party specs" that moved 3rd party boards to the AppData directories, or that it ever worked "well", even before that.It's not clear whether Studio is under "active" development, or whether Microchip is going to abandon it and migrate users to MPLABX. :-(QuoteArduino.h is considered part of the Arduino Core, rather than a "library." (although that "core" code and it's include files might be regarded as a library by Studio...)QuoteYou should use gcc (the Arduino IDE uses gcc.)XC8 is essentially GCC with added restrictions, and perhaps different libraries. Last time I looked, XC8 had essentially broken floating point support for AVR by replacing the avr-libc functions with code that was about 10x bigger. :-(QuoteWhat is your actual goal? If you are just after a "better" IDE for Arduino sketches, that's going to be different than if you want to transition "past" the Arduino framework entirely.delay() is easily replaced by _delay_ms() from avr-libc. (but replacing millis() is harder.)PORTD, DDRD, etc, is NOT from Arduino; those are the Atmel-provided definitions.In either case, you'll need to pay more attention to a bunch of the stuff that you've admitted to not knowing, with more diffuse documentation, less community support, and less actual "steal-able" code for supporting random external peripherals.

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: April 17, 2023, 03:00:02 am
content: VS code with Platform IO seems to be a popular alternative. And it will import Arduino sketches.

author: westfw
author_rank: Super Contributor
timestamp: April 17, 2023, 06:03:53 am
content: QuoteFrom IDE v2.x?

author: uliano
author_rank: Regular Contributor
timestamp: April 17, 2023, 08:04:05 am
content: sorry for jacking in...Quote from: westfw on April 16, 2023, 07:57:49 pmMicrochip studio is EOL and no more in development.QuoteId' like to be able to debug with Atmel-ICEI 'm able to import .ino's with MegacoreX or DXCore (which are the most interesting) with MPLABX but then I can't debug. Is it ever possible? (given that someone can understand that mess)With microchip studio, on the contrary I'm not able to create new project using any of the custmo cores/boards I installed into Arduino.From what you say above I'm hoping that somewhen in th past files for external core suppot got moved by arduino adn that could be the reason Microchiop studio isn't able to find them anymore.So question iswhere were those files stored before being moved under appdata?

author: mvno_subscriber
author_rank: Regular Contributor
timestamp: April 17, 2023, 08:04:54 am
content: Thanks a lot for the replies, the main reasons I want to move away from Arduino are not only proper development tools and debugging, but I also find it difficult to work with many of the restrictions. For example, I can't (or it's difficult to) program the fuses, I have limited interrupts, and the way Arduino uses its own pin numbering scheme is very frustrating. I'll be using the MCU standalone.I have programmed PIC controllers in assembly before. C/C++ is new to me, but I've worked as a developer in java/.net for many years so I guess this is the "middle ground". As such, Visual Studio isn't unknown, but still I do realize there is a steep learning curve. I won't be doing any protocol interfacing (except IR remote control), so there's a limited need for specialized libraries.

author: mvno_subscriber
author_rank: Regular Contributor
timestamp: April 17, 2023, 08:05:58 am
content: Quote from: uliano on April 17, 2023, 08:04:05 amWait, what? What do people use, then?

author: uliano
author_rank: Regular Contributor
timestamp: April 17, 2023, 08:09:55 am
content: MPLABX, if they can...

author: mvno_subscriber
author_rank: Regular Contributor
timestamp: April 17, 2023, 08:16:33 am
content: Wow.. and no telling on the product page! Good I hadn't started migrating yet, then. I'll toss this silly putty out of my window and grab a copy of MPLABX, then.

author: uliano
author_rank: Regular Contributor
timestamp: April 17, 2023, 08:27:46 am
content: I woudn't be so smug if I were you...

author: Lindley
author_rank: Regular Contributor
timestamp: April 17, 2023, 07:53:57 pm
content: If you are not happy staying with Studio, then agree that Platform IO is probably the best for you.Its a newish program, 2014 , also based on Microsoft VS and the Platform IO Plug In is still being regularly developed and has a good following.Considerably different to using the Arduino IDE and has loads of features you are looking for.eg fuse programming -https://docs.platformio.org/en/stable/platforms/atmelavr.html#fuses-programmingMplabX took several years to iron out many of its bugs, so no idea what their replacement for Studio would be like, if at all ?

author: westfw
author_rank: Super Contributor
timestamp: April 17, 2023, 07:54:35 pm
content: Quote\Program Files\Arduino\hardware\<less clear>QuoteReference? There was a PCN from 2019 when they discontinued the physical DVD, but I haven't seen anything but speculation since then...

author: uliano
author_rank: Regular Contributor
timestamp: April 18, 2023, 05:10:29 am
content: I have read it some time ago (~1 year??) on Avrfreaks, possibly by Microchip emplyee, (but I forgot the reference): Microchip Studio won't ever be upgraded for Window 11 (even if it works seamlessly) and its support will crease in 2025 together with windows 10. Microchip is trying to converge all platforms to MPLABX (which would make a lot of sense if MPLABX weren't that huge pile of crap)Maybe if I install an older version of arduino I can shad light over <less clear> do you remember which version?

author: westfw
author_rank: Super Contributor
timestamp: April 18, 2023, 05:54:25 am
content: QuoteIt may be before there was a "board manager", and I'm just remembering the instructions for how to install new cores without it. Ie:https://github.com/MCUdude/MiniCore#manual-installation(I'm not sure that ever worked for boards that required a new compiler?)

author: uliano
author_rank: Regular Contributor
timestamp: April 18, 2023, 06:46:07 am
content: Update, sad.I succeeded in making Microchip studio see the third party cores by installing arduino 1.6.4 (the first one with board manager) but, alas, neither with MegacoreX nor with DxCore Microchip studio was able to produce a viable project (thrown some errors here and there)I'm afraid I have to quote Gandalf here: Microchip Studio way to Arduino is shut.MPLABX, instead, can produce working projects with those cores. but I declare myself unable to debug using that pile of steaming crap. And that was the only reason to go that way.

author: uliano
author_rank: Regular Contributor
timestamp: April 18, 2023, 08:24:52 am
content: Update, bis. Sad again.As I didn't waste enough time with microchip crappy sw I went a little over than blinky and imported the sketch in MPLABX with MegacoreX.The led blinks but, alas, serial monitor isn't working (and with Arduino ide it was). It's not even a a clock question that pin simply doesn't go low, ever.So, at least for me, the choice is dichotomic: either Microchip Studio and its usable debugger OR Arduino libraries.

author: Simon
author_rank: Unknown
timestamp: April 23, 2023, 07:47:23 pm
content: Here's a tip, just forget about the arduino, you are either using it and it's lets say specific way of doing things or you are letting yourself loose on a microcontroller and now have full control over it and are not tied to the particular one the arduino happens to use.

author: Simon
author_rank: Unknown
timestamp: April 23, 2023, 07:49:19 pm
content: Quote from: uliano on April 18, 2023, 08:24:52 amDo you know how much code is required to set the serial port up? less than 10 lines. Do you know how much code it takes to send a message?"serial port buffer" = "data you want to send"Seriously forget the arduino.

author: tooki
author_rank: Super Contributor
timestamp: April 24, 2023, 11:26:30 am
content: Quote from: westfw on April 17, 2023, 06:03:53 amSketches themselves aren’t specific to an IDE version.PlatformIO doesn’t rely on an installed instance of the Arduino IDE for its Arduino libraries (it downloads them itself) so it doesn’t need any installed IDE to import them.Bearing in mind that it’s also easy to do yourself:1. Make a new project in PlatformIO using the Arduino framework.2. Copy your code into the main.cpp file.3. Install the libraries used into the project4. In your main.cpp file, create function prototypes for any of your own functions.That’s it.In fact, if you use the .ino file extension, you don’t even need to add the function prototypes. But you miss out on some IntelliSense (code autocomplete) features.

author: westfw
author_rank: Super Contributor
timestamp: April 25, 2023, 11:59:26 pm
content: QuoteI didn't' know that. Neat! It should help a lot, assuming that it gets the correct libraries for each platform (ie the SPI library is different for SAMD vs AVR.)

author: tooki
author_rank: Super Contributor
timestamp: April 26, 2023, 07:36:53 am
content: Quote from: westfw on April 25, 2023, 11:59:26 pmIt knows.I haven’t looked into how it’s implemented exactly, but basically, in PlatformIO, a project (or more specifically, the build environment for the project) has two core settings: the software framework (Arduino, CMSIS, CubeMX, etc.) and the board (Arduino Uno, ESP32 dev kit, STM32 Nucleo L432, etc). The latter is what defines all the hardware, which frameworks are available, the toolchain used, etc. In either case, it downloads it as needed.One of the big advantages of PlatformIO over the Arduino IDEs is library management. Whereas Arduino has the “easy” but problematic approach of installing libraries globally, PlatformIO has you install libraries to a project, so that you can use specific library versions for each project, including the not-so-rare occurrence of third party libraries with conflicting names. (*cough* DS3231 *cough*)So via the board definition it will select and procure the correct SPI library for your board.You can also assign multiple build environments within a project — for example, Arduino UnoandESP32 dev kitandArduino Dueanda compatible Nucleo board — and then select which one you want to compile and flash. Each build environment has its own library definitions, so if you had MCU-specific code, you could either use #ifdef blocks to insert build environment specific code (for example, #ifdef ARDUINO_AVR_UNO for the Uno and #ifdef ARDUINO_ESP32_DEV for the ESP32 board), or you could save the hardware-specific code to hardware-specific libraries with the same filenames and then use the build environment settings to include the correct one for each.

author: uliano
author_rank: Regular Contributor
timestamp: April 27, 2023, 07:11:46 am
content: Quote from: Simon on April 23, 2023, 07:49:19 pmMy trajectory started with Atmel Studio, then I adopted VSCode for many other stuff and become addicted to IntelliSense so I switched to Platformio that, for avrxxxDx, allows you to create only "Arduino framework" projects. The fact that the framework is there doesn't force you to use its API, in fact I only use millis() and Serial, the rest of the code accesses peripheral registers directly.On occasion I feel the lack of the debugger and I would have liked to be able to convert the project for Microchip Studio or MPLABX IDE. Alas, I can't.Besides, I find your register quite patronizing.

author: tooki
author_rank: Super Contributor
timestamp: April 27, 2023, 09:42:25 am
content: Quote from: Simon on April 23, 2023, 07:47:23 pmThis shows that you know very, very little about Arduino, and should probably refrain from commenting on it so vociferously until you learn more about it.1. You have nearly full control over Arduino hardware. You can write directly to registers. Pretty much the only thing you can’t change much is the programming fuses. Not an issue in most situations. (And you can do it if you’re really intent on it.)2. You can choose to use Arduino library functions or not. You most certainly are not required to use them.3. The Arduino framework is supported on a wide array of hardware, not just “the particular one Arduino happens to use” (which is also wrong, since even Arduino-branded boards use a variety of architectures). You’re not “tied to” their hardware. Quite the opposite, I consider code portability to be one of the biggestadvantagesof the Arduino ecosystem: I can write code that will run unmodified on AVR, ESP32 (both Extensa or RISC-V models), SAMD, STM32, and others. That is not the case when using the manufacturers’ dev environments, where you’re more closely tied to their specific HAL syntax.Edit: fixed typo

author: Simon
author_rank: Unknown
timestamp: April 27, 2023, 08:58:40 pm
content: So what you are saying is that Arduino has morphed into a bunch of cross platform standard libraries. Given my experience with Arduino itself which yes, yes it's perfect, so perfect that it's only on here that I get nuggets of information on how profoundly nuts some of what is under it's skin is that I would never trust anything with the arduino brand. STM32? look, just get up to date and have chatGPT write your code

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 28, 2023, 01:07:00 am
content: As formulating clear specifications is often the hard part, can we use ChatGPT to have it generate a well-structured query for ChatGPT to generate your code?

author: westfw
author_rank: Super Contributor
timestamp: April 28, 2023, 03:00:18 am
content: QuoteSuch as?The usual complaint is things like digitalWrite(), which is some 50x slower (on AVR) than the single instruction that sort-of does the same thing, as long as you have completely different assumptions and requires for the arguments.I could write a paper on things that I think Arduino had done wrong, but very little of it approaches "profoundly nuts" (and the biggest mistakes, IMO, are in trying to maintain backward compatibility in newer code for things that were idiosyncrasies of the original AVR (like "these board-level pins will have PWM capability", or "digitalWrite a 1 to a pin in INPUT mode turns on the internal pullup." Sigh.)

author: uliano
author_rank: Regular Contributor
timestamp: April 28, 2023, 05:36:05 am
content: Quote from: westfw on April 28, 2023, 03:00:18 amThis stuff is also well known and avoidable, on the other hand there are parts of Arduino that are way better than any HAL or any 10 lines self made code. E.g. I read recently the implementation of uarts in dxCore and I couldn’t come even close to that. The approach to Arduino could/should be to keep the good and go bare metal for the rest.

author: tooki
author_rank: Super Contributor
timestamp: April 28, 2023, 11:41:37 am
content: Quote from: Simon on April 27, 2023, 08:58:40 pmIn a sense, yes. Though that’s nothing new. I didn’t touch Arduino until 2014 or 2015 and by then it was already on numerous platforms.Quote from: Simon on April 27, 2023, 08:58:40 pmCan you rewrite that run-on sentence into comprehensible English? The only part that’s clear is “I would never trust anything with the Arduino brand”.Quote from: Simon on April 27, 2023, 08:58:40 pmWhat about it?Look man, it’s fine to have legitimate complaints about something. But the hate against Arduino is often not grounded in reality. Or it’s based on issues that were resolved ages ago. Either way, I think it does people a big disservice to dissuade them from using it on principle, as opposed to using current, factual reasons to let people weigh which approach might be best for their use case. If I were writing the firmware for a car engine ECU, Arduino would be decidedly wrong, and a safety-certified toolchain from the MCU manufacturer would be appropriate, even if it had a steep learning curve. Conversely, if a novice wants to learn system integration by combining inputs and outputs, various peripherals, etc, and general code writing, but without having to delve into the registers of every external peripheral they want to use, Arduino is ideal. Then, as they run into the limitations of the Arduino IDE, they’ll move to a better one. And as they learn how to improve libraries, they will. And then they’ll write their own.

author: tooki
author_rank: Super Contributor
timestamp: April 28, 2023, 11:44:59 am
content: Quote from: uliano on April 27, 2023, 07:11:46 amWhat about the debugger in PlatformIO? I’ve used it a fair bit (on ESP32 hardware).

author: uliano
author_rank: Regular Contributor
timestamp: April 28, 2023, 02:20:38 pm
content: Quote from: tooki on April 28, 2023, 11:44:59 amEnjoyed it with ESP32 and STM32, not available for AVRxxxDx and ATmega480x, the AVR chips I use.For some, older, AVRs there isavr-stub

author: Simon
author_rank: Unknown
timestamp: April 28, 2023, 03:53:02 pm
content: I've been told that there is a weird thing with millis() where if you take two time stamps they may actually be back to front due to how it fudges it.I have struggled to do just normal code as if you code goes too deep like more than a couple of levels of if's it fails. Essentially my main issue is that if you have a problem it is hard to sort out and it's therefore not worth it especially when there ids little support other than a bunch of clueless people telling you how perfect it is. I can create pretty much the same functions like pinRead() etc very quickly on any MCU, I generally use the micro controller as a micro controller, the only reason I would use the arduino is so that I don't have to access the hardware at a low level but then the functionality you get is a fractional amount of the peripheral capabilities and I tend to be doing proper electronics not just using it as a PC so need to play with those peripherals. So sure I can do that in Arduino, but then what is the point of the arduino system if I am fiddling with the low level stuff.The panacea of just jumping from one micro to another very different one without having to change the code just does not exist unless you are severely underusing the thing.I mean tell me, with a SAMD based board does the ADC average samples? I use the SAMC, not sure if an Arduino layer for it has been written but one of the reasons I could get some what that it was not on an arduino board.... with a few lines of code the ADC is set up and runs a round robbin giving me 16 bit oversampled readings that are very filtered with a channel read each 1ms.It's not that I just dislike the arduino, what I dislike is the happy clappy lets just throw some shit together and feel proud of the thing we made while not really knowing how it works because we just downloaded some code that we have no idea what it does.If all you want to do is flip some pins, sure.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 28, 2023, 06:22:50 pm
content: Quote from: Simon on April 28, 2023, 03:53:02 pmOnce you start doing anything non-trivial, that's basically right.The same thing holds for cross-platform apps, like Java was thought to solve all of this and more (maybe the world hunger, if Java was popular right now, it would be saving the climate). But in practice, you still end up having to write platform-specific code in some ways and getting bugs that are specific to a given platform.With that said, you can write a sizable chunk of your code in a portable way and "isolate" the target-specific code as much as it makes sense. This is what I strive to do. This way you can reuse most of your code, but you *don't* expect not to need any porting work.Solutions like Arduino tend to hide this fact to the programmer and thus tend to make them assume there will be no work involved when switching targets.Portable code is great (unless you are making money off the number of LOCs you write), but aiming for the lowest common denominator is less so. It will get you just that.

author: Simon
author_rank: Unknown
timestamp: April 29, 2023, 08:46:43 am
content: Are you talking about Java as in PC's?From what I see many people coding micro these days are more computer programmers than electronics engineers. Stop anyone in the street and ask them what they think electronics is and they will basically start talking about computers. Dave did a drive time rant on this many years ago where he said that he ends up not challenging people who make the assumption he designs computers because it's just too much effort to explain.When we talk about PC's we assume an x86 standard platform, so if you have an OS you love chances are it will work on any x86 or derivative, this is a given to the point that many probably do not understand the level of standardization. Companies who might be at each others throats in advertising are actually working together in the background to make sure that their products are compatible so that they can both be picked for your OS of choice.Then we come to operating systems. Now I am well aware that there are many programs that work on multiple operating systems. So clearly whatever high level language they use, this is supported on any OS used and the same code will produce the same result, because obviously the whole world does not do the same work 2 or 3 times over just to get the same results. There will of course be a massive amount of work done by someone else to ensure the same resources are available in each OS and that they appear the same so that the code can simply be recompiled.But everything I have outlined above has one thing in common, the hardware!!!!! a motherboard from asus will function just as well as one from msi because they both use components that adhere to a standard. Micro controllers are hardware, and they are not standard!!! The closest we have to standardization is that we all use C and C++ and well there are others of course. I learnt C not because I felt it was what I needed but because everyone else uses it and if I wanted help asking for help in some obscure implementation of basic would probably not get me anywhere. the peripherals are different on any MCU, even MCU's of the same brand will have wildly different procedures for setting them up and features.I use the SAMC, it has 2 types of counter on the one chip! I can't even write standard code that will work on both types of counters on the same chip!!!. Well I could, but I would have to strip the functionality of the more complicated one down to that of the simpler one. Where do I stop? a TC has 2 PWM outputs, a TCC has 4 PWM outputs and can have a second set of 4 PWM outputs that are delayed relative to the main 4 so that you can do dead times for things like push-pull outputs.So do I write my standard code so that any counter is treated the same? well if I did that I would reduce a TCC down to about 1/4 of it's functionality just for something that is one of the functions the counters can do. In my current project I am actually running out of counters. If I did this I would actually have run out and have to get a bigger chip. So instead of the SAMC21J with 64 pins I would get a SAMC21N with 100 pins, oh but on this chip although you have more counters these extra ones share the interrupts of the already existing ones, this now complicates the code and actually slightly slows things down potentially, not to mention the cost.What I am saying is that there is no free lunch. A micro controller that is not running an operating system but being used as a real time device is an electronic component, it is an ASIC without the need to pay the cost of actually getting an ASIC made, why are we trying to use them as computers and expect the same panacea of compatibility from sub 1$ devices that we have from at the least, a $50 SBC which can still be a bit of an ask or a PC that costs several hundred dollars?