I am a Newbe on this Forum. In fact, I'm a Newbe on any forum really; I've rarely got into this sort of thing.
I notice that there are several things that “gets the goat” of people trying to help on this forum (not necessarily in this order):
Cross posting, lack of information, and lack of clarity of help requested.
Starting with the last:
How do I define an instrumentation problem (then design solution) using OOPs: I was a bit surprised to see C++, not C as the go to design methodology here.
My experience is in digital electronics, mostly for scientific instrumentation: involving instrument control, data acquisition, pre-processing and storage before transmission to central data services providing compression, transmission, etc. This means that my system design involved flow charts, FSM diagrams, data flow diagrams etc. the use of which was pretty obvious: system control, data rates and data processing all drop into neat functions with a “spin loop” manager sitting on the top. Typical procedural based design.
I have attempted to apply the same philosophies to a C++ design. Doesn’t really fit; I need help to take my old fashioned design style and make it fit C++.
So questions:
What design diagrams are used in OOPs instead of my old assembly and C design diagrams? Should I just continue with the “good old way” and forget OOPs libraries etc?
Second question:
I intend to use Modbus for a power control project, all Slaves (Servers) being Nanos.
I notice advice stating “do not use ArduinoModbus” for this family due to memory usage, but not a recommendation of what to use instead.
Which Modbus Library should I use for nano slaves (servers) and Mega2560 Master (client)?
There is no problem with going on in C.
But many libraries use C++.
Read about using classes at www.GeeksToGeeks or so.
It is not much different from structs in C.
Classes basically provide a namespace for your data and functions. And allow you to hide (and protect) data and functions. And keep together data and functions.
How to start: think what would be your objects (Serial communication, oxygen sensor, lcd display). Think what functions your objects should perform. Think what data are needed in each object (lcd needs to know pins that control the display, oxygen sensor needs to know pins connected to sensor).
If you have more than one sensor that sends a 4-20 mA signal, you might want a general object that can read and map that kind of signal.
In the end you should still have a loop() that rapidly runs through all tasks (read all sensors, send data, display data, etc.). Just like in your C main function.
You rattled off a bunch of stuff that stumps newbes here all the time. Noobs too, and beginners no matter if they call themselves that even if they are not.
All that is exactly applicable, and even if you never, woukd also be worth carrying into going full on C++.
FSM + IPO.
Add one or two tricks from "blink without delay" and you are on the way.
Diagrams! We do not use stinking diagrams! Well that would be the majority of novices we get on the forum that are here just to complete their homework.
But, old-salt programmers understand that a design diagram is just another tool to assist with creating a focus on a solution based on requirements expected from the system. Bravo for asking. You will find this PDF useful for concepts: Review of Java (umb.edu)
OOP is already 'built-in' to Arduino by default as the uC cores are C++ based. For example: Stream - Arduino Reference
So, you can write within the IDE in assembler, in C, or in C++; whatever is necessary/comfortable. Of course there are caveats.
Most coders will find that there projects will reduce to functions which are called sequentially from the loop(). But, one can implement callbacks and fancy stuff as necessary.
Hello again, thanks to all who have replied.
That's not quite what I expected: food for thought.
To be honest I expected "we haven't done it that way since the Ark's design".
I need to update my profile to explain where I came from, no point in putting that in a post.
So, the general opinion seems to be "stick with the design strategy that worked, tweak if needed".
Is the term "spin loop" still used? I don't recognise the IPO abbreviation, a google search comes up with a lot of options.
So, I will continue in C and try to bodge in other library stuff later.
I don't expect a reply to the question about Modbus libraries from this part of the Forum (my first balls up) should've been a separate post to a different topic. OOPs.
Ta,
Kerrin
ArduinoIDE messes with the normal C programming approach just a wee bit. Arduino as an IDE does preprocessing of source before the C/C++ preprocessor in an attempt to ease the requirements of function prototypes. Some other minor stuff, too.
The big abstraction is how spin loop is implemented. From the Arduino core we have something similar too:
void main() {
setup();
while (1) {
loop();
}
}
I think it is beneficial here to note that some core implementations, ex: ESP32 by Espressif, adds a bit more control to loop since the ESP32 is a dual-core chip and FreeRTOS is automatically included during the linking process. By default, core_0 is dedicated to Espressif RF and protocols, etc. core_1 is dedicated to Arduino code, by default. As such the loop() function includes a hidden yield() function to give FreeRTOS opportunity to timeslice with core_0.
Yes; but consider where you want to go in the microcontroller world. These chips are increasingly becoming more powerful and more complex moving closer to current SoC ( System on Chip) silicon. Therefore, the term microcontroller is becoming a bit difficult to define. Just check-out the specs on the RP2040 which is $4 USD: