Show Posts
Pages: [1] 2 3 ... 8
1  Using Arduino / Programming Questions / Re: doesn't go throw the whole condition on: March 20, 2011, 10:50:14 am
You have posted raw code.  No comments to communicate the intent.

So when I read it - the result is that I pretty much agree with the complier.  Where as you clearly are not agreeing with the compiler.

To fix this, please add comments to the code that explain what you mean to achieve.
Since you are having problems with the if/else clauses, comment the intent of these, and also comment the code that you want to always run.

This will help others review your code, and from my experience, will help you (the author) clarify what you expect the code to do, perhaps leading you to find your own problem..
2  Using Arduino / Programming Questions / Re: Ethernet Memory Leak :( on: March 20, 2011, 10:38:39 am
strdup() wraps up memory allocation and copying..

Your struct Page has strdup() in its constructor (page.h), and no destructor - so these are memory leaks.

Your DoResponse(...) (WebServer.pde) creates a Page and uses strdup() to also leak memory.

So your program will crash quite quickly.

You have two alternatives
1 - do not use strdup(), just assign the string to the pointer.
2 - or make sure you free the old pointer before replacing it, and free it in the destructor.

--
There is a lot of code, and I am not familiar with the environment, so this is probably not all of the problems.

 

3  Using Arduino / Programming Questions / Re: sketching to read 3 dof IMU combo board on: March 20, 2011, 10:20:23 am
Given your explanation above.. the sensorZero stuff is just confusing you and every one else.

I recommend you remove it until you find a reason for it.

And then you could display the value sensed as a simple integer...

I understand that the sensor reads 0g of acceleration as 2.5 V and varies that by 1V for each g.

So you might expect to see 2.5 v on two and either 1.5 or 3.5v on the other.

ie 512, 512, and 307 or 723.

As you say, the orientation of the sensor would determine which reading is which value.

4  Using Arduino / Programming Questions / Re: sketching to read 3 dof IMU combo board on: March 19, 2011, 10:53:07 am
Your sensor module seems a bit strange to me.
It adjusts readings relative to the first position of the board.
And then it adjusts the X readings by 205?

So the values displayed can not be interpreted without knowing the initial position.
And the X values require mental arithmetic after that.

Do have a reason for this?

Code:
// Sensors Module  ---------------------------------------------------------------------

/* dafid - this is called in the setup() and calculates a 'zero' value that is used to adjust
subsequent readings.
 */
void calibrateSensors() {                                       // Set zero sensor values
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<50; i++)       v += readSensor(n);
    sensorZero[n] = v/50;
  }
/* dafid - except the X axis is specially offset by 205.
      I do not understand why you do this at all.
*/                                                         
  sensorZero[ACC_X] -= 205;                       
}

void updateSensors() {                                         // data acquisition
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<5; i++)       v += readSensor(n);
    sensorValue[n] = v/5 - sensorZero[n];
  }
}
5  Using Arduino / Programming Questions / Re: Timer2 problem on: March 16, 2011, 11:54:26 am
That is correct, but the ISR_NOBLOCK puts it before the registers are pushed onto the stack, reducing the impact on the latency.

And when writing interrupt driven code, the impact of 'too slow' is harder to understand than in simple procedural code, so you do need to be careful how it is written.
6  Using Arduino / Programming Questions / Re: This simple program freezes. Why?? (0022 vs 0021?) on: March 16, 2011, 11:17:01 am
I suspect you are seeing the effect of fragmentation in the heap.
As temporary String objects are created and freed the heap grows, leading to stack and heap colliding, and the program crashing.
A hint for this is - the unused string object on the stack being created and destroyed, changes when the crash happens - and all it does is make the stack a little deeper and allocate and free an empty string.

A test to confirm if it is fragmentation is to reduce the number of causes of fragmentation..
If you can pre-allocate the Strings with a length long enough to hold the result you expect then there will be no fragmentation in the heap as all results will be fit in all free spaces...

Just read code for String .. and .. it is not suitable for use as it always allocates a buffer exactly the length of the string side it, so the fragmentation of the heap can not be avoided that way.

i am out of definitive ideas. i think a character array passed and strcat() will work/ but is ugly.
perhaps the gnu string class works on arduino. it has buffer size args for the constructor.
7  Using Arduino / Programming Questions / Re: sketching to read 3 dof IMU combo board on: March 16, 2011, 10:47:57 am
Hitmitsu,

Start a new thread as your problem is likely different, and discussion will be confused otherwise.
Post your code and a schematic of the wiring.
Tell us what the sensor board is.
Explain what you where doing when the output was generated.

With all of the above, perhaps someone can help you
8  Using Arduino / Programming Questions / Re: Calling Functions NOT working as expected... on: March 15, 2011, 11:55:58 am
I dont see anything wrong with your code...

try replacing loop() with

Code:
void loop()
{
int i ;

  for (i=2; i<=5; i++)
  {
    digitialWrite(i, HIGH) ;
    delay(1000) ;
    digitalWrite(i, LOW) ;
  }

  for (i=10; i<=13; i++)
  {
    digitialWrite(i, HIGH) ;
    delay(1000) ;
    digitalWrite(i, LOW) ;
  }
}
This treats all the pins alike.
Any differences in behaviour is then down to wiring.
9  Using Arduino / Programming Questions / Re: Timer2 problem on: March 14, 2011, 04:00:50 pm
So 26 uSec is 416 clocks.

You could write your own interrupt handler that does not block further interrupts..

http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html

See the section that talks about this.
Code:
ISR(XXX_vect, ISR_NOBLOCK)

Then the additonal latency that the timer interrupt could add would be the 5 clocks to set up the interupt, one more for the SEI, and one or two more more for the instruction after the SEI (which is always executed before the interrupt is taken).

That seems quite small to me, relative to the 416 clocks that 26 uSec accuracy represents.

Hope this helps - have fun


10  Using Arduino / Programming Questions / Re: Telegraph Project from Quick-start Guide runs incorrectly on: March 13, 2011, 01:38:28 pm
Thanks for the explanations..
11  Using Arduino / Programming Questions / Re: Telegraph Project from Quick-start Guide runs incorrectly on: March 13, 2011, 11:22:18 am

Even a pin set to INPUT can drive a LED a little, as the digitalWrite(pin, HIGH) enables the pull up resistor on the pin (20 - 50 k ohms); so the LED will see between 0.25 to 0.1 milliAmps of current. Enough to light-up a small LED.

However... it will be quite dim.
12  Using Arduino / Programming Questions / Re: Trouble with simple code, i think on: March 13, 2011, 10:59:38 am
you need a global variable to hold the users target value.
like
Code:
int tempUpPin = 5;
then it will hold its value between calls of loop().
13  Using Arduino / Programming Questions / Re: unexpected result with millis on: March 13, 2011, 10:32:42 am
The maximum current the ATMEGA2560 can use is is 200 milliAmp, so even though the per output current limit is 40 milliAmps, in your case where there could be most of the 40 pins active at once, you should be drawing 5 milliAmps (or less) per pin.

Also - in the code i posted earlier there are errors -- I will fix them in place and leave the bad code as comments so you can see clearly the mistakes.



14  Using Arduino / Programming Questions / Re: sketching to read 3 dof IMU combo board on: March 13, 2011, 07:28:58 am
To insert code into the post use the # button (3rd last bottom row).
15  Using Arduino / Programming Questions / Re: sketching to read 3 dof IMU combo board on: March 13, 2011, 07:26:41 am
That thread refers to a different sensor board
http://www.sparkfun.com/products/9268

Code:
#define   GYR_Z                 2                              // Gyro Z (IMU pin #7)
#define   ACC_X                 0                              // Acc  X (IMU pin #1)
#define   ACC_Y                 1                              // Acc  Y (IMU pin #2)

These IMU pin numbers are not correct for the board you linked to in the first post http://www.sparkfun.com/products/9249.

Nothing much can be said with out correct understanding of how the arduino is linked to the sensors.

Pages: [1] 2 3 ... 8