New to Arduino - some observations

So I'm a long time maker/hobbyist using the zbasic platform but came to Arduino as I needed more speed for a particular project. I was a paid developer 30+ years ago when the world was simpler, and now just dabble as a hobby.

Some observations on Arduino and it's environment which may or may not ring true with others, or people could offer some guidance on.

  1. tab stops in the ide. I'm used to tab stops behaving properly. The default ide behaviour is to expand tab stops to spaces, which works but misses the point. I have tried turning expand tabs off and tab size to 8 characters (the correct value) but the formatting is all over the place. Each time I open my project it looks different. Lines of code have randomly moved left or right when they used to line up. Once you've used an editor that implements tab stops properly there is no going back - unless you have to :frowning:

  2. i want to write reusable functions, and libraries are probably the answer here, but it's not as convenient as using tabs in the IDE as you can't see the library code so readily and you can't easily amend it. But if you use code tabs, the code has to reside in the project folder. If there was an option to specify a location, one could create a folder of reusable code and include it as wanted.

  3. when you build a project, the compiler tries to compile everything in the project folder regardless of whether it is used or included in the project. I believe it does this as there is no mechanism/file to tell the project which modules to use (i can't find a project file specifying which modules are used etc). It doesn't seem sensible.

  4. Function prototypes - the ide has a go at inserting these but is tripped up pretty easily. seems to be a long standing issue. Is there an option to turn off prototyping so I know I have to do it all myself ?

  5. I have compiler warnings telling me a variable is unused, but if i comment out the declare, i get an error saying the variable is not declared - is this usual and do people just put up with it ?

Don't misunderstand, i'm really enjoying the move to Arduino but I'm surprised that an environment that has been around so long, and is so popular has so many issues. I've only been working on Arduino for a few weeks and I've spent a good percentage of that time chasing my tail. As time goes on and I understand how to work with or around the issue things will get easier but I'd thought I'd document some new comers trials

FFMan:

  1. tab stops in the ide. I'm used to tab stops behaving properly. The default ide behaviour is to expand tab stops to spaces, which works but misses the point. I have tried turning expand tabs off and tab size to 8 characters (the correct value) but the formatting is all over the place. Each time I open my project it looks different. Lines of code have randomly moved left or right when they used to line up. Once you've used an editor that implements tab stops properly there is no going back - unless you have to :frowning:

I can't reproduce this. Please provide a detailed set of instructions I can easily follow to see the problem, including which version of the Arduino IDE you're using.

It is definitely true that the Arduino IDE's editor is very limited. Advanced users will often use the editor they prefer instead. If you select File > Preferences > Use External Editor in the Arduino IDE then the IDE's editor will be disabled and any changes you make to the sketch via your external editor will be reflected in the Arduino IDE. This way, you can just use the other useful functions of the Arduino IDE like compiling and uploading. If you don't even want anything to do with the Arduino IDE's GUI, the Arduino IDE has a CLI or you can use arduino-cli.

FFMan:
2) i want to write reusable functions, and libraries are probably the answer here, but it's not as convenient as using tabs in the IDE as you can't see the library code so readily and you can't easily amend it. But if you use code tabs, the code has to reside in the project folder. If there was an option to specify a location, one could create a folder of reusable code and include it as wanted.

The usual approach is to use your preference of text editors to write library code. However, I do prefer to use the same interface for writing all my Arduino code so I do use the Arduino IDE to write my libraries. Here's how to do it:
It is possible to use the Arduino IDE to edit libraries:

  • Add a dummy .ino file to the folder containing the library files you want to edit with the Arduino IDE. The .ino filename must match the folder name. This allows the Arduino IDE to open the library source files as if they were a sketch. This file will not actually be compiled as part of the library. I use it as a place to store my "to do" list. You could also use it for a test sketch for the library, in this way you can actually compile the library right from the same IDE window where you are editing it instead of having a sketch open in a separate IDE window.
  • Add a file named .development to the root of the library folder. This is necessary because otherwise the Arduino IDE treats the contents of the library as read-only (to prevent people from accidentally modifying example sketches).
  • If it doesn't have one already, add a file named library.properties in the root of the library folder. You can find the specification of the format here: Arduino IDE 1.5: Library specification · arduino/Arduino Wiki · GitHub. This is required for the .development feature to work.

FFMan:
3) when you build a project, the compiler tries to compile everything in the project folder regardless of whether it is used or included in the project. I believe it does this as there is no mechanism/file to tell the project which modules to use (i can't find a project file specifying which modules are used etc). It doesn't seem sensible.

It seems perfectly sensible to me. If you're not using something, then why is it in your sketch folder? Remember, the primary focus of the Arduino IDE is to be easy for beginners.

FFMan:
4) Function prototypes - the ide has a go at inserting these but is tripped up pretty easily. seems to be a long standing issue. Is there an option to turn off prototyping so I know I have to do it all myself ?

There certainly have been a lot of problems with function prototype generation over the years but I think it's really quite reliable in Arduino IDE 1.8.9. There are some rare cases where function prototype generation still fails, but they are not often encountered.

There is no way to turn off prototype generation. However, if you prefer to do it yourself, well go right ahead. The Arduino IDE only generates prototypes for functions that don't already have a prototype. Also, prototype generation is only done on .ino files. No prototype generation is done for any .cpp, .c, .h files in your sketch. So you can simply put all your code in those files if you don't want the Arduino IDE messing with it.

FFMan:
5) I have compiler warnings telling me a variable is unused, but if i comment out the declare, i get an error saying the variable is not declared - is this usual and do people just put up with it ?

If you will post a minimal sketch that demonstrates the issue we'll take a look at it.

Don’t use the Arduino IDE then. if you want a more professional tool then use one. The Arduino IDE is a kids toy. You don’t need it to use Arduino. Just use the core libraries with whatever IDE you like. I use Eclipse.

thanks for the reply - responses to each by number below:-

  1. regards tab stops in the IDE - i do keep my code in dropbox and pick the code up on one of two machines. however i've altered the tab preferences on both machines but still get line-up issues as i described.

  2. thanks for the description - it all sounds quite clunky when all that is really required is the ability to locate shared code into a specified directory and include them in a sketch as desired. for instance zbasic has a simple 'add files to project' and allowed these to be from anywhere. that is a simple easy to understand alternative to libraries and allows you to debug library code in one project.

  3. it would seem sensible if the included file appeared in a tab. the behaviour is sort of worst of both worlds. you can't see the file in the ide, but you get compiler errors. Either would be ok, do not compile files not open in the ide, or do compile them but display them in a tab so its obvious what the issue is

  4. it seems to be a long standing issue, maybe technically it's not possible to fix but it should then be documented and throw a sensible error. it took me several hours to get to the bottom of, and without understanding why some prototypes work and some don't it's a try and see approach which isn't beginner friendly

  5. i'll see if i can create a small sample

on a plus note, i see the teensy 4.0 has a turn of speed :slight_smile:

There are Arduino add ins for visual studio which Might be better for you.

hammy:
There are Arduino add ins for visual studio which Might be better for you.

…and Eclipse, as already mentioned. Perhaps it’s just more fun to whine about the known limitations of the standard tool that’s acknowledged to be geared towards beginners.

I have never used the Arduino IDE. For years, I used VisualStudio, with the VisualMicro plug-in, which works great. More recently, I'm using VisualStudio Code, which is much "lighter weight" than full VisualStudio, and has built in support for Arduino. Both VisualStudio and VisualStudio Code are free.

Regards,
Ray L.

I share your sense of frustration with some features of the Arduino IDE - particularly with the inability to use code from another location.

I use the Geany editor for all my programming - Arduino, Python, HTML etc

I have written a simple Python program to compile and upload Arduino code using the command-line IDE. It allows code to be included from other locations because the Python program converts relative references to absolute references. It can be used without Geany.

I tried Eclipse many years ago but I much prefer the simplicity of a text editor.

...R

FFMan:

  1. tab stops in the ide. I'm used to tab stops behaving properly. The default ide behaviour is to expand tab stops to spaces,

That's how everyone is doing it these days. In olden times, tab stops were 8 characters. Which is just way too much - these days people are indenting by 2. So either you make tabs 2 spaces wide, which means that your nicely formatted code will go banannas every time you export it into anything else that doesn't know this, or your indents become a mix of tabs and spaces - yuck!

FFMan:
2) i want to write reusable functions, and libraries are probably the answer here, but it's not as convenient as using tabs in the IDE as you can't see the library code so readily and you can't easily amend it. But if you use code tabs, the code has to reside in the project folder. If there was an option to specify a location, one could create a folder of reusable code and include it as wanted.

Yeah, the IDE isn't full-featured - source paths, things like that. Perhaps there's an arduino version of Eclipse that will do what you want? Mind you - the solution to "I can't see the source" is better documentation. If you need to see the source, then the library isn't really re-usable.

FFMan:
3) when you build a project, the compiler tries to compile everything in the project folder regardless of whether it is used or included in the project. I believe it does this as there is no mechanism/file to tell the project which modules to use (i can't find a project file specifying which modules are used etc). It doesn't seem sensible.

Welcome to the wonderful world of C++, where compiling is a completely different step - and done by a completely separate executable - to linking.
If your code environment is that complex, then maybe you'd be better off biting the bullet and using a makefile and calling avrdude directly.

FFMan:
4) Function prototypes - the ide has a go at inserting these but is tripped up pretty easily. seems to be a long standing issue. Is there an option to turn off prototyping so I know I have to do it all myself ?

Use a .cpp extension rather than .ino . Your .ino can be blank, if you want. In fact, the compiler will only do the function prototype generation for the first .in file it finds, so having more than one is a bad idea.

FFMan:
5) I have compiler warnings telling me a variable is unused, but if i comment out the declare, i get an error saying the variable is not declared - is this usual and do people just put up with it ?

Weird.

Yes, the Arduino IDE is a bit minimal. It's a beginner's tool. The emphasis seems to be on the "supporting a whole bunch of different microcontrollers" side. If you have complex stuff going on, then maybe as I said you need to look at eclipse and at authoring proper makefiles to do the build.

---- EDT ----

If you don't even want anything to do with the Arduino IDE's GUI, the Arduino IDE has a CLI or you can use arduino-cli.

A great idea. Let the CLI take care of working out what libraries you need to link for the boards you are using, use another tool to write your code.

  1. I have compiler warnings telling me a variable is unused, but if i comment out the declare, i get an error saying the variable is not declared - is this usual and do people just put up with it ?

Weird.

You do not need to declare your variables and functions in the IDE. In fact, declaring them can hide other problems further down. (Post your and we can try to find the error).

Re-tabs and re-useable code.

I just maintain all my common files in a folder on my thumb drive called 'common'

Each new project I create I just copy those common files I need to the new project folder.

If I make any changes to the common file then I make sure I copy them back to my 'common' folder.

Good enough until such time that Arduino IDE allows you to add tabs for files in locations other than your sketch folder.

FFMan:
4) it seems to be a long standing issue, maybe technically it's not possible to fix but it should then be documented and throw a sensible error. it took me several hours to get to the bottom of, and without understanding why some prototypes work and some don't it's a try and see approach which isn't beginner friendly

You might give the beta build of the Arduino IDE a try. It uses a new prototype generation system so you might discover that your bug has already been fixed:

If not, then you should consider that if nobody bothers to report a rare bug then it's unlikely to get fixed unless one of the Arduino developers just happens to stumble across it in their own testing. You can be part of the process of making the Arduino IDE better, or you can just complain about its deficiencies on the forum. The choice is yours.

FFMan:
on a plus note, i see the teensy 4.0 has a turn of speed :slight_smile:

Yeah! Teensy is great.

  1. Function prototypes - the ide has a go at inserting these but is tripped up pretty easily. seems to be a long standing issue. Is there an option to turn off prototyping so I know I have to do it all myself ?

If you want to create your own prototypes then feel free to go ahead and do it, no need for an option

SteveMann:
You do not need to declare your variables and functions in the IDE. In fact, declaring them can hide other problems further down. (Post your and we can try to find the error).

You don't have to do forward declarations on functions true, but it doesn't hurt anything and can often save you from the IDE making mistakes.

You most definitely do have to declare your variables before you use them. That first part of your statement is nonsense.

Delta_G:
You don't have to do forward declarations on functions true, but it doesn't hurt anything and can often save you from the IDE making mistakes.

Depends on the version of the IDE.
It can help on some versions and hurt on others, particularly on the older versions of the IDE where depending on how you do the declarations it can cause the IDE to misinsert function prototypes, create malformed prototypes that won't compile, or not create any prototypes for the ones you don't declare.

On the positive side, the most recent versions of the IDEs don't suffer from the issues I used to see quite often in the past.

--- bill