I've been using the Arduino language for a while now and I'd like to have a go at coding in raw C or C++ instead. I know a little C++ and I've begun by compiling and uploading some of the examples on this page: https://www.mainframe.cx/~ckuethe/avr-c-tutorial using the ino Python package. This all works fine, but I'm looking for more example code so that I can expand my knowledge. Does anyone know where I can look? Most of the examples I find on the net just blink the LED.
if you like video instruction here are some good youtube channels on using AVR chips with Atmels Studio 6
which is what i have personally been doing my self just trying to broaden knowledge into AVR microcontrollers in general as oppose to strictly Arduino
Human HardDrive Human HardDrive - INtro to Avr - C - programming
Ive learned a bit from both these guys , make sure to brush up on your bit shifting and operations or just write a good macro to keep it simple
and get the chips datasheet , set is as your desktop background hahhaa youll learn the pinout in no time.
Also get a programmer , i use tinyISP but its requires some work to get it all working with Atmel studio.
If you get a supported programmer like MkII (MK2) then it is supported off the bat.
Enjoy. its rather fun and the Atmel Studio is based on VIsual Studio which is pretty neat. in my opinion of course
if you want example code search perhaps AVR Freaks
Nick, I think there is some confusion about what I'm asking. I state in my question that I am familiar with the the Arduino platform and know a little C++, so I'm obviously not asking a generic beginner "how to program an Arduino" question. The sticky at Point One tells the beginner to Google "C++ tutorial." It would be more useful if it instead referred people to this page: Arduino - Home and this page: http://arduino.cc/en/Tutorial/HomePage A generic C++ tutorial will be useless to an Arduino beginner. Perhaps the sticky should be updated?
The Arduino can be programmed in fully fledged C++ but the "sketches" one typically sees in tutorials, etc, are based upon a stripped down and simplified (Arduino - Home) version of C; hence I was using the term "raw C" to distinguish the alternative. I don't know if "raw C" is the best descriptor, but it's been used in the past: http://gentoo-en.vfose.ru/wiki/Raw_C_on_Arduino_Uno, Which programming languages are supported to program Arduino? - Electrical Engineering Stack Exchange I guess "C for AVR" is an equally good descriptor: as the second respondent realised, what I'm effectively trying to do is learn more about generic programming of AVR micro-controllers using AVR Libc.
As instructed by point 5 of your sticky (which I read before posting), I took the effort to provide an example: I supplied a link to show what I am working through and what I'd like to learn more about. If you go to that link you will see that, for instance, writing a "hello world" script for serial output in C using AVR Libc (https://www.mainframe.cx/~ckuethe/avr-c-tutorial/lesson4.c) is very different from the equivalent Arduino Sketch (http://arduino.cc/en/Tutorial/SoftwareSerialExample). That is the basis for my question.
eddiea6987:
if you like video instruction here are some good youtube channels on using AVR chips with Atmels Studio 6
which is what i have personally been doing my self just trying to broaden knowledge into AVR microcontrollers in general as oppose to strictly Arduino
Thanks, the links are useful. Right now I'm using an Arduino rather than programmer and a bare AVR chip. It's enough to get me going.
raacampbell:
The Arduino can be programmed in fully fledged C++ but the "sketches" one typically sees in tutorials, etc, are based upon a stripped down and simplified (Arduino - Home) version of C;
Arduino IS C++. It is not a stripped down version at all. The reference page just shows a list of functions which are written to make your life easier. Just look inside the arduino core, you will see that there is nothing special, no changes to the language, just a load of header and cpp files with C++ functions in them.
I see, thank you, I hadn't realised this. I played around a little and I see that you're right.
But can you clarify something, please? I thought it was a subset of C or C++ because, for instance, at the bottom of the reference page (Arduino - Home) it states that "The Arduino language is based on C/C++". Also, some guides I've seen (such as this PDF: Home) describe the "Arduino programming language" as "a simplified version of C/C++" So is this just wrong or does mean something other than what I originally thought? e.g. Is is just that certain common libraries, such as iostream, aren't needed on an Arduino?
Is is just that certain common libraries, such as iostream, aren't needed on an Arduino?
There are some things that make sense in a system with more resources and an operating system, like fork(). fork() makes no sense on a system without a task-switching context manager (also known as an OS). The "Arduino language" is C++, which is a superset of C, but there are things missing, that make no sense on the Arduino.
The sketch you run on your arduino is compiled by the gcc compiler, so it can use the full capability of C++. Some library functions are omitted or reduced for space - an example of this is sprintf - it doesn't support %f for printing floats. There are also of course functions like printf and fork that make no sense in a microcontroller environment.
The homepage quote is a little misleading; I can only assume that it is a reference to the behind the scenes manipulation of your sketch to add a main function.
The statement from the PDF just isn't accurate. It's true that most sketches you'll see here don't use many C++ features (although the libraries do) but those features are available to you if you want them.
Ah... Thanks, chaps. This is really useful. This "simplified" C++ thing has been a source of confusion for me for some time. There's a lot of misleading (at least to me) stuff out there. Here's another: http://arduino.cc/en/Reference/Comparison where it states "The Arduino language (based on Wiring) is implemented in C/C++". So the resources on this very site make it look as though there is some separate language at play.
So if I want to learn more about what's under the hood, I should be looking for "AVR Libc" tutorials? If anyone knows any good introductory books or websites (in addition to those above) that would be much appreciated.
It looks like we are on the same page now. I was trying to clarify that the IDE supports full C++ (and indeed C if you add a secondary file to your project). A compiler switch disables exceptions, however that isn't really changing the language, since you could do that on other platforms too.
The home page which carries on about "based on C" is rather misleading IMHO. That is really why I put that "point 1" in the sticky, to try to head off questions about what the language is really like.
the "sketches" one typically sees in tutorials, etc, are based upon a stripped down and simplified ... version of C;
Tutorials tend to be simplified, yes, but really they are not a simplified version of C. Just simplified. (And indeed, C++, because things like Serial are a class).
We had a recent discussion about this in another thread as to whether the fairly minor changes made by the IDE to the source of your sketch constitute a language change.
That's a good thought but perhaps this point should be expanded in the sticky? I can see how it could have answered my question, but as it reads now it conveyed to me "RTFM about C++ before asking about it on the forum." That felt like an answer to a different question.
Arduino has being programmed in C++, as everyone knows; but what a lot of people do not know (until you face it) is that you CANNOT have a multi-archive project. That means, if you've gotten some nice code in C++ (or plain C) and you want to use it as is (without changing the file's name) in your Arduino project, you are not allowed to do it 'cause INO doesn't support multi-file projects.
Of course, the quick-and-dirty turnaround is to copy and paste your nice code into a INO's file. But that's not only awful, but also not so much professional.
Personally I don't like Arduino, 'cause I consider myself as a professional developer. However, I love the fact that this platform is full of libraries that one can use.
I've often wondered what the regulars here feel about Nick's statement: ...the IDE supports full C++...
True, the IDE doesn't throw up on the double data type, but does it really support it? I'd say no, especially when some of the underlying objects don't support that data type. I'm not sure how to answer someone if they ask me if the IDE supports "full" (ANSI?) C.
but what a lot of people do not know (until you face it) is that you CANNOT have a multi-archive project.
Yes it does. You can make a new "tab" in the IDE and add in .cpp and .h files, just like in a regular project. Plus, libraries let you extend your code by bringing in extra modular components.
I've often wondered what the regulars here feel about Nick's statement: ...the IDE supports full C++...
True, the IDE doesn't throw up on the double data type, but does it really support it?
Well, I agree with it, but then I would, wouldn't I?
Give us an example of it not supporting C++.
It doesn't support exceptions (throw/catch), but that is a compile-time option.
I'd say no, especially when some of the underlying objects don't support that data type.