As an aside, for the C/C++ purists amongst us, my understanding is that when we initiate a compilation, the IDE slips in a "main" function while we aren't looking.
Are you saying that the first step is to interpret the code into C and then compile it? Unless that step is very well handled, I can imagine the C compiler rejecting something and providing a cryptic reponse which would floor the beginners.
@Antedeluvian: Are you saying that the first step is to interpret the code into C and then compile it? Unless that step is very well handled, I can imagine the C compiler rejecting something and providing a cryptic reponse which would floor the beginners.
No, the code you write is essentially C/C++.I'm sure I didn't explain this very well. Let me take another stab at it. A regular C/C++ program contains one or more functions. One of these functions has to be called "main", e.g.:
// your statements go here
When you run your program, the operating system essentially hands control over to the "main" function in your program. The OS may also pass parameters into the "main" function. You can add a bunch of other functions in your program and these could be called from "main" (or one or more of them could be called from "main" and these could call the others).
When you are in the Arduino IDE, your programs (called "sketches") do not have a "main" function -- but they must have a "setup" function and a "loop" function as follows:
// Your statements go here
// Your statements go here
The Arduino documentation explains that the "setup" function (well, I think they say "the statements in the setup function") is executed one time, after which the "loop" function (the statements in the loop function") is executed over and over again.
Once again, you can add as many of your own functions as you wish. You can call your own functions from the "setup" function and/or the "loop" function; also some of your own functions can call others of your own functions, just like regular C/C++.
When I say that my understanding is that the Arduino IDE "slips in a 'main' function while we aren't looking," I think that what it does is take your sketch and use it to generate a temporary file that looks something like the following:
boolean keepDoingIt = true;
setup(); // Call "setup" function one time
while (keepDoingIt == true)
loop(); // Call "loop" function repeatedly
// This is your "setup" function
// This is your "loop" function
So the IDE doesn't interpret your code into C/C++; your code is C/C++. The temporary file (including the under-the-hood "main" function) is just handed over to a regular C/C++ compiler. Any error messages you receive are no more crypric than they usually are from a compiler :-)
I agree -- having the Blink program pre-loaded is a great idea -- and even if it's not loaded, the fact that they provide a copy with the IDE and you can download it yourself over the USB cable really does make it easy to get up and running.
The impressive thing to me is how easy it is to get started in comparison to other standard IDEs. I just downloaded the update, placed it in my applications folder, fired it up and ran blink all in about 60sec. Try and do that with any other IDE and it takes at least 2 orders of magniture longer (if all goes perfect!).
Now the other IDEs do have lots more features, but getting that first design up and running is critical to grabbing my interest. There should be the 'simple' mode that the IDEs come up in to start and as you learn the esy tools other come 'online'. Now an expert can override this and just go to the full set, but the new users would be so much more comfortable.
The conclusion I come to is that most IDE manufacturers aren't really looking for new users...
@DrFPGA: The impressive thing to me is how easy it is to get started in comparison to other standard IDEs.
Ease of getting started is reflected both in the IDE and the hardware -- the fact that the Blink program is pre-loaded means that as soon as you connect your Arduino to your host computer via the USB cable, the USB powers the board and a LED on the board starts blibking to show you that all is well -- and this is before you've even downloaded the IDE...
@Max- Most simple eval board come with a preoaded demo- usually more complicated than Blink, but you can plug them into USB and have them do a demo. TI eval board for example can come up with the LCD screen showing the TI logo and a few user selectable routines ready to go (I like the one where you tilt the board and the cursor on the LCD screen slowly 'rolls' around.
But what these eval systems can't do is allow you to download the example code (from the IDE!), compile it and run it on the board all in 60 seconds. I'd love to see a comparison as to how long it takes for EACH vendors IDE to do that! Kind of like the fat content posted on a breakfast bar...
But what these eval systems can't do is allow you to download the example code (from the IDE!), compile it and run it on the board all in 60 seconds.
Without trying to cast aspersions on the Arduino, or any other evaluation- my experience with Android has caused me to be a little cautious of canned solutions that quickly show you your system is working. Android has a bulit in "hello world" and you can have it running in 10 seconds once you have installed the environment. But the next step of creating your own program is not a simple incremental progression.
You are correct that it is never as easy as it seems to get to your own design, and Arduino isn;t really built to create complex designs as we typically need for a production ready syste, BUT it is a great way to get a few simple projects 'under your belt' so moving to the next stage isn't as daunting...
For example, I wanted to do a simple project to play a short segemnt of a popular movie theme (Star Wars) when a timer expired. I was able to use an existing example design to quickly prototype it in about an hour (most of the time was spent downloading the sheet music and transcribing (with much trial and error) into the note data the program needed). Easy Peezy!
At least thats been my experience. If I was trying to build a remote controller robot from scratch with Arduino I might not be so positive about the experience...