I am trying to use C++ on my Arduino uno board with the Arduino program and other programs, but have found myself stuck. I've looked into this online but have found no specific instructions on how to do so. I understand that the Arduino program uses C/C++ but I just want to use C++. I have also read a topic on the forums about removing the preprocessor so that you would be able to use C++ only. All of this information I have found I feel is wrong, because I am new to coding, and I am hoping that someone with a better understanding than I could help me.
The Arduino IDE uses C++ but of course the physical environment is limited so not all C/C++ features can be used and the Arduino environment has helper functions to enable you to use the hardware easily and the Serial monitor for input/output.
I was planning to use the Arduino to learn the basics of coding and eventually learn C++ on my own. I'm not sure what everyone means when they say that the arduino program uses c/c++ when the commands are completely different.
Almost without exception the whole of the C/C++ language is available on the Arduino but any program will need to interact with the user an/or external hardware hence the Arduino extensions. The Arduino reference page details these extensions as well as some standard C/C++ functions but the list is not exhaustive, nor could it be.
One thing that the Arduino IDE does is to hide some the the mechanics of C/C++ by not requiring there to be a main() function written by the user. Rather it is added during the compilation process but as I said in my previous reply you can write your own but you will then also be responsible for initialising the Arduino hardware environment which the Arduino compilation process also does behind the scenes.
Well even if the Arduino commands are not completely different from the commands from C/C++, is there a third party program that is supported by arduino that i could use without the different commands?
JohnIguana:
Well even if the Arduino commands are not completely different from the commands from C/C++, is there a third party program that is supported by arduino that i could use without the different commands?
The biggest bar to this is input and output to/from the Arduino. As Robin suggests you would be better to focus your efforts to learn C/C++ on the PC unless/until you need the functionality that the Arduino hardware can provide.
If you really want to learn C/C++, learn it on a PC (as Robin indicated). It teaches you how to properly construct a program. No Arduino Builder that takes a little bit of work out of your hands but sometimes drops a stitch and you have no idea what is wrong.
If you use Linux (and the same probably applies to the Mac), it comes with C and C++ compilers. For Windows, you can download a free edition of Visual Studio; it used to be called Express, I think it's now 'Community Edition'); just check if it supports C++, I think it does. There are plenty other free compilers available for Windows.
Next when you start using Arduino, you have a solid foundation but there are minor differences. There ain't things as reading keyboard and writing to screen (as the Arduino does not have them). And there are a few libraries added so you can read pins and control outputs and the likes.
In this context by "arduino" you must mean your Arduino Uno. The compiler used by the Arduino IDE for the Uno is avr-gcc. So if you want to program your Uno with C++ but don't want any of the Arduino libraries then just use avr-gcc directly. Or you could use the Arduino IDE but not use any of the Arduino libraries.
But you need to understand that Arduino sketches are C++. There is no Arduino language, only some helpful libraries, mostly in C++. If you start writing programs with the Arduino IDE I guarantee you will learn C++, even if you take advantage of the many useful libraries available to you. You're always welcome to open up the library source files and learn from them instead of pretending they don't exist.
You may notice that Arduino sketches have the extension .ino, which is not a standard extension used for C++ files. The reason for this is that there is a minor amount of preprocessing done on .ino files before they are renamed with the .cpp extension and compiled with the C++ compiler. The preprocessing is:
In the IDE, open File:Preferences and turn on Verbose outputs.
Compile a simple sketch.
You will see all the commands that are being executed, some of which are the avr-gcc commands.
Copy & save those, experiment with running them with the avr-gcc environment.
I'm thinking about starting to play with the Arduino. From what I've read, the "native" language (or language of choice) is C/C++. But what if I want to use the MPU's assembly language instead? I didn't find anything on this site about this (haven't searched the forums completely, but so far no answers to my questions).
It's certainly possible to program the AVR in assembly language, but you'll have to do a little extra legwork. The compiler used by the development kit is AVR-GCC, which supports assembly language as an input, but this isn't directly an option from the GUI.
If you want to use an Arduino with its entire GUI infrastructure, libraries, etc. then it's best to use C/C++. If you just want to use it as a microcontroller board, you can achieve the same results using AVR-GCC and AVRDUDE for sending your results to your board, and bypass the GUI altogether. It's easier to program in assembly that way.
You can also mix C and assembly using the "asm" pseudo-function. By using the "naked" attribute for functions, you can write your entire program in assembly code, but from within a C file so that the compiler takes care of all the labels, section directives, etc. For example:
Final word of advice: it's really not worth it. I understand the desire to be as close to the machine as possible, but the AVR architecture makes hand-assembly not that much less efficient than C-language-generated code. Unlike other processors (mostly from the past) where a 10-to-1 improvement is fully expected when comparing higher-level languages to assembly, in my experiences this just no longer holds. The underlying architecture is so C-friendly (lots of registers, orthogonal instructions) that the compiler-generated code is really good.
Rugged: Thanks for the quick reply. And while I don't doubt that C makes things easier, I still prefer down-to-the-bits assembly language for these kinds of projects, primarily for personal reasons. Besides, while I know C, I don't know C++, and really have no desire to learn it (not planning on entering the programming job market any time soon). All that class stuff, etc., gives me a headache.
I have been doing some tinkering in assembly language using two of the 'duino boards. If you haven't purchased a board yet then make sure you get one with an ICSP header - it makes things a lot easier. A real Arduino should be ok and I know that the Modern Device BBB and Lady Ada's Boarduino are suitable.
And is there any documentation I can look at on it? Why is it so difficult to find this stuff? Everything I read on both the download and reference pages implies that the software supports only C/C++.
So if you'll pardon this n00b, some questions: Arduino doesn't actually make the microprocessors, right? These come from Atmel? And what does "AVR" stand for, anyhow? Seems to designate this line of uPs.
The reason you're not finding anything about it on this site is because Arduino tries to make it as easy as possible for beginners to get started with microcontrollers, which means sweeping a lot of information and low-level details under the rug. For example, people are often surprised that the AVR has no notion of "pin 13" but instead breaks the I/O pins up into multiple ports of 8 pins each. "Pin 13" is a higher-level construct layered on top of that.
I should explain my motivation here: while I do prefer the more primitive approach of assembly language for programming, and don't really appreciate or need the "hand-holding" nature of C (or Basic!) programming, I do like the way that Arduino packages the hardware into a neat little bundle. No need to supply my own oscillator crystals, voltage regulators, etc., and the board has easy-to-use connections.
It's fascinating to hear you say that, since I've heard other people say exactly the opposite ("I really like the way the Arduino environment simplifies software development, but the hardware is an overpriced piece of fluff that I could easily make myself.")
(To my thinking, both comments emphasize the "correct" placement of Arduino. It appeals to people who COULD make their own hardware. It appeals to people who COULD write their software from the ground up in raw assembler. It appeals to people who COULD do both. And of course it appeals to people who aren't particularly interested in doing either one, but still want to achieve a result best implemented with a microcontroller...)
Right. Some of us are saying "Oh wow, here's this tiny cheap device that I can program like a computer to do anything" and others are saying "Just this once I'm going to splurge on a huge development board with all sorts of features and I don't have to solder anything or keep a 496 page datasheet handy."
I appreciate how easy the development environment is to use, too. But here's the main reason I use Arduinos now: whatever I build is accessible to anyone. It's easier to share ideas when there's a common platform. If someone wants to try out a microcontroller application I've put together, they don't have to pick up a soldering iron right away.
I agree. Also, one reason I stay with the Deumilanove, rather than moving voer to the Mega, is that the chip is PDIP and therefore I can program something, prototype it then pop the chip out and make my own custom PCB with the chip.
I modified the IDE in a way that the assembly language can be used for sketches. Have a look at the LumiNet thread in this forum and you will find my patches or the whole modified IDE for download. For example, I implemented/ported a very fast software serial lib in assembly language for my ATtiny-based Arduino-compatible boards. And because assembly language, C, and C++ use the same (gcc) compiler, you can call routines from one language in another one.
c80f0f1006