What is the best language for programming microcontrollers?

In summary: However, it should be noted that C++ is not the only possible language for developing embedded software - any sufficiently powerful language can be used.In summary, C++ is a better language for developing embedded software due to its ability to facilitate team development, its support for OO design, and its ability to avoid bloat. However, C is a good option for beginners, and is easier to learn.
  • #1
KonaGorrila
12
0
I am wondering what programming language, whether it is C, C++, or other, would be best for programming micro controllers. What are the benefits of either one. I understand C is easier to learn but does that actually make it better? I need to use these micro controllers for sensor applications if this helps.
 
Technology news on Phys.org
  • #2
Depends on the toolset that is offered for the microcontroller. Most of the embedded systems I've worked on are written in a combination of C and assembly (mostly for stuff like interrupt handling. context switches by a kernel, ... ).
 
  • Like
Likes QuantumQuest, FactChecker, KonaGorrila and 1 other person
  • #3
I believe we are using microchip mplab, Thanks for your response!
 
  • #4
C++ is an object orientated language which greatly simplifies coding of large complex systems,
also it facilitates team development of software.
That is very unlikely to be the case for microcontroller software,
and it could even introduce unnecessary processing overheads and memory use.
Ideally microcontroller software could be most efficient if written in the native machine language of the processor.
However vanilla C is usually good enough with perhaps some critical routines written in assembly.
 
Last edited:
  • Like
Likes FactChecker
  • #5
rootone said:
C++ is an object orientated language which greatly simplifies coding of large complex systems,
also it facilitates team development of software.
That is very unlikely to be the case for microcontroller software,
and it could even introduce unnecessary processing overheads and memory use.
Ideally microcontroller software could be most efficient if written in the native machine language of the processor.
However vanilla C is usually good enough with perhaps some critical routines written in assembly.

This is wrong. C++ is a multiparadigm language and has been for a long time. Consider the STL. That is not an object-oriented design. Some or none of the traditional OOP techniques may be used freely together with procedural and generic programming. There is increasing support for a functional programming style. It does not force the shoehorning of a design into class hierarchies like certain other well-known languages, and that style was left behind by people keeping pace with the language in the 1990s.

The use of C++ in embedded systems is increasing. As other answers identified, this has everything to do with availability of tools.

Unnecessary processing overheads and memory use, including fragmentation, have nothing to do with the language and everything to do with the available compilers and design techniques used. One is not forced to use every feature of a language, instead a general purpose language allows a wide range of problems to solved by selecting subsets of features. For example, in hard realtime applications encountered in embedded systems, exceptions are often inappropriate. The obvious solution is simply not to use them.
 
  • #6
C is usually used for things like that because C++ compilers for embedded systems can be hit or miss, they will also rarely implement anything that they don't need, so you can probably expect std::string to work, but forget boost. C++ also tends to bloat software because it has to do little things like allocating vtables or doing memory alignment. I also prefer to manage my registers manually in some circumstance, so more often than not, you will still have to write some assembly.
 
  • Like
Likes QuantumQuest
  • #7
KonaGorrila said:
I am wondering what programming language, whether it is C, C++, or other, would be best for programming micro controllers. What are the benefits of either one. I understand C is easier to learn but does that actually make it better? I need to use these micro controllers for sensor applications if this helps.
If C++ is available, it would be the best choice. It is not necessary to use all of the C++ language features or libraries. Simply having the "this" pointer will make it hugely easier to break up large functions (>200 lines) into meaningful pieces. And, of course, you have generally better support for OO design, encapsulation, etc.
If your application is safety-related, there may be restrictions. For example, automotive applications are generally forbidden from calling a function through a variable - so v-tables (virtual functions) would not be allowed.

Since C is nearly a subset of C++, it follows that it is easier to learn C. But in the long run, it is easier to develop in C++. And with experience, it will be easier to test and maintain your object-oriented code.
 
  • Like
Likes KonaGorrila

1. What is the difference between high-level and low-level programming languages?

High-level programming languages, such as Python or Java, are easier for humans to understand and write, but they are also slower and require more resources to run. Low-level programming languages, like assembly or C, are more difficult for humans to read and write, but they are faster and use less resources.

2. What factors should be considered when choosing a programming language for microcontrollers?

When choosing a programming language for microcontrollers, it is important to consider factors such as the microcontroller's architecture, available resources, performance requirements, and compatibility with other systems or devices.

3. Is there a "best" language for programming microcontrollers?

There is no one "best" language for programming microcontrollers, as different languages have different strengths and weaknesses. It ultimately depends on the specific needs and requirements of the project.

4. Can any programming language be used for microcontroller programming?

While many programming languages can be used for microcontroller programming, certain languages may be better suited for specific tasks or microcontrollers. It is important to research and consider the capabilities and limitations of the language before choosing it for a project.

5. Are there any resources or tutorials available for learning a specific language for microcontroller programming?

Yes, there are many resources and tutorials available for learning specific languages for microcontroller programming. These resources can include online courses, books, forums, and hands-on projects. It is important to choose a resource that matches your learning style and goals.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
8
Views
865
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
2
Replies
54
Views
3K
  • Programming and Computer Science
2
Replies
58
Views
3K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
2
Replies
69
Views
4K
Back
Top