using the arduino IDE without the arduino - Page 1
Forum section: electronics / general

author: Simon
author_rank: Unknown
timestamp: October 22, 2021, 12:03:16 pm
content: I have need to write a program that at the moment is not really going very well. For example there is an interrupt on a pin that is being pulsed at 10Hz but my readout says 1Hz, I can also see a delay in the screen updating sometimes yet there is nothing in my project to cause this delay.My problem is that i need something like the arduino libraries but without anything that runs in the background. Is there an established way to do this? I'd like to be able to access the hardware directly but don't want to fight the arduino system and break everything.Alternatively is there a way of putting all of the arduino libraries into a C++ project in microchip studio and using them there? I have some sort of plugin that does that but I don't want even that messing with my work.

author: PlainName
author_rank: Super Contributor
timestamp: October 22, 2021, 04:09:22 pm
content: QuoteThat would smell to me, and the first thing I'd do is look for alternative confirmation before trying to fix the wrong problem.QuoteSeems to me you're wanting your cake and eating it too. The only way to be sure is to do it yourself. Either use someone elses random code and accept everything it entails or have it do exactly what you want by writing it yourself. There is a mid-point where you could take some other code and either fix it up (but then you'd have to understand what it does, and knowing that you might as well write it properly) or use it as the basis for your own version (see previous comment). But doing that to what amounts to an OS is non-trivial unless your requirements are quite flexible, and yours don't seem to be.

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 12:32:52 am
content: the 1 in 10 interrupt seems to be a calculation error on my part but it is clear to me that there is a load of code in the background that on the one hand I don't want to upset if it is in use and on the other hand it is no use to me so might as well take it out. I can't possibly write everything I need from scratch and at some point need to trust someone. At least the arduino libraries seem to work and really they are not ardueino specific. Try looking at the LCD library, much of it's functionality comes from standard C++ libraries. It stupid things like whatever drives the millis() functionality that I don't want and want to write my own.

author: langwadt
author_rank: Super Contributor
timestamp: October 23, 2021, 01:07:37 am
content: Quote from: Simon on October 23, 2021, 12:32:52 amhttps://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/delay.c

author: westfw
author_rank: Super Contributor
timestamp: October 23, 2021, 02:40:14 am
content: QuoteWhat is it that you think Arduino "runs in the background"? About all it has is ISRs for a 1-millisecond clock tick and UART (if you use "Serial.")

author: Ian.M
author_rank: Super Contributor
timestamp: October 23, 2021, 06:14:26 am
content: ... and USB if you use one with a MCU that has native USB and let it initialize the USB interface.(i.e. Don't expect to be able to do hard realtime code on an Arduino Leonardo, and still be able to log data back to your PC over the (emulated) USB serial port.)If you follow:https://www.gammon.com.au/forum/?id=12625to use the Arduino IDE with a pure C/C++ program, (i.e. no setup()/loop() nonsense) the only resource it still squats on is the timer rollover interrupt used for millis()/micros() timekeeping. This can be disabled, but not removed.A few years back, I posted a 'Hello world' example in 'vanilla' C for ATmega328P based Arduinos that uses real C printf() over the UART, with no interrupts or other crap. (Its unbuffered and simply polls the UART peripheral, busy-waiting till its ready for the next character.) Reply #64.

author: semir-t
author_rank: Regular Contributor
timestamp: October 23, 2021, 06:49:35 am
content: Quote from: Simon on October 22, 2021, 12:03:16 pmSo what is the purpose then ? Arduino IDE is the editor with integrated libraries and compiler. If you use this libraries in the microchip studio, you only changed the IDE environment and you will again use same libraries which are cousin you the problem in the first place.For me, there are only two possible solutions:1. Look at the libraries source code and get familiar what they are doing in background. Then you will know what problem they can generate and possibly you can change them to fix this.2. Write your own stuff. You will know then exactly what part of the system you are using.

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 09:55:58 am
content: So the background to this is that I have a project done by a work experience student on Arduino. My boss was amazed at what he could do and came back from a school presentation ranting about the arduino. I explained that it's not all plain sailing as you rely on others code and don't have direct access to the hardware. He does trust my judgment but at the end of the day the monster is already born.In trying to use the students design and code I found that certain things that are really basic to the functionality won't work. I tried to rewrite the project for just this basic functionality as we need to do a demo for the customer that only needs this. I soon found that my project also would not work just like the students. The issue seems to be that you can't call millis() from too deep in function calls. There is a lot of other functionality we want that the student has already put in that I believe works like logging to the SD card, an RTC and a bluetooth module. None of this I can do in straight C++ which is what all libraries seem to be written in now as I do not know C++ (I have set out to learn it) and it would be silly to try and write all of my own libraries to do this.So I can use a bunch of libraries that seem to work together or start trying to piece random libraries together. I have already attempted to isolate the liquidcrystal library and use that in a C++ project in microchip studio but I am missing something that has something to do with the print library that i also copied over and others that depends on and so it goes on and on. So either I take all that stuff and use it as one working block if I can, or I tame the arduino to do what I want with access to the hardware registers. To do this I need to stop all the stuff in the background and know that there are no dependencies that i am about to break.As things stand I have been updating an LCD every 2s, now and then it does not update for longer than that. Something is going on in the background. Either because it disables my code and the 2s slot is missed or it's actually taking 2s to do whatever and a screen update gets missed now and then. I do not want unknowns like this. It reminds me of a personal project I tried to do for my last boss which was actually quite similar to this and it just failed to work as it was not very responsive again like something else was going on in the background.i would rather stick the Arduino libraries into microchip studio as I am not comfortable with the arduino compiling. I wrote some code that used an "else if", this failed to work and I had to make it an else, this in principle is not a good idea as just else means anything else rather than if that did not work try this and only this. I don't know yet if this is a C++ thing or an arduino thing.

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 10:06:00 am
content: Quote from: Ian.M on October 23, 2021, 06:14:26 amOh, so let me get this straight, this is one of the guys that is behind the arduino or is he just big on their forum telling us how to avoid problems it causes for itself? sweet. Wonder why this was not posted on the arduino forum or better main site, maybe he would get banned from his own forum like I was for a couple of weeks for politely pointing out that the lcd documentation was a bit thin on the ground and despite others agreeing and helping me and saying they would update the documentation.....

author: PlainName
author_rank: Super Contributor
timestamp: October 23, 2021, 10:52:04 am
content: QuoteSounds like a stack issue.But let's suppose it's not - it illustrates one of the issue of using (non-library) code from elsewhere in that some changes can't realistically be done because of the code architecture. Your student (as a for example) may have designed it in such a way that millis() can't be used beyond a shallow call depth, and if your mods require a deeper depth then you're stuck between a rock and hard place.QuoteParticularly when it comes to this stuff. Perhaps the SD card has a blocking delay loop, so if you're updating the LCD and do an SD card access you get a flicker (or worse) and things temporarily halt. The fix may be to remove that blocking delay, but doing so may need the SD card stuff redesigning to not need that delay. You can easily end up with a bodge on a kludge held together with hope and disappear down a rabbit hole.So, maybe the student had A Plan and decent design, and all you need to do is get into the same mindset so you can go with the flow rather than be trying to divert the Amazon. Or he just hacked likely looking stuff he copied off the web and it's actually a pile of poo, in which case you're just digging in deeper if you continue with it.Any chance you could ask the student to fix it up?Edit: or ask him to walk you through his design.

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 11:37:46 am
content: The student will be in next week to work with me on productionizing it. This why i am trying to explore all options now so that we have a plan. No he does not have a highly sophisticated plan, he has used the arduino like most that first start programming and thought he had most things working with a list of things that I need no sort out or that he could help sort out later.To stop the millis function from working all you have to do is put it in an if block, that is all. I prefer not to use millis() and instead run my code when I want it to run rather than keep checking the current time.

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 11:51:10 am
content: basically Ian's post above explains the possible sort of issueshttps://www.eevblog.com/forum/embedded-computing/using-the-arduino-ide-without-the-arduino/msg3765269/#msg3765269there is a solution but no reason why. I guess if our code will be interpreted straight C/C++ without any other interference it can be a solution. but it would be nice to use an IDE that has it all like the ability to explore and open the included files.

author: DrG
author_rank: Super Contributor
timestamp: October 23, 2021, 04:03:04 pm
content: Quote from: Simon on October 23, 2021, 11:37:46 amYou may want to look at some alternative code for millis()https://github.com/zkemble/millis/blob/master/arduino/millis/millis.cppI have been following these threads (concerning the project) and note that you are not too happy about the tasker. You may want my head to be rolling as well, but I am trying to understand and see exactly what problems you are encountering....it ain't easy.What do you think about "productionizing" student products now?

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 04:17:40 pm
content: The company does a project with the school where they are given a real problem to solve. They do their best under the guidance of a teacher the aim being they get a real world problem not a manufactured one. It's not expected that what they produced will be the production solution. They understand that it will need refinement and if I said it had to be done from scratch so be it.I can't here and now replicate the arduino capabilities but clearly to go with stock arduino is asking for trouble as at the moment it's falling all over itself. So I am trying to find a workable middle ground where we make best use of the features identified but do not tie ourselves to something that can change at random.This is why I rather like the idea of pulling all of the arduino stuff into a microchip studio project. That will be a load of stuff that will be frozen and selectively updated with what we need rather than oh another version is auto updating itself - whoops we have just lost a load of functionality that worked.

author: DrG
author_rank: Super Contributor
timestamp: October 23, 2021, 05:22:10 pm
content: Quote from: Simon on October 23, 2021, 04:17:40 pmI can't say that your approach is wrong because, for one thing, you know much more about the project than I do [I still do not know which Arduino board is actually being used). Still, I think that you are asking for (or had someone ask for you, e.g., 'da company') and receiving a great deal of head-banging.FWIW, I STILL say, get the thing to work on the Arduino IDE first....the thing is, it seems more and more that there were serious problems with it and it never really did work. If that is so, it could be a huge problem in that "you can't get there, from here'. The sooner you find out how far it is from working on the IDE (and why), the better. It may be a complete rewrite. The sooner you make that decision the sooner you abandon this half and half approach...that my two cents anyways

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 09:55:54 pm
content: No actually as far as I am aware the whole thing works, it is based on the MKR Zero with a SAMD21 what was actually failing was the bit that relied on millis() that was just one level too deep for the arduino to handle so a speed calculation based on time elapsed and tacho pulses was just putting out nothing or gibberish. This is the simplest bit of the product but a main feature. This is what I hate, some really complex stuff works fine but the really simple one just breaks and as far as straight C and probably C++ there is nothing wrong with it. That is not a way to work but I don't want to spend time rewriting 90% of the project that works. Sure it all needs tidying up, it's a bit of a mess - simply because it was written in Arduino by someone that does not have much experience in programming large projects whilst having to try pop luck at getting the arduino to work because that is what it is down to.

author: Simon
author_rank: Unknown
timestamp: October 23, 2021, 10:00:07 pm
content: My personal dilema is that to achieve any of this without the Arduino I need to know C++ well enough to read and understand others code and that means very well, I can write my own simple stuff long before I can read others code that will of course flex every C++ muscle and be as clever as possible. I have been bought books I asked for, the one I need to start with is 1250 pages. So it's some months down the line before I will have anything like any idea of C++, meanwhile this little project needs to get moving once this current lashup have been shown to the customer.Meanwhile I am shown a link to the personal forum of someone linked to the arduino project telling us how to get around undisclosed bugs in the araduino.

author: langwadt
author_rank: Super Contributor
timestamp: October 23, 2021, 10:30:53 pm
content: Quote from: Simon on October 23, 2021, 09:55:54 pmthat makes absolutely no sense, look at the code for millis() it just returns a tick counthttps://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/delay.c

author: westfw
author_rank: Super Contributor
timestamp: October 24, 2021, 12:11:55 am
content: I think you should just start reading the Arduino code, looking up the C++ stuff that it uses as you run into it.You keep acting like you're sure that the Arduino code is doing deeply mysterious stuff that is inexplicably interfering with basic functionality, but I'm pretty sure you're wrong, and ... there just isn't that much TO the Arduino core. Stop thinking "it's Arduino, and that's C++, and I don't know C++. and a C++ manual is 1000+ pages, so I'm doomed", and just leap in and figure out the code that is actually there.QuoteIt shouldn't be months, because the Arduino code is not "as clever as possible with C++ muscle." Most of it looks a lot like C.

author: Simon
author_rank: Unknown
timestamp: October 24, 2021, 09:45:34 am
content: The arduino uses a lot of standard libraries like print, string. that is why there is not much to the arduino itself. Being able to use the arduino libraries as is would be very helpful, that is it's power, you want to do something - there is a library for that. I can't just look at some C++ and start figuring it out. If you want I can switch to writing this all in Italian that I am fluent in and you may not be and you can just figure it out.....I aim to learn C++ as clearly any library I pick up is more likely to be written in C++ than C and so I will also have to write in C++. Until I am fluent I cannot read other people's code and know what it does. even with C I find it easier to write my own than understand someone else's.If i can write in C and then C++ whilst using the arduino library system that is mostly well documented that would be a nice way of getting into more complex stuff. There is no point in trying to write my own libraries to work with files on an SD card when these exist anyway. If I just download some I have to figure out how to use them and what they depend on. The arduino goes one better in having them in place and already working with their dependencies sorted out. But I would rather jump over the hardware stuff and go direct. Ass soon as i try to use arduino stuff on a SAMD I get requests for AVR headers when i work in microchip studio.The new arduino IDE looks a lot easier to work with than the current one and I could live with that more easily for more hardcore stuff. I have now one project to get sorted out, it will be used well into the future so I don't want to leave myself open to issues if I am asked to make a mod in 5 years. For future projects I will hopefully have more time and when I come to do them will be more knowledgeable and find it easier as I would have this first one under my belt anyway.

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 24, 2021, 03:26:32 pm
content: Quote from: Simon on October 24, 2021, 09:45:34 amNo, it doesn't. Arduino uses a freestanding C + C++ environment, and implements some of those familiar functions itself.However, they are different.Any resemblance to the standard functions is intentional, but only that: resemblance, not equivalence or sameness.Arduino does also have a limited implementation of the standard C libraries, provided by avr-libc, newlibc, or picolibc. Anything related to processes or signals will be missing, for example. Floating-point support may be limited.If you switch from Arduino to e.g. PlatformIO, you still have the same library limitations. Microcontrollers just don't have the resources to implement a standard C++ library: even core features, like exceptions, tend to be unavailable!

author: Simon
author_rank: Unknown
timestamp: October 24, 2021, 03:45:26 pm
content: OK, which is why I am trying to take all of the Arduino library code and use it as a package but whilst still being able to talk to the hardware myself without the fear that I am interfering with something in the Arduino.

author: DrG
author_rank: Super Contributor
timestamp: October 24, 2021, 04:12:21 pm
content: Quote from: Simon on October 24, 2021, 09:45:34 amI wrote a lengthy response to this earlier and deleted it all because it was preachy and not terribly helpful. There are four points that I want to make in response.1. I hope you have abandoned moving to Microchip Studio. I never saw a legitimate reason to do this and said as much.2. Thanks for informing me about the 2.0 IDE, which is beta (and WIN10+, the Windows version I mean)). I am only going to watch this for a while and it is likely, at some point, will try it out - but not while in beta.3. Please remember that Arduino libraries (external downloaded ones specifically) change and they change all the time, e.g.,https://github.com/arduino-libraries/ArduinoBLE. If you think that you can lock a version of this project and come back to it in 5 years to do something, you will want to have copies of all the libraries that you used and even the version of the IDE.4. Do not discount how much of a library you can understanding knowing C and not C++. Depending on the library, I have been able to completely understand what is going on and I know only the bare essentials of C++. So, for example, an LCD library that uses a character function only, or a chip-bound RTC, is no big deal.Figuring out a BLE library is another matter. Using devices with AT command firmware (e.g., HM-10 and some PICs) is one thing, but devices like the ESP32 or the Linkit 7697 or the MKR 1010 are quite another, and I found that, for me, it was absolutely necessary to go through the header and .cpp files so that I could figure out how to use the commands - the examples just go so far.Good luck with the tasker and you will probably get it figured out

author: Simon
author_rank: Unknown
timestamp: October 24, 2021, 04:19:41 pm
content: Quote from: DrG on October 24, 2021, 04:12:21 pmWhich is precisely why I want to be able to take the libraries and keep-em using them as local includes on a microchip studio project. If I use the arduino IDE they will change all the time and I don't know how much separation there is between IDE and libraries. I need to bring libraries in one at a time and localize them where needed.

author: xrunner
author_rank: Super Contributor
timestamp: October 24, 2021, 04:27:56 pm
content: Quote from: DrG on October 24, 2021, 04:12:21 pmI've been reading all of this for some time and didn't feel like I had anything much to add that wasn't covered. But I will say that the libraries have updates all the time, and it isn't entirely obvious to the user just looking at the main window.For example, I just opened the IDE v 1.8.13 (I have been using the new Beta for a recent project and didn't have any problems but ...). There is no real indication of anything that needs updating on the main window at the moment.However, if you go to Tool - Manage Libraries - Type: updatable you will see the list of libraries that have updates. And even the "Update" button does not show unless you hover over the library "sub-window". I find eight libraries that have updates at this time.Maybe that's obvious to Simon I don't know, but if he knows this I apologize ...

author: Nominal Animal
author_rank: Super Contributor
timestamp: October 24, 2021, 04:46:09 pm
content: Quote from: Simon on October 24, 2021, 03:45:26 pmIt might be easier to start withPlatformIO framework support for Arduinofor that.Maybe look at howcommon exampleslook like there?(The platform-atmelsam does support MKR Zero;hereis its mkrzero.json board support file, andherethe SVD XML file for ATSAMD21G18A.)For example, the Arduino Blink exampleported to PlatformIO, targeted for Atmel SAM, hasthisplatformio.ini configuration file, andthisBlink.cpp file.Basically, you work with the C++ sources, without the source-code mangling that the Arduino IDE does.That means tracking dependencies and modifying the Arduino core files and libraries is easier (because it's then all just C++ code you can see without magickal mangling), and you can remove all the stuff you don't want.The downside is that tracking Arduino cores and libraries becomes harder, as any customization you do needs to be ported to each new version.

author: DrG
author_rank: Super Contributor
timestamp: October 24, 2021, 04:53:03 pm
content: Quote from: xrunner on October 24, 2021, 04:27:56 pmI am using 1.8.13 and it does the usual notification about libraries that need updating (although you don't have to update them). I don't know about IDE 2.0, that is the one I meant as in beta.Regardless, you don't have to use libraries from the Arduino library directory (where they get updated through the manager) you can put the files in their own directory where they stay quite nicely and do not update unless you do the update manually. There is plenty online about local use of libraries and you don't need to use microchip studio to do this. I think this feature was added back in 2017 (https://github.com/arduino/Arduino/issues/4936). This is how I lock a library version, when I feel like I am done with the project and don't want to return to it with a new version of a library.But I could be confused - that does happen