Design Con 2015
Breaking News
Comments
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?

jjulian274
User Rank
Rookie
Re: Interpret to C?
jjulian274   10/10/2013 11:50:34 AM
NO RATINGS
Max,

 

Actually, the "main" function is defined among the other files in the hardware specific directory of the arduino ide installation.  I just discovered this myself fairly recently while reading a book on programmin the arduino as an AVR platform.

 

Max The Magnificent
User Rank
Blogger
Re: Interpret to C?
Max The Magnificent   10/10/2013 11:54:13 AM
NO RATINGS
@jjulian: Actually, the "main" function is defined among the other files in the hardware specific directory of the arduino ide installation.

Ah -- thanks for the update -- so, does it look anything like I suggested in my earlier comment below?

jjulian274
User Rank
Rookie
Re: Interpret to C?
jjulian274   10/10/2013 11:57:46 AM
NO RATINGS
Max,

 

Yes, the main is nothing (usually) but:

 

int main()

{

    init();   // I think.  This is where hardware specific initialization is done (IO ports, timers, etc.

    setup();

    whilte (1)

    {

        loop();

    }

return 0;

}

 

I think this is where it is incase there is "extra" initialization that needs to be done.

 

Hope that helps.

Max The Magnificent
User Rank
Blogger
Re: Interpret to C?
Max The Magnificent   10/10/2013 12:02:51 PM
NO RATINGS
@jjulian274: Yes, the main is nothing (usually) but...

Great -- thanks for this. Now, do you have any thoughts on the question I just posed in a blog I posted a short time ago: What's the Best Robot Base for my Arduino?

TonyTib
User Rank
CEO
Main loop is like Structured Text
TonyTib   10/10/2013 12:34:38 PM
NO RATINGS
A bit of semi-off-topic trivia:

since the Loop() function runs continously, that makes it a bit similar to programming in Structured Text on a PLC (programmable logic controller) -- the PLC code is run as a continuous loop, whether you're using ladder logic (ugh!) or structured text (better).  The syntax is very different, however (ST is kinda BASIC/Pascal hybrid with PLC oddities).

Max The Magnificent
User Rank
Blogger
Re: Main loop is like Structured Text
Max The Magnificent   10/10/2013 12:48:02 PM
NO RATINGS
@TonyTib: A bit of semi-off-topic trivia...


I LOVE off-topic trivia!!!

Duane Benson
User Rank
Blogger
Re: Interpret to C?
Duane Benson   10/9/2013 1:25:41 PM
NO RATINGS
AD - I can confirm that some of the error messages are rather cryptic. I've had a few that don't seem to give any actual information relative to what the error ended up being. That's kind of frustrating.

I've developed (in my head) a standard checklist of sorts to look at first when there's an unclear error message.

DrFPGA
User Rank
Blogger
Re: Interpret to C?
DrFPGA   10/9/2013 2:56:54 PM
NO RATINGS
@Duane-

Maybe a blog post where you take the checklist out of your head and show us?

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

DrFPGA
User Rank
Blogger
Re: Arduino IDE on MAC
DrFPGA   10/9/2013 12:39:41 PM
NO RATINGS
@Max- If we could get several volunteers to each try out one MCU/IDE combination I would be happy to compile all the info.

Task-

Start the timer.

Download the IDE used with a simple MCU eval board.

Download the code for Blink (or hello world, etc)

Compile and load the code into the board

Watch it work.

End Timer

Report board, IDE and Time Required. (And any 'bumps' encountered, like license not working, need to update code, example design out of date, USB driver not installed correctly for your version of Windows, etc)

 

Let's find some takers. Anyone want to pick a particular board/IDE to start?

Caleb Kraft
User Rank
Blogger
Re: Arduino IDE on MAC
Caleb Kraft   10/9/2013 2:35:21 PM
NO RATINGS
blinking and hello world are no problems. THey usually have that code ready to go with the board. However, where I find the most benefit to the Arduino community is that there are THOUSANDS of tutorials for things beyond that.

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

Duane Benson
User Rank
Blogger
Re: Arduino IDE on MAC
Duane Benson   10/9/2013 1:30:45 PM
NO RATINGS
AD - I have few negative things to say about the Arduino when used for it's intended purposes. The biggest issue I ran into originally was the limited amount of RAM and program storage FLASH available.

I was able to set up a wired Arduino web server amazingly quickly. However, when I tried to make it wireless, I ran out of space.

I got my Arduino working with a Ti CC3000 WiFi breakout board, but when I tried to add in a small OLED, I ran out of RAM.

Since that time, I've discovered 32 bit Arduino compatible boards. The ChipKIT PIC32-based Arduino I have has plenty of both RAM and FLASH. It's pretty compatible, but not quite 100%, so I've run into a few issues there.

alex_m1
User Rank
CEO
Re: Arduino IDE on MAC
alex_m1   10/9/2013 2:42:18 PM
NO RATINGS
Duane , i believe the arduino due is fully compatible(specifically designedby atmel for this purpose) , and more capable(32 bits, mor memory ).

Duane Benson
User Rank
Blogger
Re: Arduino IDE on MAC
Duane Benson   10/9/2013 6:41:21 PM
NO RATINGS
Alex - Yes, the Due is 32 bit. There are more and more 32 bit Arduino compatibles popping up too. My theory is that with the more powerful procesors, the Arduino language will start to fnd acceptance in some commercial applications.

alex_m1
User Rank
CEO
Re: Arduino IDE on MAC
alex_m1   10/9/2013 7:07:32 PM
NO RATINGS
Duane,

Even if people accept the open license terms of the arduino for some projects, wouldn't it just make sense to learn the mbed, and due to commercial friendly licensing terms , use it it in more projects , and get a better return on learning?

Also, yes there are plenty more content/code around the arduino than the mbed, but if we're talking about professionally usable content/code , how do they really compete ?

 

Duane Benson
User Rank
Blogger
Re: Arduino IDE on MAC
Duane Benson   10/9/2013 8:45:15 PM
NO RATINGS
Alex - Right now, the Arduino doesn't really compete with the mbed in the comercial world. I think that's changing though. I think that the Arduino will end up as a decent alternative; especially in the cross over from maker to commercial community.

I'm a big fan of the mbed too. It's nice to see it showing up on more platforms as well.

TonyTib
User Rank
CEO
Don't forget the standard IO & sensor systems
TonyTib   10/9/2013 5:29:54 PM
NO RATINGS
Although I prefer the BeagleBone, I'm getting an Arduino for my nephew, because of the size of the ecosystem & amount of tutorials (he has NO electronics experience).  However, instead of getting a kit with discrete parts, I'm buying a Seeeduino plus the Seeeduino Grove shield, some Grove devices, and (I hope I can get them to work at the same time) an Arduino motor shield R3 (which actually has Tinkerkit connectors).

The Grove & Tinkerkit systems are similar: there are standard connectors and then you can get various prewired devices. Devices can communicate via analog input, digital input, digital output, or I2C.

The Grove system is currently cheaper than Tinkerkit & has a wider variety of components, such as analog thumb joystick, button, motor controller, OLEDs, LEDs, current sensors, PIR, WiFi, Bluetooth, and much more.  You can also get Grove kits, but I much prefer picking out exactly what I want, for substantially less than a kit (or the kits you showed).

Similar systems include Digilent's Pmods, Olimex's UEXT, mikro elecontrica's mikro bus, and Microsoft's Gadgeteer.

Hoyt_Stearns
User Rank
Manager
Quicker development if you use FORTH
Hoyt_Stearns   10/11/2013 3:06:44 PM
NO RATINGS
That's all very nice, but you can skip the "edit-compile-reedit-compile-load-test"

phases if you just use the FORTH language to begin with :-) . Development goes much faster.

 

e.g. : http://forum.arduino.cc/index.php/topic,8838.0.html

 

Hoyt Stearns

Scottsdale, Arizona US

Max The Magnificent
User Rank
Blogger
Re: Quicker development if you use FORTH
Max The Magnificent   10/14/2013 4:36:14 PM
NO RATINGS
@Hoyt: ...you can skip the "edit-compile-reedit-compile-load-test" phases if you just use the FORTH language to begin with...

I must admit that I always has a soft spot for FORTH -- also I once met Chuck Moore (the guy who invented FORTH).

TYsun
User Rank
Rookie
Re: Quicker development if you use FORTH
TYsun   10/16/2013 2:00:44 PM
NO RATINGS
"The Magnificent" ??? oh please. Not another narcissist. Narcissism makes whatever positive traits suspect due to your infatuation with your own image. Good luck with your autoerotism.

Max The Magnificent
User Rank
Blogger
Re: Quicker development if you use FORTH
Max The Magnificent   10/16/2013 2:04:27 PM
NO RATINGS
@TYsun: Good luck with your autoerotism.

Why thank you -- that's very kind of you (sad to relate, I don't even know how to spell narcissism :-)

Max The Magnificent
User Rank
Blogger
Re: Quicker development if you use FORTH
Max The Magnificent   10/16/2013 2:08:24 PM
NO RATINGS
@TYsun: Oh please. Not another narcissist.

What? You don't like the competition? LOL

If only I had the wit and daring to come up with a cool screen name like TYsun, I wouldn't have to spend all my time on this never-ending quest for self-validation.



Flash Poll
Top Comments of the Week
Like Us on Facebook
EE Times on Twitter
EE Times Twitter Feed

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Life
Frankenstein's Fix, Teardowns, Sideshows, Design Contests, Reader Content & More
Max Maxfield

Book Review: Deadly Odds by Allen Wyler
Max Maxfield
10 comments
Generally speaking, when it comes to settling down with a good book, I tend to gravitate towards science fiction and science fantasy. Having said this, I do spend a lot of time reading ...

Martin Rowe

No 2014 Punkin Chunkin, What Will You Do?
Martin Rowe
Post a comment
American Thanksgiving is next week, and while some people watch (American) football all day, the real competition on TV has become Punkin Chunkin. But there will be no Punkin Chunkin on TV ...

Rich Quinnell

Making the Grade in Industrial Design
Rich Quinnell
13 comments
As every developer knows, there are the paper specifications for a product design, and then there are the real requirements. The paper specs are dry, bland, and rigidly numeric, making ...

Martin Rowe

Book Review: Controlling Radiated Emissions by Design
Martin Rowe
1 Comment
Controlling Radiated Emissions by Design, Third Edition, by Michel Mardiguian. Contributions by Donald L. Sweeney and Roger Swanberg. List price: $89.99 (e-book), $119 (hardcover).