Show Posts
Pages: 1 2 [3] 4 5 ... 265
31  Using Arduino / Programming Questions / Re: Struct as argument on: April 06, 2014, 11:09:21 am
All these _ etc are conventions you can use or not use they have no true meaning in the language specifications

Many commanys have there own ideas, MicroSoft 10 years or so ago used so called Hungarian notation . where variable names tried to describe themselves for program documentation..

Naming conventions are a modern idiom, but names are better than callingvariable a,b.c etc only..
I'm so glad they dropped Hungarian notation with .NET...  However, I know some ex-Microsoft developers who even now STILL use Hungarian notation, and it bugs the hell out of me!  Horrible idea...

I do remember when all I had at my disposal was variables A-Z and A$-Z$ and floating point was non-existant...  Those were the days...

But we digress...

In C and C++ things always have to be declared before they can be used.  That "before" means lexically in the file - i.e., higher up the page.

You can "forward" declare something in C and C++ by putting in what is called a "prototype" - i.e., something that says "I am going to further define this later on, but this is roughly what it will look like".  For a function that might be:
Code:
void function b(); // This is the prototype

void function a() {
  b();
}

void function b() {
  // ...
}
Function B is defined after function A, yet function A wants to call function B, so it need to know about it, so a prototype is added before function A to tell it that function B will be defined later.

You don't need to do any of that on the Arduino because the IDE does it all for you - it scans through your sketch looking for functions and builds up a list of prototypes which it then inserts into the top of your sketch after any #includes.

Now, if one of those functions has your own typedef or struct in it, where that typedef or struct is defined at the top of your sketch, the prototype (using that typedef or struct) will be inserted before the typedef or struct is defined, and the IDE isn't clever enough to know any better.  So, it throws a wobbly because it doesn't know what the variable types in the prototypes are.

By moving the typedefs or structs into a header file and #include-ing them into your sketch at the top you are forcing those definitions to occur before where the prototypes are inserted.
32  Using Arduino / Programming Questions / Re: Struct as argument on: April 06, 2014, 10:47:24 am
I did not say it was not acceptable but having lectured c and c++ to newbies ysing the typedef route more clearlydefines what a structure is..
 
So does appending the commonly used _t to signify a typedef...  It should really be key_t...
33  Using Arduino / Programming Questions / Re: Struct as argument on: April 06, 2014, 10:37:52 am
Afraid your problems are because of misunderstanding of some fundamental C programming ideas.. or even programming ideas.

 I have the following struct:

struct key {
  int board;
  int value;
  int type;
};

does not create a variable its a struct definition i.e how you want to group the data  would advise you use..
form its more obvious for newbie..

typedef struct  {
  int board;
  int value;
  int type;
} key;  // now it is obvious you have defined a new variable type but not the variable

key myKey;  // now the variable mykey exist of type key

myKey.board = 9;  // thats how to get to items inside  notice the dot
Not strictly true.  While that held true for C, C++ does the typedef of a struct for you.
Code:
struct key {
  int board;
  int value;
  int type;
};

key foo;
is perfectly acceptable in C++.
34  Using Arduino / Programming Questions / Re: Creating Multiple Interrupts on: April 06, 2014, 10:27:36 am
Have you installed the library?
35  Using Arduino / Programming Questions / Re: Creating Multiple Interrupts on: April 06, 2014, 10:21:05 am
You are, of course, assuming the TX buffer is empty.  What if you only want to send 3 characters (say, the number 200), yet the buffer, because of what you are already sending elsewhere, only has 2 characters remaining in it? Or worse, non?

For example, your ISR triggers while the sketch is already waiting for room in the serial buffer.  Oops - crash and burn...

Remember: serial is SLOW - so slow your sketch may be spending a lot of its time waiting on that serial buffer to get some room in it.

So all in all, using Serial inside an ISR is bad, no matter which way you look at it.
36  Using Arduino / Programming Questions / Re: Creating Multiple Interrupts on: April 06, 2014, 10:08:33 am
It's not a question of "trying not" to use Serial.print inside an ISR.  It's a case of NEVER use Serial.print() inside an ISR.

The serial TX buffer is emptied as it transmits, which is done by an interrupt.  When inside another interrupt that Serial ISR won't ever run, so as soon as you fill up the (small) serial TX buffer the sketch will just sit and wait in an endless while loop waiting for room in the buffer that will never appear.
37  Using Arduino / Networking, Protocols, and Devices / Re: Arduino to RS232 with UART on: April 06, 2014, 09:58:05 am
The Arduino id 5V, the DE2 is 3.3V, that's 1.7V too many.
38  Using Arduino / Networking, Protocols, and Devices / Re: Arduino to RS232 with UART on: April 06, 2014, 09:52:39 am
If that's coming straight from the FPGA then yes, it'll be 3.3V.  You may want to add a level shifter to your Arduino's TX so it doesn't over-power the FPGA's input, but other than that it should work fine.
39  Using Arduino / Programming Questions / Re: Struct as argument on: April 06, 2014, 09:49:47 am
Try putting your struct into a header file and #include-ing it.  It's probably the auto-generated function prototypes that the IDE inserts that's causing the error.
40  Using Arduino / Networking, Protocols, and Devices / Re: Arduino to RS232 with UART on: April 06, 2014, 09:48:25 am
That depends on exactly WHAT it is you're connecting to.

The RS-232 standard uses higher voltages than the Arduino can cope with - up to +/- 12V, so do NOT just plug it in without checking first.

You can directly connect to something that uses TTL-level (+5V / 0V) UART signalling, but not direct to, say, a PC's serial port.  For that you will need something like a MAX232 chip to convert the voltages.

Please tell us what it is you're connecting to so we can advise better.
41  Using Arduino / Project Guidance / Re: Horizontal printing with Serial.print/ln on: April 06, 2014, 08:38:49 am
Successive Serial.print() calls go horizontal.  It only goes to the next line when you use Serial.println().

Code:
Serial.print(val1);
Serial.print(",");
Serial.print(val2);
Serial.print(",");
Serial.println(val3);
42  Using Arduino / Motors, Mechanics, and Power / Re: Power supply on: April 06, 2014, 08:19:53 am
If the voltage is within specification, yes, that is more than enough current to run an Arduino.

What is the voltage?  THAT is the important value.
43  Using Arduino / Programming Questions / Re: What goes in setup, what comes before? on: March 26, 2014, 01:26:08 pm
Quite a lot of things happen before setup() is called.

Many people think that main() is the first bit of code called, but that is not correct.

The first bit of code is called "crt0" (C RunTime stage 0).  This performs:

1. Copying of pre-set variable data from flash to RAM
2. Configure basic system settings
3. Executing of global object constructors
4. Execute main()

On the Arduino main() then does a number of functions, including setting up the timers for millis(), PWM, etc, and configuring such things as interrupts and ADC.  It basically gets the system ready for you - all things you would normally be doing manually in a less abstracted system. (check out the init() function in wiring.c)

Then and only then does setup() get called.

Point 3 in the list above is the one that catches most people out.  If you have a global object with code in the constructor that does things with peripherals that aren't configured until main() has run then you can have all sorts of strange things happening or just plain not working right.  That is why most classes have a .begin() member function to do all the configuration instead of doing it in the constructor.
44  Using Arduino / Programming Questions / Re: UECIDE error For compiling LCd Program on: March 26, 2014, 04:59:06 am
Don't worry, this is the third forum.  I'm trying to help him on the official forum, but the language barrier is being a bit problematic.  I posted a reply here for future reference of others.
45  Using Arduino / Programming Questions / Re: UECIDE error For compiling LCd Program on: March 26, 2014, 04:56:34 am
lcd.ino also needs to include LiquidCrystal.h
Pages: 1 2 [3] 4 5 ... 265