logo elektroda
logo elektroda
X
logo elektroda

Arduino Programming: C or C++? Discover Language Essentials for Arduino Projects

reiko 9219 16
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16537675
    reiko
    Level 10  
    Hello,

    the question is addressed to older people, but every opinion will be taken into account - what exactly is programming in Arduino? I am specifically interested in Arduino, not Atmel processors in general. I ask because I see C elements (Serial.print ()) while in C ++ I always used cout; I also see C ++ elements (in some libraries). I am asking because I would not want to waste hours learning the wrong language. I know that I have to train myself in this because in the example codes I saw previously unknown phrases like PROGMEM etc.

    Before anyone can give me advice, please note that I'm only interested in programming in Arduino. It's like building a house - when building a house, I don't need to know what and how a block, oven or car is built of.

    Best regards!
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 16537741
    grko
    Level 33  
    If you are only interested in arduino then you should invest time in C ++ because it is the default language in this IDE. Remember that knowing the language syntax alone does not make you a programmer yet. Algorithms and data structures are the basis.
  • ADVERTISEMENT
  • #3 16537775
    Anonymous
    Level 1  
  • #4 16537825
    grko
    Level 33  
    @emarcus Following this line of reasoning, when building a house, you must produce the blocks, roof tile, roof truss and all other materials needed to build the house. However, you should use common sense and appreciate the arduino in certain circumstances. For many, it is the only platform on which they can implement something. After all, not everyone wants to be a professional embedded programmer.
  • #5 16537841
    Jawi_P
    Level 36  
    Arduino is neither pure C nor C ++.
    I think it comes from Wiring very similar to C / C ++.
    Generally, in Arduino you don't have to write in accordance with their overlay and I recommend it. If someone works on AVR development boards and the like, they can write in C itself. The code comes out much smaller and "normal". If you ever want to change, you'll do it without a problem.
  • #6 16537902
    reiko
    Level 10  
    @Jawi_P and what about writing libraries? Can they also be written in C? I have little experience in Arduino but I have seen several libraries with * .cpp files
  • #7 16537944
    Anonymous
    Anonymous  
  • ADVERTISEMENT
  • #8 16537982
    tmf
    VIP Meritorious for electroda.pl
    Jawi_P wrote:
    Arduino is neither pure C nor C ++.
    I think it comes from Wiring very similar to C / C ++.
    Generally, in Arduino you don't have to write in accordance with their overlay and I recommend it. If someone works on AVR development boards and the like, they can write in C itself. The code comes out much smaller and "normal". If you ever want to change, you'll do it without a problem.


    To compile the program, Arduino uses g ++, so the C ++ compiler. Even if you don't use all the benefits of C ++ and write in the style of C, it's still C ++.
  • #9 16537984
    dasej
    Level 32  
    Hello.

    @reiko

    Interesting, you're not going to find out what a block is made of and you want to write libraries.
    Of course you can easily write libraries under Ardiuno, but only when you understand
    the commands you need to give to the chip to do what we want.

    And this is no longer building a house, just designing it.

    Good luck.
  • #10 16538067
    reiko
    Level 10  
    Gentlemen @dasej and @emarcus are probably right. I wanted to take shortcuts but it's probably not worth it. I'll start from scratch. Ultimately, nothing prevents you from learning C and C ++. I see that @tmf recommends the book "C language for AVR microcontrollers. From the basics to advanced applications" - I will use it, especially since Arduino has an AVR processor.

    Best regards!
  • #11 16538110
    rb401
    Level 39  
    Jawi_P wrote:
    Arduino is neither pure C nor C ++.
    Probably derived from Wiring very similar to C / C ++.


    For the record, there is no Arduino language, dialect, wiring etc.

    Technically speaking, the arduin sketch (.ino) is implicitly converted into a .cpp file for the user (added includes of the Arduino basic library, declarations of functions defined by the user in the sketch, etc., added at the beginning of the file). NB. this file can be found on your computer in a temporary folder where Arduino compiles the project.

    And this implicitly created C ++ file, complete with libraries (with some modules written in pure C), both standard for Arduino and added in the sketch, is completely standard compiled by the quite normal GCC compiler as a normal mixed C / C ++ project.

    And the fact that the user in his file (sketch) e.g. does not see the main () function (which of course exists in the project) and does not need to include the Arduino basic library, but only uses functions seemingly built into the language, it's basically just a trick, because it what the user writes in the sketch is part of a normal C ++ program (although there are already some conditions imposed that the user cannot see or influence).



    reiko wrote:
    I know that I have to train myself in this because in the example codes I saw previously unknown phrases like PROGMEM etc.


    The PROGMEM and F macros are not related to the language used or Arduino in any way. These are specific things necessary due to some design limitations of AVR processors.
    So don't be scared of them. You will switch to better processors, e.g. ARM, you will forget that something like this is needed.
  • #12 16538157
    Anonymous
    Anonymous  
  • #13 16538186
    michalko12
    MCUs specialist
    The world doesn't end with arduino. Learn what is needed at the moment.
  • ADVERTISEMENT
  • #14 16538216
    Jawi_P
    Level 36  
    tmf wrote:
    To compile the program, Arduino uses g ++, so the C ++ compiler. Even if you don't use all the benefits of C ++ and write in the style of C, it's still C ++.

    As someone once said "The most beautiful thing about C ++ objectivity is that you don't have to use it at all".

    Added after 7 [minutes]:

    Piotrus_999 wrote:
    How to learn is C ++. Object-oriented languages are the present and the future.

    Future? Yes, but on 32-bit uC. But probably this is not the most optimal language for Arduino?
    As for the present, then for 8-bit players, C rules. A whole bunch of books, examples etc. It's easier to learn C.

    Added after 3 [minutes]:

    michalko12 wrote:
    The world doesn't end with arduino. Learn what is needed at the moment.

    It's true, even now it pays to buy Arduino on average, especially the original one.
    For the same price you already have a similar set with some Cortex.
    But lots of examples, of ready-made ones, do their job.
    But the question was about Arduino.
  • #15 16547514
    pimpuk
    Level 23  
    Optimal language for Arduino?
    What are you writing about?
    When I was learning to program, I thought C was the basis.
    You know, Vintage, cradle. Everything can be done on structures, and object-orientation is such freemasons, useless bullshit that destroys this crystal transparency of the code. Better is the enemy of the good.
    Did you know that when I met C ++, I genuinely recognized learning time C as lost time? Unbelievable, is not it?
    C ++ is the foundation, this language rules.
    And when it comes to Arduino, the vast majority of libraries are written in C ++ and you won't get far without knowing this language.
    Best regards.
  • #16 16553084
    japycz321
    Level 26  
    Jawi_P wrote:
    For the same price you already have a similar set with some Cortex.

    Arduino nano with ch341 and atmega 328 at our friends from the east costs 7-8 PLN. It's hard to find a better alternative: -)
  • #17 16553167
    Anonymous
    Anonymous  

Topic summary

The discussion centers around the programming languages used for Arduino projects, specifically the relevance of C and C++. Participants emphasize that Arduino programming is primarily based on C++, although it incorporates elements from both C and Wiring. It is noted that while Arduino sketches are written in a simplified format, they are ultimately compiled into C++ code. Users are encouraged to learn C++ for its object-oriented features, which are beneficial for future programming endeavors. The conversation also touches on the importance of understanding the underlying hardware and libraries, as well as the potential for writing libraries in C. Overall, a foundational knowledge of C and C++ is deemed essential for effective Arduino programming.
Summary generated by the language model.
ADVERTISEMENT