arduino keeps restarting: debugging pointer error?

I am using the Arduino Duemilanova with an LCD shield and an Ethernet shield. I first programmed it to only use the LCD, which worked. I then added the Ethernet functionality (or I should say: Webduino functionality) and then the Arduino started to keep restarting. I can resolve this by altering a line that is in itself correct and has worked before enabling the Ethernet functionality. After rewriting a bit the unit restarts at a later point in time.

I fear that either I or some library (but I'd bet on the first option) make some pointer error. The current behaviour ("doing something one cannot understand based on the code-fragment where it happens") does bring some memories from earlier C programming. However: what is the best approach to resolve this? Altering the code makes the error disappear or at least change, so adding Serial.print does not seem to be the best option. On the other hand: there obviously is not much output from the Arduino itself. I have not found debug-environments, but perhaps I am not looking in the right places. And the only "emulator" is the VSPDE solution that seems not to support shields and is in itself influencing the error.

Any help appreciated (if you can understand my brabble).

F

It sounds like an out of memory problem.

Which processor is on your Duemilanove? When you build your Sketch, what is the reported size? (The line should look something like "Binary sketch size: 1428 bytes (of a 30720 byte maximum)")

If your Sketch is running out of SRAM, this may be helpful... http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720/19#19

Interesting thought... will check out the tips from the thread you mention

The sketch is 12532 bytes and this is a 328. Now I have included the MemoryFree library as per the link you included. Not only does this make the Serial report 975 bytes over and over again, but it also "solves" the problem. No restart, no gibberish, it simply works. My fear for a pointer error returns...

12532 bytes used versus 32768 available. 975 used versus 2048 available. I think you're OK for memory. :)

Are you using malloc or new? Are you using the String library?

My fear for a pointer error returns...

Unfortunately, if the problem isn't out-of-memory related, that's probably the next most likely culprit.

what is the best approach to resolve this?

One possibility is to post the code here. I suspect some kind soul would give it a perusal.

Does your program make use of interrupts?

12532 bytes used versus 32768 available. 975 used versus 2048 available. I think you’re OK for memory.

Thought so too… As I wrote above: after adding the freeMemory function and using Serial for 1 output only the board is running like a dream.

Are you using malloc or new? Are you using the String library? Does your program make use of interrupts?

Nope. I use some multi-arrays for integers (initiated once with {} value), use the Webduino, LiquidCrystal and Ethernet library and that’s it as far as I can see. I have been playing around with inheriting from the LiquidCrystal object, but had no problems with that before joining the functionality.

what is the best approach to resolve this?

One possibility is to post the code here. I suspect some kind soul would give it a perusal.

Dropping the complete code on anyone here is too much to ask. And don’t forget that the restarting takes place before it even makes it to the loop() function. So narrowing down, I am still bothered by that inheritance thing. This is the code I tried to use:

#define KEY_RIGHT  1
#define KEY_UP     2
#define KEY_DOWN   3
#define KEY_LEFT   4
#define KEY_SELECT 5
class MyLiquidCrystal: public LiquidCrystal
{
  public:
    MyLiquidCrystal():LiquidCrystal(8,9,4,5,6,7) {}
    void printAt(uint8_t, uint8_t, const char*);
    void printAt(uint8_t, uint8_t, int);
    byte getKey();
};

byte MyLiquidCrystal::getKey() {
  const int adc_key_val[5] ={30, 150, 360, 535, 760 };
  int i=analogRead(0); for (int k = 0; k < 5; k++) if (i < adc_key_val[k]) return k+1;
  return 0;
}

void MyLiquidCrystal::printAt(uint8_t c, uint8_t r, int i)         { setCursor(c,r); this->print(i); }
void MyLiquidCrystal::printAt(uint8_t c, uint8_t r, const char *s) { setCursor(c,r); this->print(s); }

The idea is to extend the LiquidCrystal object (it’s MyLiquidCrystal so I don’t have a flexible constructor) with the function getKey (I have an LCD with keypad connected to A0) and printAt. The latter should print something at a given column, row. I only need to print either integers or strings, so made only those two. But it does not seem to work that good… Am I doing something wrong here?

Am I doing something wrong here?

Looks good to me.

Dropping the complete code on anyone here is too much to ask. And don't forget that the restarting takes place before it even makes it to the loop() function.

Well if we can't get you to punish us with everything, then post everything up to the point (or thereabouts) that it fails.

Am I doing something wrong here?

Looks good to me.

I'd say that, but it does not work. Whenever I call lcd.printAt(0,1,"text") the display shows some random digits in stead of 'text'.

Still investigating, but after adding the reference to Serial the problem went away (perhaps the program is now poking in the Serial receive buffer). I'll get back here with more code if it continues to bug me. Thanks for your help until now.