C, C++ ... or less?

Hi, I apologize but english is not my natural language
I am a professional of C and C++ and I am going to help a friend to drive his model railroad with an Arduino. It's the first time I work with Arduino.
my basic questions are (and I need basic answers !) :
can we use C or C++ or only C
in C, can we use
structure, union I can not see those items in the reference guide
software interrupts

Bonjour, je suis un développeur C et C++ professionnel et je vais aider un ami à automatiser son réseau de chemin de fer miniature. Je me demande si le langage C utilisé par l'Arduino est 'complet'. Je n'ai pas trouvé, dans les références, la possibilité d'utiliser les STRUCTURE et la clause UNION. D'autre part peut-on utiliser les interruptions soft ?
Merci d'avance

Jean à Grenoble

The Arduino reference is a guide to the Arduino functions, not a complete guide to the C++ language that the Arduino is programmed in

Test it by yourself by writing a simple blinking sketch using the C++ instrctions needed for your project.

The Arduino '.ino' files (if there are more than one) are merged together into one '.cpp' file with #include <Arduino.h> at the top and function prototypes inserted just before the first function definition. That is then run through the C++ compiler for the selected board/processor.

The Arduino was designed for non-technical folks like artists. The automatic function prototype generation was to save the users from having to declare functions above where they are called. You can write any C++ code the compiler supports (most of C++11?).

arduino ide uses the gcc compiler

That answers everything the OP asked I think. What functions is the Arduino going to control on the model railway?

Of course, since there is no operating system and no standard display, keyboard, or file storage, there are missing functions related to hardware and the file system, etc.

I'm not sure about software interrupts but I assume you have to use assembly language.

As a "professional of C and C++" can you not SEE that the Arduino compiler is simply the ubiquitous gnu c/c++ compiler? You can use c or c++ as you desire.

waouh ! it's an very active forum !!
The problem I have is that I have no arduino board at home. I wanted to know a little more about it before visiting my friend next week. And reading the documentation raised some questions.
For its first arduino, my friend want to manage the sidings (tracks where trains are stocked 'in the backoffice'). He thouht that programming was easy and that difficulties were with the 'hardware'. In fact, it's the opposite.
Many thanks to all

I'm pretty sure the AVR has no software interrupt, but they can be simulated by setting a pin change interrupt on a spare pin, and then using a pin write to trigger an interrupt.

You can download the IDE and compile code though. You'll need an Arduino to test of course, but you can familiarize yourself with what you're going to need in your program.

Actually, if you already have C/C++ skills, he's probably right.

1 Like

It will be once you grasp the Arduino version of C++. It's mostly the same as what you are used to but simplified for the beginner. A lot of the housekeeping details are hidden from the user. Get an Arduino Uno learning kit and play with the sample sketches in the IDE. (Arduino code is called a sketch because, in my opinion, the developers don't want to hear purists complain that it is not a program).

By the time you have run three or four sample sketches, you will feel like you can write the code your friend wants.

Wouldn't that imply an OS?

No, plenty of microprocessors have SWI (or similar) instructions.
It might imply an OS precursor.

What is "manage" the sidings? Signalling? Controlling points? Look at NMRA LCC.

Anyway, be aware that a lot of work has already been done on using Arduino for model railroads. Some Arduino projects like DCC+ are linked to there.


Not at all. ALL Intel x86 processors have software interrupts, whether you run an OS or not has NOTHING to do with it. It is a hardware feature of the processor itself, an actual processor instruction, and always has been.

It all depends on what you are good at :slight_smile:

Let me introduce you to the fun-filled world of https://wokwi.com/ Now you can mess about without even needing an arduino

1 Like

On an AVR, there is little difference between a "software interrupt" and a "call" instruction, especially without an OS to make svcalls to,

Arduino uses avr-g++, so it supports C and C++, but due to the restrictive hardware environment (2k RAM), many of the C++ constructs you may be used to in a desktop environment are not present. No STL, no libc++, no exceptions, no cout/cin, and very limited dynamic memory allocation. (some of these can be added, sort-of.)

Arduino on ARM. ESP. and RiscV microcontrollers is less limited (there is usually STL), but still not what you'd be used to, due to low RAM.

Thanks to evryone who answered my question. I learnt a lot.
First, I didn't know that I can download the IDE without having a board. I'll try it as soon as possible. I'll also play with wokwi.com.
This first app will drive 4 points and 2 relays. Its main purpose is learning how it works. I'll look to the link about railroad mainly to see 'how far' can we go.
Now, there is a big difference between a subroutine call and a software interrupt : the adress of the routine to be called by the interrupt is stored in RAM (basically, the adress of the routine to call by interrup 80 is in the word 80 of the memory). It means that you can modify the routine to call without having to compile again the app; You can also 'insert' a routine if this routine stores the adress of the interrupt in a memory word, then stores its own adress in the interrupt word and call the previous routine instead of the 'return'. I hope you understand !
By the way, is there any french people among you ?
Best regards