Breaking News
Blog

Wrapping One's Brain Around the Arduino, Part 2

NO RATINGS
1 saves
Page 1 / 2 Next >
View Comments: Oldest First | Newest First | Threaded View
Page 1 / 4   >   >>
antedeluvian
User Rank
Blogger
Interpret to C?
antedeluvian   10/9/2013 9:12:32 AM
NO RATINGS
Max

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.

Max The Magnificent
User Rank
Blogger
Re: Interpret to C?
Max The Magnificent   10/9/2013 10:14:52 AM
NO RATINGS
@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.:

main ()

{

   // 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:

setup()

{

  // Your statements go here

}

 

loop()

{

  // 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:

main()

{

  boolean keepDoingIt = true;

  setup();     // Call "setup" function one time

  while (keepDoingIt == true)

    loop();    // Call "loop" function repeatedly

}

setup()

{

   // This is your "setup" function

}

loop()

{

   // 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 :-) 

Does this make more sense?

DrFPGA
User Rank
Blogger
Arduino IDE on MAC
DrFPGA   10/9/2013 11:00:23 AM
NO RATINGS
One of the things I like is the availability of the Arduino on the MAC. here is what it looks like with the Blink Code loaded. Comes as an example and is easy to load, verify, compile and run.

 

Very easy to get strated with!



Max The Magnificent
User Rank
Blogger
Re: Arduino IDE on MAC
Max The Magnificent   10/9/2013 11:14:55 AM
NO RATINGS
@DrFPGA: Very easy to get strated with!

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.

 

DrFPGA
User Rank
Blogger
Re: Arduino IDE on MAC
DrFPGA   10/9/2013 11:35:25 AM
NO RATINGS
@Max-

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...

Max The Magnificent
User Rank
Blogger
Re: Arduino IDE on MAC
Max The Magnificent   10/9/2013 11:41:06 AM
NO RATINGS
@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...

DrFPGA
User Rank
Blogger
Re: Arduino IDE on MAC
DrFPGA   10/9/2013 12:07:56 PM
NO RATINGS
@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...

Max The Magnificent
User Rank
Blogger
Re: Arduino IDE on MAC
Max The Magnificent   10/9/2013 12:16:18 PM
NO RATINGS
@DrFPGA: I'd love to see a comparison as to how long it takes for EACH vendors IDE to do that!

I'd love to see that comparison also... when do you think you'll be able to do it and write it up for me? :-)

antedeluvian
User Rank
Blogger
Re: Arduino IDE on MAC
antedeluvian   10/9/2013 12:20:37 PM
NO RATINGS
DrFPGA

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.

DrFPGA
User Rank
Blogger
Re: Arduino IDE on MAC
DrFPGA   10/9/2013 12:34:09 PM
NO RATINGS
AD-

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...

Page 1 / 4   >   >>
August Cartoon Caption Winner!
August Cartoon Caption Winner!
"All the King's horses and all the KIng's men gave up on Humpty, so they handed the problem off to Engineering."
5 comments
Top Comments of the Week
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Times on Twitter
EE Times Twitter Feed
Flash Poll
Radio
NEXT UPCOMING BROADCAST
How to Cope with a Burpy Comet
October 17, 2pm EDT Friday
EE Times Editorial Director Karen Field interviews Andrea Accomazzo, Flight Director for the Rosetta Spacecraft.