Go Down

Topic: Pass in Arguments to Arduino Due (Read 3797 times) previous topic - next topic

miqbal

Hi everyone

I'm new to Arduino so please excuse this noob question but how could I pass in command-line arguments to main method? or I guess the setup method in this case. WHat I mean is, in C language I could write a program which takes in an argument like this:

Code: [Select]
int main( int argc, char *argv[] ) 
{
   if( argc == 2 )
   {
      printf("The argument supplied is %s\n", argv[1]);
   }
   else if( argc > 2 )
   {
      printf("Too many arguments supplied.\n");
   }
   else
   {
      printf("One argument expected.\n");
   }
   return 0;
}


The reason I need this is because I am building a robot which will go to a certain location via gps coordinates I will supply, I need a nice command-line or graphical way of passing these coordinates to the robot. Any help or assistance will be much appreciated.

If you need any clearification of my question or need more info of what exactly I'm asking, please let me know

Coding Badly

Hello.

The communications path is through Serial.  There is no operating system to pass arguments to main.

GoForSmoke

You could pass user I/O through buttons/switches/sensors/keypad/etc but usually we use serial to PC on the USB cable.
Too bad you need to send coordinates, that pretty much rules out game controllers.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

miqbal

I appreciate your help but could you give me an example? like programmatically, when you guys say communication is through serial, how could I do this? Like would I send in data to the Arduino via the Comm/Serial Monitor?

Code: [Select]
double waypoint1, waypoint2, waypoint3;

Serial.println("Enter a coordinate 1: ");
Serial.input(waypoint1);


I understand this might make absolutely no sense but I hope you can better understand my question here


Coding Badly

I appreciate your help but could you give me an example?


Follow the link in my post.  There are examples in the lower-right corner of that page.

Quote
Like would I send in data to the Arduino via the Comm/Serial Monitor?


Yes.

Code: [Select]
double waypoint1, waypoint2, waypoint3;

Serial.println("Enter a coordinate 1: ");
Serial.input(waypoint1);


http://arduino.cc/en/Serial/ParseFloat

GoForSmoke

Oh dear.....  PC programmer, you're not in Kansas any more.

Regular Arduinos do have float and double but they are the same 32-bit IEEE floating point (6 to 7 places "accuracy") that is computed without an FPU (is slowww). Your BEST BET is to ditch floating point and work in integers which for you probably means a bit of discovery and invention. If you are/were good at math concepts it should be relatively easy. If not then chances are you'll stick with float and either accept the error or torture your code into correcting for the round-offs like so many others.

Regular Arduinos have very little RAM. For example, UNO has 2048 BYTES of RAM. MEGA has 8196. If you use wasteful practices like C++ Strings and/or other Container classes then expect to crash once you get beyond trivial code. That 2k is for both heap and stack which, do they still teach about those or is hardware a non-subject?

Regular Arduinos have no operating system. You put your own bugs in, but you can import libraries and code examples to occasionally save time there. There used to and still may be bumps in the heap management too, I can't say since I avoid deallocation like the plague.

Your Arduino IDE comes with Libraries and Example programs fit to whatever version it is. The Arduino main site has pages just covering those (you would do well surfing the site and bookmarking entry points because you WILL need to refer to them, be sure to get this one too: http://www.nongnu.org/avr-libc/user-manual/modules.html).

If you have to have main() then you can but the IDE is set up to put you inside of main. You may know C++ but there are concepts you clearly have not picked up yet. Here is a good link to start, don't blow it off:
http://arduino.cc/en/Tutorial/Foundations#.Uw8280gz3jI

Spend time with the Examples. They are not perfect, especially the ones that use Strings, but they work. They were written by modern PC programmers.

Learn Blink Without Delay sooner than later. It is at the heart of real time code and interleaved tasking. If you want to 'do more than one thing at a time' then you need BWD.

Get through all that and you will be able to ask much better questions and save yourself much time.

Next time we might be able to talk about finite state machines.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

PaulS

Quote
Regular Arduinos do have float and double but they are the same 32-bit IEEE floating point (6 to 7 places "accuracy")

Hmmm...
Quote
On the Arduino Due, doubles have 8-byte (64 bit) precision.

GoForSmoke


Quote
Regular Arduinos do have float and double but they are the same 32-bit IEEE floating point (6 to 7 places "accuracy")

Hmmm...
Quote
On the Arduino Due, doubles have 8-byte (64 bit) precision.



The Due, Yun and Galileo are IMO FrankenDuinos.
Regular Arduinos run on AVR chips that cost less than 10 Euros.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

AWOL

Quote
The Due, Yun and Galileo are IMO FrankenDuino

The Due, however, is the subject of this topic.

GoForSmoke

I forgot.
But he still has to deal with the IDE or get a different compiler.

It's a shame though, the project could probably run on cheap AVR's.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

AdderD

Yes, the Due can do 64 bit doubles but why would you? The Cortex M3 chip still lacks an FPU just like the AVR chips in the other Arduino boards. It's still slower than a  three legged dog swimming through molasses when trying to do floating point work. The advantage is that the Due is something like 8 times faster in clock speed and has 96k of RAM. On the Due you can get away with some programming habits you picked up doing PC programming and still be OK. But, in my opinion, using floating point is not one of them.

miqbal

There is definitely more to Arduino than I figured but thanks for all your prospectives guys

Go Up