Arduino Nano 328 Resets when used without serial monitor

Hi,

I have several Nano's 328 but when i run my code without opening the serial monitor the arduino crashes and restarts the program.
When i open the serial monitor to check if i could find the reason the code works properly.
i let one of them run for a day without crashing. closed the serial monitor and atleast every minute it will reboots.

i hope someone has any idea because i'm lost.

Kind regards

Johan

Please post a sample program that exhibits this behaviour and details of any external inputs or outputs to the Arduino.

I copied a slight piece of the code. because we have a lot of animations but then it will be to long.
we also use normaly progmem instead of normal mem
but because we had this issue from the start i don't think its an issue with something like that.
i expect a timings issue but i wont understand where and why.

Output with serial monitor is
Start Setup
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop

int DataPin = 11; //shift input
int LatchPin = 10; //rstclk on shift
int ClockPin = 13; //srclk on shift
int clock = 9; //decade clk
int Reset = 8; //reset
int x;  //used in the for loop counter
int y;  //used in the for loop counter

unsigned char light [][8][3] = {
{{63,255,252},{127,255,254},{255,255,255},{255,231,255},{255,231,255},{127,195,254},{127,129,254},{30,0,120}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}};					

unsigned char vis [][8][3] = { 
{{8,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{0,0,0},{0,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{0,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{0,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{255,255,255}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{255,255,255},{255,255,255}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{8,0,0},{255,255,255},{255,255,255},{255,255,255}},
{{8,0,0},{8,0,0},{8,0,0},{8,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{8,0,0},{8,0,0},{8,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{8,0,0},{8,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{8,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{255,255,255},{127,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{71,255,255},{3,255,255},{71,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{163,255,255},{129,255,255},{163,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{209,255,255},{192,255,255},{209,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{209,255,255},{192,255,255},{209,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{232,255,255},{224,127,255},{232,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{244,127,255},{240,63,255},{244,127,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{250,63,255},{248,31,255},{250,63,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{253,31,255},{252,15,255},{253,31,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{254,143,255},{254,7,255},{254,143,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,71,255},{255,3,255},{255,71,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,163,255},{255,129,255},{255,163,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,209,255},{255,192,255},{255,209,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,232,255},{255,224,127},{255,232,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,244,127},{255,240,63},{255,244,127},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,250,63},{255,248,31},{255,250,63},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{255,253,31},{255,252,15},{255,253,31},{255,255,255},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{255,255,255},{255,254,143},{255,254,7},{255,254,143},{255,255,255},{255,255,255}},
{{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,71},{255,255,3},{255,255,71},{255,255,255}},
{{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,163},{255,255,129},{255,255,163}},
{{255,255,253},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,209},{255,255,192}},
{{127,255,252},{255,255,254},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,232}},
{{127,255,252},{255,255,254},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,248}},
{{0,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{0,0,0},{0,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{0,0,0},{0,0,0},{0,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{255,255,255},{255,255,255},{255,255,255},{255,255,255}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{255,255,255},{255,255,255},{255,255,255}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{255,255,255},{255,255,255}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{255,255,255}},
{{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}};
										
 
//e.g unsigned char your_new_animation [][8][3] = {

//You can only have a limited amount of frames even if they are in different animations.
//If you have to many frames, the code won't start on the arduino, so you will have to reduce the amount of them.
//An animation can be played an unlimited amount of times but it can only hold so much data. 


void setup(){
Serial.begin(115200);
Serial.println("Start Setup");
  pinMode(DataPin,OUTPUT);   //Basic setup of pins etc
  pinMode(ClockPin,OUTPUT);
  pinMode(LatchPin,OUTPUT);
  pinMode(clock,OUTPUT);
  pinMode(Reset,OUTPUT);
  digitalWrite(Reset,HIGH); //Reseting the decade to 0 as it can be at a random stage on start up 
  delayMicroseconds(5);
  digitalWrite(Reset,LOW);
}

void run_animation(unsigned char frame_time,unsigned char frames[][8][3],unsigned char num_frames,unsigned char num_loops){  //My function called run_animation
 
 for(int i=0;i<num_loops;i++){      //The display algorithm shifts out the 3 numbers in the array to display row 1 and then drops down a line....
  for(x=0;x<num_frames;x++){        //and continues to output the data for that line. It drops down through each of the 8 rows then resets. It then does the next frame.
   for(int z=0;z<frame_time;z++){
    for(y=0;y<8;y++){
     digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,LSBFIRST,frames[x][y][2]);   
     shiftOut(DataPin, ClockPin,LSBFIRST,frames[x][y][1]);
     shiftOut(DataPin, ClockPin,LSBFIRST,frames[x][y][0]);
     digitalWrite(LatchPin, 1);
     delayMicroseconds(700);
     digitalWrite(LatchPin, 0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
     shiftOut(DataPin, ClockPin,MSBFIRST,0);
     digitalWrite(LatchPin, 1);
     digitalWrite(clock, 1);
     digitalWrite(clock, 0);      
    }
    digitalWrite(Reset, 1);
    digitalWrite(Reset, 0); 
  }
}
}
}

void loop(){
Serial.println("Start Loop");
//Fill in this to call each of your animations:  run_animation(frame time, animation title, number of frames in the animation, number of loops);

//e.g. run_animation(8,your_new_animation,11,12);

run_animation(4,vis,47,2);
run_animation(4,light,2,200);

}

Does the code you posted exhibit these symptoms?

yes. even with one animation we have this problem
because i use several tabs normaly i get the initial code

unsigned char vis [][8][3] = {

You've done such a crappy job of formatting your code that I can't tell how big this array really is. But, it looks pretty large. How big is it really?

How much free memory do you have?

I tested your code and got:

Start Setup
Start Loop

this is the sample. so i didn't create it only use it.
but because the reset wont happens when the serial port monitor is open i want to know what can be the reason

Kind regards

Johan

Nick,
but you get it from the serial port. when i run the program i see the arduino resets. random.
sometimes during the first animation sometimes during the seconde and somethings after 5 or 6 loops. but never longer than 2 minuten.

Kind regards

Johan

But you indicated it was resetting with the serial monitor open:

jl-p:
Output with serial monitor is
Start Setup
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop
Start Loop

Me too.

O sorry its the other way around.
When i open the serial monitor it works perfect.
But when i only connect it to my laptop and wont open the serial monitor he keeps restarting.
Randomly. Sometime within second sometimes a little longer. But always within 2 minuten

How do you know it's restarting? I'm looking at a Nano here with your sketch running and with the serial monitor closed there's no sign it's doing anything.

Also, when I run it here with the serial monitor open I only get "Start Loop" once. Is that different to what you get?

OK then, I uploaded the above sketch, did not open a serial monitor, and monitored the pins with the logic analyzer. This is what I saw after about 8 minutes:

I assume that's working.

I have no idea why. But when i connect the arduino with the battery pack the issue disapears.
So it works. I will check later if i can reproduce it. And test also with a scope.

Thanks for testing.

Johan

jl-p:
I have no idea why. But when i connect the arduino with the battery pack the issue disapears.
So it works. I will check later if i can reproduce it. And test also with a scope.

So it doesn't reset when used without the serial monitor?

I think something on your computer is probing the USB ports - when the serial monitor is open it has
exclusive access to that USB port and prevents the rogue process from probing it.

My suspicion is that this is an OS issue, not an Arduino one. That would mean that all Arduino sketches
would be misbehaving this way though, which seems rather unlikely.

Just a thought.

MarkT:
I think something on your computer is probing the USB ports - when the serial monitor is open it has
exclusive access to that USB port and prevents the rogue process from probing it.

Good thinking. Some applications for managing mobile phones and so on do this sort of thing.