Every time I've messed with that in the past it broke my code, it either couldn't compile, couldn't upload, or couldn't run.The other thing you can do is turn off optimization (or change the level of optimization) and measure the effect.
The only exception to that would be code that needs to be particularly fast or lightweight. Then those things are part of the requirements. But most code doesn't need to worry about that since we have so much CPU and memory, even MCUs today.Yes.
Then you need a better compiler.Every time I've messed with that in the past it broke my code, it either couldn't compile, couldn't upload, or couldn't run.
I would encourage simple, good, legible code over strictly optimized for all software. This is not saying the compiler is magic and will convert poorly structured C code into good machine code.So when making a library, most would encourage simple, good, legible code over strictly optimized?
from the The Zen of PythonSimple is better than complex
Complex is better than complicated.
I'm using Arduino IDE and whatever compiler comes with it or when I download the board files from the manufacturer.Then you need a better compiler.
My advice: if you want optimized code then stop using Arduino.I'm using Arduino IDE and whatever compiler comes with it or when I download the board files from the manufacturer.
Maybe someday. But for now, it's really easy and simple and upon used to it. I kind of want to experiment with Micro Python or Circuit Python, but I have basically no experience with Python. I've been programming in C and Java off and on for 15 years so the syntax in Arduino IDE is familiar, and most of the code needs little to no rework to work between very different chips. I also don't like how in those two versions of Python it's really easy to accidentally delete your code. In Arduino saves are automatic. I'm running Linux, is there something that's considerably better than Arduino IDE for programming on RP2040, SAMD21, ESP8266/ESP32, AVR, and whatever other MCUs I might acquire that would likely be worth learning? Keep in mind that I'm strictly a hobbyist, not a professional when it comes to MCU stuff.My advice: if you want optimized code then stop using Arduino.
The Arduino IDE uses GCC, which is fine.My advice: if you want optimized code then stop using Arduino.
Oh, also, you can use VSCode with PlatformIO which is a much better environment than the Arduino IDE.My advice: if you want optimized code then stop using Arduino.
So as strictly a hobbyist, is it worth the time to learn other environments, like AVR's dedicated one, when I use a half dozen or so different brands of MCUs?For sure, Arduino has its benefits. It was intended for hobbyists who have little or no knowledge of how MCUs work. It is widely popular and supported, with lots of open source libraries written by third party individuals for a wide range of peripherals and applications. It is easy to get from A to B very rapidly.
Personally, when I deploy an MCU I like to have control and know what code is going into it. If I am going to use an Atmel AVR MCU, I am going use Atmel Studio or IAR Embedded Workbench.
You can just send millis() to the serial monitor at the beginning and end of your code (or after 100 cycles or what ever consistent thing you want. Then make your "efficiency change" and try again. Compare. - if you are optimizing on processing speed.Using what, millis()?
If learning other environments is part of your hobby, then, yes. Otherwise, no. After all, it is your hobby. You decide if you want it. I know PIC (c and asm) and Espressif's environment plus Arduino - plus many other languages not related to micros. In the end, they are all the same at some level and each has some special parts that can be helpful in certain situations.So as strictly a hobbyist, is it worth the time to learn other environments, like AVR's dedicated one, when I use a half dozen or so different brands of MCUs?
All of those tricks are things you do when you need heavy math on math light hardware. If you need math use something (hardware math processing on 16 or 32-bit controllers) that handles full IEEE floats faster that a 8-bit controller can bit-shift so you can write structured math code instead of 1990's style bit tricks. It's 2022 guys.Examples... Avoid floating point math and avoid division (which creates floats). Use bit-shifts if possible instead of divide or multiply by powers of 2, use byte and char variables instead of int for small values.
Well to each their own. I just tried it out, and I really don't like how it's set up. For a professional environment it might be a lot better than Arduino IDE, but I really like how minimalist Arduino IDE is in comparison. Creating a whole new project and having to select the board for the project feels like way too much for me, especially since I regularly put the same project on different boards and evolve the projects as I go. Being able to just change the board target in settings in Arduino IDE is preferable to me. But thank you for the suggestion, I'm glad I gave it a try.Oh, also, you can use VSCode with PlatformIO which is a much better environment than the Arduino IDE.
It is definitely more complex, but the VSCode editor is much better than the Arduino IDE. I still use the Arduino IDE though. Mostly because the learning curve for VSCode hasn't been worth it to me yet. But because I want to use Electron, and have some Javascript stuff I will be doing for the web, I want to learn it anyway. Then I will see if I prefer it to the Arduino IDE.Well to each their own. I just tried it out, and I really don't like how it's set up. For a professional environment it might be a lot better than Arduino IDE, but I really like how minimalist Arduino IDE is in comparison. Creating a whole new project and having to select the board for the project feels like way too much for me, especially since I regularly put the same project on different boards and evolve the projects as I go. Being able to just change the board target in settings in Arduino IDE is preferable to me. But thank you for the suggestion, I'm glad I gave it a try.
Yeah if I did lots of other programming types having a single IDE might well be worth the learning curve. But I do Arduino compatible MCUs exclusively. I bought one by accident (Particle Core, formerly Spark Core) that isn't Arduino compatible (it was only $2 or $3 thankfully) and I'm probably just never going to end up using it. I do like how all the libraries are added to a project though so it's completely self-contained in VS, that makes stuff much more portable. But again, that mainly only matters for distribution or other professional scenarios. I use one computer for everything, so I don't need that sort of portability.It is definitely more complex, but the VSCode editor is much better than the Arduino IDE. I still use the Arduino IDE though. Mostly because the learning curve for VSCode hasn't been worth it to me yet. But because I want to use Electron, and have some Javascript stuff I will be doing for the web, I want to learn it anyway. Then I will see if I prefer it to the Arduino IDE.
Oh, and the other reason I use Arduino IDE is for Teensy boards which are very well integrated in it and not so much elsewhere. In fact, I run Teensyduino which is a fork of the IDE that does Teensy and all the other boards;