Pages: [1]   Go Down
Author Topic: Arduino Keeps Restarting within Setup()  (Read 747 times)
0 Members and 1 Guest are viewing this topic.
Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've been learning various functions here and I've gotten them to work in individual sketches for individual functions:

I learned how to connect my EthernetShield and my EthernetPOE to the network with a fixed IP address and connect to the Internet. I learned how to do the same with my WiFi shield but with DHCP as Fixed IP doesn't work on the WiFi shield (a separate matter). I created an individual sketch for each of these functions (3 sketches) and they worked fine.

I learned how to access the SD card, create and write to files on the SD card, set the datetime stamps (created, modified & accessed) on the files with set values, read the files' sizes and read the amount of free space on the SD card. I put all of this in to one sketch and it worked fine.

I learned how to get the time from a fixed NTP server, adjust it for a given time zone (mine), store it in a time variable and display the various time elements properly formatted. I put all of this in to one sketch and it worked fine.

Then I got ambitious ... and it seems to have fallen apart.

I put all of these functions in to one big sketch as it is part of a long-term goal for an actually functional project... It compiles fine although it is much bigger than I thought it would be at this stage (25,516 byte). But I certainly haven't even started optimising any of it... I'm just trying to get it to run.

When it runs it gets to the part where it sets the IP address on the card and display the address info. As it displays the DNS it only displays the first digit of the address, then one random character and ... the whole sketch starts up again ... and again ... and again ...

[The code's too big to put in this message I'm going to try putting it in a separate message]
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
[The code's too big to put in this message I'm going to try putting it in a separate message]
Chances are you're running out of RAM.
You can attach your code rather than posting it.

(Give my regards to rue Maurice Bokanowski)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 651
Posts: 50845
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
[The code's too big to put in this message I'm going to try putting it in a separate message]
Don't do that. Look below this box. See the Additional options link? One of them allows you to attach a file.
Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I couldn't get the code to fit in one message here. So I am trying to upload it Github...

Here it is:

https://gist.github.com/4525631

As it restarts within Setup() and every function appears to execute fine without returning any errors I don't even know where to start debugging this thing...

Help?
Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm also including my code as an attached file here...

* EthernetShield_FixedIP_NTP_SDTimestamp1.ino (11.55 KB - downloaded 5 times.)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lots of constant strings.
Ever thought of using the F() macro?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 651
Posts: 50845
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Arduino are you running this on? The 328-based Arduinos have 2K of SRAM. The SD library needs 1/4 of that for the buffer to read from/write to the SD card.

You have a LOT of literal text strings that are being copied from program memory to SRAM at run time. You can use the F() macro to stop that from happening:
Serial.println(F("DEFAULT.TXT created with default date/time stamps:"));

Logged

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Which Arduino are you running this on? The 328-based Arduinos have 2K of SRAM. The SD library needs 1/4 of that for the buffer to read from/write to the SD card.

I should have said that up front. This is running on the Arduino Uno with the Ethernet Shield.

I also will be testing it on an ArduinoPOE  and then on an Arduino Uno with a WiFi Shield.

I understand the memory management problems of storing tons of literals in to SRAM at run time. I had not (yet) seen any mention of F() macros in the examples I've been reading. I will certainly try that...

Aside from the code being less elegant and hogging memory do you think that is actually part of the execution problem?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 651
Posts: 50845
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Aside from the code being less elegant and hogging memory do you think that is actually part of the execution problem?
Yes. The hogging memory part. The F() macro doesn't do much for elegance. Of course, the most elegant code is code that works, so maybe it does.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The F macro is mentioned on the Serial.print reference page.
Yes, I do think it part of your problem
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Asnieres sur Seine - France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I went through and F() macroed all of my serial.print() and serial.println() calls with constant strings.

It works!

Thank you all for your help, advice and suggestions.

New version attached...

* EthernetShield_FixedIP_NTP_SDTimestamp1.ino (11.76 KB - downloaded 8 times.)
Logged

Pages: [1]   Go Up
Jump to: