Author Topic: importing arduino "sketch" to Microchip Studio  (Read 8940 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
importing arduino "sketch" to Microchip Studio
« on: October 08, 2021, 08:52:46 am »
We had a work experience student design a project and write the code in Arduino. I now have the unhappy task of trying to carry this project on.

It uses Bluetooth which I understand nothing of as of yet
It uses an RTC that is not completely working yet and again I understand nothing of
I have discovered that there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE". I tried breaking the files up and there are already a few that are all .h files with code in them and this did not work.

So I decided that the next best thing would be to import it all into microchip studio where at least I can read the damn font on a 4k screen.

So I now find that I have errors galore, mostly related to not being able to find things that seem to be defined in a file called string.h, if defined is the right word as I don't read C++ and we are now into the bowls of the arduino code. I have tried including string.h into the files that have errors but this does not work.

Ultimately it would be nice to update this project working in C but how I work around things like Bluetooth and the RTC I do not know. I should almost start from scratch but that will be a big task as I have to reverse engineer it, understand how to rewrite it and then start again.

What are my options for working on arduino code? this all compiles in the arduino "IDE"
 

Offline PKTKS

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: importing arduino "sketch" to Microchip Studio
« Reply #1 on: October 08, 2021, 10:25:41 am »
IMHO...

"Importing"  anything out from Arduino to other proprietary workspace is **THE WORST**   possible  thing one can do.  Reason being as follow:

- Arduino is currently the "de facto" IDE of choice among almost everybody
- All serious MCUs vendors already committed to that (ST/Espressif/Atmel)
- A **HUGE** code base is already available (although using the C/C++ Arduino paradigm)
- The new IDE (still alpha) uses Eclipse base ideas - very good upgrade although not for now
- Code base on Arduino is vastly available - even my 6y old nephew wants it !!! :-DD

So.. forget getting out of it .. embrace it
install the manufacturer support Board and Libraries ..

You will save *ALOT* of time and effort.

There is no way back from this...
Soon everybody will understand how bad is to depend on "proprietary IDEs"

Bottom line is that "Arduino"  is no longer some sort of board ..
or group of folks disputing the ownership of MCU breadboards..

Arduino became the standard common base workspace developer suite..
An insane library is already available.. and growing

Talks like ArduinoIDE
Paul
« Last Edit: October 08, 2021, 10:29:53 am by PKTKS »
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #2 on: October 08, 2021, 10:41:55 am »
Well, the simplest workaround would probably be to use whatever editors float your boat to work on the files, but still use the Arduino IDE for compiling and cross loading.

But if you do use the Arduino IDE: File->Preferences allows you to change the interface scale and font size


 

Offline PKTKS

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: importing arduino "sketch" to Microchip Studio
« Reply #3 on: October 08, 2021, 10:47:30 am »
more 2 cents..

- Search the relevant downloads to install your target MCU tools...
- Install board and libraries for the target.
- Have  a look on  the very handy "arduino-cli" on github.. very good tool
- just in case STM holds support https://www.stm32duino.com/
- same to Espressif https://github.com/espressif/arduino-esp32
- same to several other goodies impossible to put here

Al stuff is currently based on GCC.. being 32bits older compilers are better..

Paul
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #4 on: October 08, 2021, 11:43:35 am »
I imported the project to studio as an arduino project and told it where my arduino IDE is etc.

The main errors are actually in the arduino code so sorry but you can keep you defacto standard somewhere very safe from me. After some keyword searching for one of the defines that had not been made according to the errors reported I found a note in a file stating that this was a known issue and if I came across a board that it did not work with to do a pull request. What is a pull request? sorry, I'm not messing with stuff like this, it saves no time at all. I have spend more time trying to find out what is going on and there seems to be no proper way to use multiple files.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #5 on: October 08, 2021, 12:20:56 pm »
From datestrings.cpp


// Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr
// But not all platforms define these as they should.  If you find a platform needing these
// defined, or if any this becomes unnecessary as platforms improve, please send a pull req.

found from error: Severity   Code   Description   Project   File   Line
Error      'strcpy' was not declared in this scope   ArduinoCore   *:\*****\Electronics Upgrade\Programming\Full Code\P1\P1\ArduinoCore\include\core\api\deprecated-avr-comp\avr\pgmspace.h   63

I have a couple of C++ books on order
 

Offline PKTKS

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: importing arduino "sketch" to Microchip Studio
« Reply #6 on: October 08, 2021, 12:34:37 pm »
Critical information is missing..

You need ate very first place define your board and proper settings inside IDE

This will "select" pre made configs to instruct GCC (aka Makefiles)

It  "seems"   you are fetching deprecated headers from an improper dated gcc version.

FYI  the IDE can and usually have multiple compiler versions and different set for different MCUs.

This is a much more advanced use of the IDE instead of simple point click vanilla Arduino old times..

Today use of the IDE involves setting multiple GCC versions for multiple MCUs

Paul
 

Offline DrG

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #7 on: October 08, 2021, 01:06:26 pm »

I have discovered that there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE". I tried breaking the files up and there are already a few that are all .h files with code in them and this did not work.
....
So I decided that the next best thing would be to import it all into microchip studio where at least I can read the damn font on a 4k screen.
...
What are my options for working on arduino code? this all compiles in the arduino "IDE"

You glossed over this point a bit and it may be your best approach. I once downloaded a demo program for Arduino which contained 11 files in the same directory. These files were .c, .cpp, .h and, of course, a single .ino. It gave me all sorts of aggravation until I changed  one or two lines in the .ino, including overcoming an extern definition in one of the files...

 LCD_ST7735S LCD; // note: added to overcome extern in lcd.h (just looked at it and my note)

I think you might have the greatest success in using the ardunio ide and trying to work through some issues causing errors, which may be easier to solve than you think. As far as included libraries (assuming that the ble and rtc are included libraries) always involve going to those libraries to examine the code.

...my two cents.
- Invest in science - it pays big dividends. -
 

Offline PKTKS

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: importing arduino "sketch" to Microchip Studio
« Reply #8 on: October 08, 2021, 01:37:31 pm »
(..)
You glossed over this point a bit and it may be your best approach. I once downloaded a demo program for Arduino which contained 11 files in the same directory. These files were .c, .cpp, .h and, of course, a single .ino. It gave me all sorts of aggravation until I changed  one or two lines in the .ino, including overcoming an extern definition in one of the files...
(.)
...my two cents.

This is actually how  everybody is building libs to the IDE... (interfacing)

Forget about making a multi file on the root base of the IDE paradigm.
It exists to newbies so to be easy and simple..

The devels are using the ~/library/MyLIB/<>   root to put everything needed in REAL *cpp and *h files the regular way..

It already contains a hell of a huge repos.

Including ours customized ones.
Paul
 

Offline DrG

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #9 on: October 08, 2021, 01:55:30 pm »
(..)
You glossed over this point a bit and it may be your best approach. I once downloaded a demo program for Arduino which contained 11 files in the same directory. These files were .c, .cpp, .h and, of course, a single .ino. It gave me all sorts of aggravation until I changed  one or two lines in the .ino, including overcoming an extern definition in one of the files...
(.)
...my two cents.

This is actually how  everybody is building libs to the IDE... (interfacing)

Forget about making a multi file on the root base of the IDE paradigm.
It exists to newbies so to be easy and simple..

The devels are using the ~/library/MyLIB/<>   root to put everything needed in REAL *cpp and *h files the regular way..

It already contains a hell of a huge repos.

Including ours customized ones.
Paul

I agree that it may be the best way, but that may not be the critical issue at this point because, as I see it, the OP is not writing the program but trying to get it to run and understand it with the intent of ultimately updating. It is already in multiple files in the root base, unless I am simply not understanding.

In my case, that was exactly what was happening - that is my point. Once I could get it to run and observe it, I could deal with using the lcd as I wanted to and without someone else's "library", unless I chose to do it that way. As to why it did not run when I download the sample code, I don't know.

But, again, just my two cents to try and get to a solution.

- Invest in science - it pays big dividends. -
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #10 on: October 08, 2021, 02:58:41 pm »
You can use Microsoft Visual Studio as the IDE with a plug-in https://www.visualmicro.com/  It knows where the files are located...
You can also use Visual Studio Code as the IDE: https://maker.pro/arduino/tutorial/how-to-use-visual-studio-code-for-arduino

The Arduino IDE itself is damn near unusable.  Who puts orange messages against a black background!  They're invisible!  Changing the color scheme is a true PITA.  OK, to be fair, I don't have one positive thing to say about the factory IDE.  But that's just me...

 

Offline dl6lr

  • Frequent Contributor
  • **
  • Posts: 458
  • Country: de
Re: importing arduino "sketch" to Microchip Studio
« Reply #11 on: October 08, 2021, 03:08:23 pm »
You can use Microsoft Visual Studio as the IDE with a plug-in https://www.visualmicro.com/  It knows where the files are located...
You can also use Visual Studio Code as the IDE: https://maker.pro/arduino/tutorial/how-to-use-visual-studio-code-for-arduino

The Arduino IDE itself is damn near unusable.  Who puts orange messages against a black background!  They're invisible!  Changing the color scheme is a true PITA.  OK, to be fair, I don't have one positive thing to say about the factory IDE.  But that's just me...

Voting up for using Visual Studio Code. Compiling big projects is a lot faster (or sometimes even possible) with the tool chain from platformio instead of using the Arduino IDE.

For the OP I would suggest to first getting it compiled with the Arduino IDE as it was developed. If everything works, you can migrate to another IDE, tool chain and project layout.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #12 on: October 09, 2021, 07:33:13 am »
Ultimately I want to be albe to switch microcontroller if I have to. I have 1'000 SAMC's on order but the arduino uses SAMD, my guess is they are all out of stock as used by people basing products off the Arduino plus it's a few cents cheaper. My hope is that I can find alternate libraries or work out how to use the Arduino libraries not in Arduino having stripped aut the Arduino references.
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #13 on: October 09, 2021, 09:07:49 am »
Heh. You'll just fail to communicate if you imply or think your preferred hardware is identified when you say "the arduino". I believe the AtMega328 is still the most common "Arduino" processor, and is the default assumption when not otherwise mentioned.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #14 on: October 09, 2021, 02:34:06 pm »
Heh. You'll just fail to communicate if you imply or think your preferred hardware is identified when you say "the arduino". I believe the AtMega328 is still the most common "Arduino" processor, and is the default assumption when not otherwise mentioned.

I can turn that back at you and say well you just assumed, I believe one of the big potential pitfalls of the Arduino is that it tries to have a uniform usage on many different micro controllers. Why would by Arduino I be implying the ATmega328?
 

Offline PKTKS

  • Super Contributor
  • ***
  • Posts: 1766
  • Country: br
Re: importing arduino "sketch" to Microchip Studio
« Reply #15 on: October 09, 2021, 06:30:17 pm »
Ultimately I want to be albe to switch microcontroller if I have to. I have 1'000 SAMC's on order but the arduino uses SAMD, my guess is they are all out of stock as used by people basing products off the Arduino plus it's a few cents cheaper. My hope is that I can find alternate libraries or work out how to use the Arduino libraries not in Arduino having stripped aut the Arduino references.

claims to have a working SAMC setup

https://github.com/mattairtech

never tried so can not tell you if works..

Things are changing way to fast
Paul
 

Online xrunner

  • Super Contributor
  • ***
  • Posts: 7513
  • Country: us
  • hp>Agilent>Keysight>???
Re: importing arduino "sketch" to Microchip Studio
« Reply #16 on: October 09, 2021, 06:47:08 pm »
It uses an RTC that is not completely working yet and again I understand nothing of ...

Heads up - if the RTC module is the same DS3231 like I've used before, you might want to inspect the battery. The circuit is designed for a rechargeable CR2032 but most of them come from China stuffed with a non-rechargeable CR2032 - not good. You can use a (non-rechargeable) CR2032 if you remove a resistor. Check this out -

https://arduino.stackexchange.com/questions/66681/ds3231-rtc-module-and-battery-problem
I told my friends I could teach them to be funny, but they all just laughed at me.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #17 on: October 09, 2021, 06:56:59 pm »
Why would by Arduino I be implying the ATmega328?

Because that's what the standard Arduino is and it's the most common variant by far, almost anybody is going to assume you mean atmega328 unless you specify otherwise. The Arduino versions based on other chips have different names.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #18 on: October 09, 2021, 08:30:09 pm »
Why would by Arduino I be implying the ATmega328?

Because that's what the standard Arduino is and it's the most common variant by far, almost anybody is going to assume you mean atmega328 unless you specify otherwise. The Arduino versions based on other chips have different names.

The specific chip is irrelevant to the discussion. We were talking about how to open the Arduino code in Microchip studio.
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #19 on: October 09, 2021, 11:01:24 pm »
Why would by Arduino I be implying the ATmega328?

Because that's what the standard Arduino is and it's the most common variant by far, almost anybody is going to assume you mean atmega328 unless you specify otherwise. The Arduino versions based on other chips have different names.

The specific chip is irrelevant to the discussion. We were talking about how to open the Arduino code in Microchip studio.

I'd agree if it wasn't the OP who added specific chips to the conversation. You're allowed to derail yourself.
 

Offline DrG

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #20 on: October 10, 2021, 12:23:07 am »
We had a work experience student design a project and write the code in Arduino. I now have the unhappy task of trying to carry this project on.

It uses Bluetooth which I understand nothing of as of yet
It uses an RTC that is not completely working yet and again I understand nothing of
I have discovered that there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE". I tried breaking the files up and there are already a few that are all .h files with code in them and this did not work.

So I decided that the next best thing would be to import it all into microchip studio where at least I can read the damn font on a 4k screen.

So I now find that I have errors galore, mostly related to not being able to find things that seem to be defined in a file called string.h, if defined is the right word as I don't read C++ and we are now into the bowls of the arduino code. I have tried including string.h into the files that have errors but this does not work.

Ultimately it would be nice to update this project working in C but how I work around things like Bluetooth and the RTC I do not know. I should almost start from scratch but that will be a big task as I have to reverse engineer it, understand how to rewrite it and then start again.

What are my options for working on arduino code? this all compiles in the arduino "IDE"

So, I read your original post again because the thread is becoming confusing, at least to me.

Your last line....this all compiles in the arduino "IDE" If that is so, then exactly what do you think that you will gain using VS? I assume that you figured out how to get a reasonable font on your 4K within the arduino ide - so, beyond that, it is not clear what you are complaining about or trying to fix - other than the obvious...some student wrote something and now you have to deal with it. I guess what I am saying is; the best option for working on arduino code that has already been written using the arduino IDE, including who knows what board and libraries, and is working (at least to some extent), is the arduino IDE.

If you are trying to translate it to C or C++, in order to "carry on" you should still be working in the ide until you can, at the least, see and understand all of the code - the student's .ino and as well as libraries that have been used. So much in there can be standard only to the evolution of arduino and I don't know anybody who thinks that 'it' follows C or C++ standards to a helpful extent.

For example, if he used an rtc library, such as rtclib, you need to go into the libraries directory, locate and go through the rtclib.h and rtclib.cpp files - to see what is not working and why it is not working. Certainly, you could rewrite that library in standard C, if you wanted to put forth the effort.

Bluetooth is more complicated and my guess is that the student used the esp32 library and so on and so forth. Even there I am guessing, but he either wrote his own stack (unlikely) or he used an existing library and that library is going to be dependent on code for the board (also available through the ide) - the point is that the source code is available to you using the arduino IDE in either case. To rewrite all that is, well, not much fun, I would imagine.

I have discovered that there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE". I tried breaking the files up and there are already a few that are all .h files with code in them and this did not work.

I think you are probably right, but it can be done. Why, however, did you do this and how is VS going to solve that for you?

I'm not trying to give you a hard time, it is just that as I think more about your OP, I just don't get exactly what you think VS is going to do for you?
« Last Edit: October 10, 2021, 12:37:36 am by DrG »
- Invest in science - it pays big dividends. -
 

Online xrunner

  • Super Contributor
  • ***
  • Posts: 7513
  • Country: us
  • hp>Agilent>Keysight>???
Re: importing arduino "sketch" to Microchip Studio
« Reply #21 on: October 10, 2021, 12:58:19 am »

I have discovered that there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE". I tried breaking the files up and there are already a few that are all .h files with code in them and this did not work.

DrG and Simon,

You can definitely split the code up into multiple parts using the Beta 12 Arduino IDE which is what I've been using for a project recently. Just make another tab or as many as you want. As you can see in the simplistic test I did, the compute() function is in part_2 and the main is in Part_1. It compiles them together just fine.
I told my friends I could teach them to be funny, but they all just laughed at me.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #22 on: October 10, 2021, 07:30:24 am »
The student is not a coding ace. He's good for a 17 year old that has been at electronics for 2 years and prefers the hardware design to software. Even in the Arduino IDE it's a rickety mess that just holds itself together. I can't straighten it out in the Arduino IDE either, I tried and it broke all over.

What I am trying to do is start again using what he wrote as a base so that I can change one thing at a time. If I can reuse any Arduino library I will. I am not sure what in an arduino library I would need to change to make it work. As far as I am aware the only main difference will be pin references. Of course every library will build on another so I will end up in a maze of chasing down libraries and sorting out their dependencies.

So for example I found the SD card library on mbed.com: https://developer.mbed.org/teams/mbed-official/code/FATFileSystem/#e2ab678eb692

Now it's all of 2 files, Surely SD card controlling is more complicated than that? well for starters there is no hardware level code there for the SPI bus because it is a generic library, but I suspect there is an SPI library somewhere (maybe on mbed.com) or I write my own lower level code and make my function names the same as those in the library like "_spi.write"

I don'n know C++ yet so have some books on the way as clearly  as soon as I try to touch anything written by anyone I will bump into C++
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #23 on: October 10, 2021, 09:54:15 am »
So for example I found the SD card library on mbed.com: https://developer.mbed.org/teams/mbed-official/code/FATFileSystem/#e2ab678eb692

Now it's all of 2 files, Surely SD card controlling is more complicated than that? well for starters there is no hardware level code there for the SPI bus because it is a generic library, but I suspect there is an SPI library somewhere (maybe on mbed.com) or I write my own lower level code and make my function names the same as those in the library like "_spi.write"

I don'n know C++ yet so have some books on the way as clearly  as soon as I try to touch anything written by anyone I will bump into C++

That's the FAT file system, which is a dependency of the SD File System, which does talk to hardware. Click on the dependencies tree up at the top and find one of the newer versions if you use that resource. It's all implemented in C++ of course. Virtual functions in particular will be new to you, as they don't exist in C. They can be sort of simulated with pointers in C, but it's a lot more work with many more opportunities for error.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #24 on: October 10, 2021, 03:22:23 pm »
well right there there is a problem, the dependencies are apparently a whole load of SD libraries by different people and apparently a USB host so that list is not worth much! it looks more like a list of related stuff.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #25 on: October 10, 2021, 07:35:48 pm »
OK, I got it, that is a list of the libraries that depend on this one, not really useful, I need to know what other libraries this one depends on. If i look at the api documentation page I get a list of files, do I need these? I mean it's not like someone is intentionally not very well documenting this stuff are they. It seems everywhere I go to involving programming assumes I know something but no one explains the stuff that apparently I should know already from some secret source!
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #26 on: October 10, 2021, 08:19:42 pm »
Quote
The specific chip is irrelevant to the discussion. We were talking about how to open the Arduino code in Microchip studio.
My experience (limited) with the Studio "Import Arduino Sketch" is that it works pretty well for Official AVR-based Arduino boards, but is pretty questionable on the SAMD boards (even the Arduino official SAMD boards.)  And it may be pretty hopeless on 3rd party boards/packages :-(

AFAIK, this feature was added to Studio back during the infancy of the current Board and Library management system, and has not been very actively maintained :-(


Quote
I don'n know C++ yet so have some books on the way
Unfortunately, most C++ books are likely to send you off in unproductive directions, if your goal is to understand Arduino/embedded C++.
(Not unlike C books, if you want to write embedded C.)

Quote
I believe one of the big potential pitfalls of the Arduino is that it tries to have a uniform usage on many different micro controllers.
Silly me.  I thought platform independence was a good thing, most of the time.

Quote
// Arduino.h should properly define PROGMEM, PGM_P, strcpy_P, pgm_read_byte, pgm_read_ptr
PROGMEM, strcpy_P, etc, are the special functions for AVR's Harvard architecture to access data in flash memory.  They're completely unnecessary on ARM CPUs, but it "would be nice" for them to be aliased for backward compatibility.  Many Arduino non-AVR platforms do that.

Quote
// if any this becomes unnecessary as platforms improve, please send a pull req.
"Pull Request" is a github thing.  This is approximately "if you fix this, let us know what you did."


Quote
there does not seem to be a well defined way to have a program in multiple files in the arduino "IDE".
There is, although I don't know whether the Microchip Studio continues to follow it.
Multiple .ino files are concatenated into a single file, which then goes through arduino "pre-processing" to generate prototypes and derive library paths.
Assembler, C and C++ (.S, .c, .cpp) files are compiled individually and "normally"; that means they need their own prototypes to allow forward references, plus "extern" declarations (even in the .ino files), and probably at least "#include <Arduino.h>" to pull in the Arduino definitions.
So you can split a .ino file into multiple .ino files relatively easily, but extracting some of the code into .cpp files will require more effort.

 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #27 on: October 10, 2021, 08:35:14 pm »

Quote
I believe one of the big potential pitfalls of the Arduino is that it tries to have a uniform usage on many different micro controllers.
Silly me.  I thought platform independence was a good thing, most of the time.


Yes providing it does not introduce bugs and make a mess of things. I have come across a a few funnies in the little amount I have used arduino and prefer to be truly platform independant not locked to some system. Right now I spend more time trying to work out what is what than just looking at programming the thing.

I tried making everything an ino file but it fell over. So is the ino file like a C file, so I create an accompanying header file for each for function prototypes? if so why all the bat shit crazy stuff on arduino forums about how to do it? that is why I do not like it, everyone is suddenly an expert and the ones that do most the talking are the ones doing it wrong!
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2416
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #28 on: October 10, 2021, 10:12:44 pm »
You might find this useful: https://arduino.github.io/arduino-cli/0.19/sketch-build-process/

From a user viewpoint, ino files are cpp files with the usual stuff like function prototypes added in preprocessing and arduino.h included at the top before it's handed to the usual compiler. Makes it very easy for newbies to get off the ground with no h file required.

The arduino-style setup() loop() structure is implemented by the default main() that looks very much like (it's in main.cpp in the core, if you want to find it):
Code: [Select]
int main(void){
  init(); // init hardware timers, etc
  setup(); // user setup function
  for(;;){
    loop(); // user run function
  }
  return 0;
}
If you provide your own main(), it'll override the default one and you can do what you want. Remember to still call init() or otherwise initialize stuff.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #29 on: October 11, 2021, 12:19:23 pm »
So I have created a new project in studio and added the files from SDfilesystem and FATfilesystem on the mbed website. The empty project compiles file using over 5kB of RAM so I assume that these files were compiled in and all is fine. Now I just need to work out what to do with them.....
 

Offline DrG

  • Super Contributor
  • ***
  • !
  • Posts: 1199
  • Country: us
Re: importing arduino "sketch" to Microchip Studio
« Reply #30 on: October 13, 2021, 12:34:22 pm »
So now the fun starts....locating every usage of the the Arduino SD lib in the original Arduino code and then writing functions that mimic those calls using "your" library. Actually, this may not be too much of a pita since the original is, hopefully just doing the usual; open/create file, write value, read values, close file; error reporting.

Wait until you get to the BLE part :)
- Invest in science - it pays big dividends. -
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: importing arduino "sketch" to Microchip Studio
« Reply #31 on: October 14, 2021, 07:26:48 pm »
Well I will reuse all that I can and just write the hardware stuff.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf