Arduino won't boot

Hi,

I’ve asked this before but never got a clear answer. Yesterday we had the issue but higher severity. When power is turned on the arduino would run the setup loop but wouldn’t continue to the rest of the sketch. Its a very abnormal problem but we tried turning off and the power back on a few times. After that I plugged my laptop in to find out it DID run the setup function cause it responded a serial message but never ran the main loop. Before it’s fixed itself by restarting it a couple of times but this time I had to reprogram the arduino (with the same sketch mind you) to get it to boot fully.

Again with simpler explanation:
Arduino would boot and give the message: “Starting…” in the serial monitor but nothing after that. should the EEPROM read loop be delayed more then 10ms?

Sketch attached.

AssemblyAutoBoard.ino (23.7 KB)

    int gtemp = gtemp = EEPROM.read(f);

WTF?

You are pissing away memory all over the place. The EEPROM.read() function does not return an int. Storing the byte that it returns in an int wastes memory.

You don't have more than 256 pins on your Arduino, so all variables holding pin numbers should be byte, not int.

A pin can not be in more than 256 states, so all variables hold pin states should be byte, not int.

Use the F() macro to stop copying literals into SRAM unnecessarily.
Serial.println(F("********** System Variables ***********"));

Your code does not have any voids in it. When you come to the end of something, that something is a function, not a damned void.

Your code seriously needs commenting. The only comments in it are useless.

WHY does the code do what it does? THAT is what you need to document with comments. The fact that a } represents the end of an if statement or a function is obvious.

Blade2021:
Arduino would boot and give the message: “Starting…” in the serial monitor but nothing after that.

Do you literally mean that line 135 works and line 136 does not?

If that is not what you mean please explain in detail.

If this was my problem I would try disabling parts of the program to figure out what is causing the problem. My wild guess is that something is corrupting your memory - for example writing past the end of an array.

You have a very extensive program - when, during its development, did this problem surface? Can you go back to the version that worked immediately before the problem arose and see what subsequent changes were made that might have caused the problem?

…R

There are a lot of warnings produced by your program, at least some of them are errors.

Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'void setup()':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:149:38: warning: operation on 'gtemp' may be undefined [-Wsequence-point]
     int gtemp = gtemp = EEPROM.read(f);
                                      ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'void loop()':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:471:15: warning: statement has no effect [-Wunused-value]
         bxyz[j];
               ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'void inactive(int)':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:527:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (y[6] == passcode) {
            ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'void savetrigger(int)':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:582:30: warning: operation on 'ytemp' may be undefined [-Wsequence-point]
   int ytemp = ytemp = y[x] / 10;
                              ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:587:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (address == EEPROM.length()) {
                 ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:593:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (address == EEPROM.length()) {
                 ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:601:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (address == EEPROM.length()) {
                 ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:607:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (address == EEPROM.length()) {
                 ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'void changetime(int)':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:744:13: warning: statement has no effect [-Wunused-value]
     arraya[j];
             ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:776:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (address == EEPROM.length()) {
                     ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:781:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (address == EEPROM.length()) {
                     ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:798:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (address == EEPROM.length()) {
                     ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:803:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (address == EEPROM.length()) {
                     ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'loop':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:180:29: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
         StateArray[indx] = 0;
                             ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:179:7: note: containing loop
       for (int indx = 0; indx < 7; indx++) {
       ^

The most critical error (array overwrite):

Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino: In function 'loop':
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:180:29: warning: iteration 6 invokes undefined behavior [-Waggressive-loop-optimizations]
         StateArray[indx] = 0;
                             ^
Somewhere\AssemblyAutoBoard\AssemblyAutoBoard.ino:179:7: note: containing loop
       for (int indx = 0; indx < 7; indx++) {
       ^

PaulS:

    int gtemp = gtemp = EEPROM.read(f);

This was a Find/Replace error. I never noticed it but it is fixed now.
it should be:

int gtemp = EEPROM.read(f)

PaulS:
You are pissing away memory all over the place. The EEPROM.read() function does not return an int. Storing the byte that it returns in an int wastes memory.

You don't have more than 256 pins on your Arduino, so all variables holding pin numbers should be byte, not int.

A pin can not be in more than 256 states, so all variables hold pin states should be byte, not int.

I've thought of this but never actually seen it done so I thought there was a specific reason more people don't do this. I've updated my code to reflect your reply. BUT! I know you mentioned the one also should be byte. This one must be an int due to the final value after it reads the memory.

PaulS:
Use the F() macro to stop copying literals into SRAM unnecessarily.
Serial.println(F("********** System Variables ***********"));

Never heard of this but included it.

PaulS:
Your code seriously needs commenting. The only comments in it are useless.

WHY does the code do what it does? THAT is what you need to document with comments. The fact that a } represents the end of an if statement or a function is obvious.

Agreed but its not done. I'll try to add more comments for future reference.

Robin2:
Do you literally mean that line 135 works and line 136 does not?

If that is not what you mean please explain in detail.

If this was my problem I would try disabling parts of the program to figure out what is causing the problem. My wild guess is that something is corrupting your memory - for example writing past the end of an array.

You have a very extensive program - when, during its development, did this problem surface? Can you go back to the version that worked immediately before the problem arose and see what subsequent changes were made that might have caused the problem?

...R

Actually yes. According the Serial monitor when it happened yesterday it did run line 135 saying the sketch was "starting". But did not send anything after.

It is a very "random" issue that is not consistent enough to debug by disabling parts of it to my knowledge. Thus the reasoning by my post. I was looking for anything that I might have missed which I did not notice a couple of things that were pointed out by everyone.

Whandall:
@Whandalls post

I have fixed the StateArray indx issue.

EEPROM.write(address, x);
if (x == EEPROM.length()) .. do something

This is how it is "shown" in the EEPROM reference. So its odd that its throwing an error. Am I missing something?

Blade2021:
This is how it is "shown" in the EEPROM reference. So its odd that its throwing an error.

That example will also throw warnings, that's in a way, odd.
It is the type of warnings you could safely ignore, but I would fix them anyway.

From EEPROM.h

    uint16_t length()                    { return E2END + 1; }

Make the address unsigned int and the warnings will go away

Blade2021:
It is a very "random" issue that is not consistent enough to debug by disabling parts of it to my knowledge.

Presumably you had an earlier simpler version of the program where this problem did not arise?

...R