Offline
Newbie
Karma: 0
Posts: 5
|
 |
« on: May 02, 2012, 02:51:35 pm » |
Hello,
I am new to programming an Arduino (Mega 2560). I am on a project that manipulates a file.txt on SD card. After the execution of a function that searches a number in the file my arduino reset. I don't see why. Have you any idea what can cause this reset?
thank
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 242
Posts: 16485
Available for Design & Build services
|
 |
« Reply #1 on: May 02, 2012, 02:55:03 pm » |
Ooh, that's a good one.
Have any code we can look at? Does any file manipulation cause that to happen?
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #2 on: May 02, 2012, 03:12:13 pm » |
After the execution of a function that searches a number in the file my arduino reset.
Just taking a shot in the dark here, since there's no code to look at, but I'd guess you're reading a large amount of data into SRAM, running out of SRAM, and overwriting the stack. This is a very common cause of Arduino resets.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #3 on: May 03, 2012, 05:42:34 am » |
Have you any idea what can cause this reset?
No, sorry. Read this before posting a programming question
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #4 on: May 07, 2012, 02:18:33 am » |
Here is the function that creates me this problem: int rechercheUtilisateur(char numUtilisateur[TAILLE_NUM_UTI]){ int i, ligne = 1; //declaration des tableaux locaux char numString[TAILLE_NUM_UTI];
//place le pointeur au debut du fichier myFile.seek(0); //retrieve the ID number of the line for(i=0; i<TAILLE_NUM_UTI-1; i++) numString=myFile.read(); numString='\0';
while(strcmp(numUtilisateur, numString)){ if(!sautDeLigne()){ //move to the next line myFile.seek(0); return 0; } ligne++; //retrieve the ID number of the line for(i=0; i<TAILLE_NUM_UTI-1; i++){ numString=myFile.read(); } numString='\0'; } //place le pointeur au debut de la ligne myFile.seek(myFile.position()-TAILLE_NUM_UTI); return ligne; }
It looks in a text file by a user's ID number. sample text file: 10000001 Marson Julien 7654 31678 11/05/2012 enseignant physique 03/04/2012 Fabre oui non 10000002 Zygmaniak Ghislain 55 21234 10/05/2012 etudiant physique 02/04/2012 Fabre oui non 63802020 Verron Maxime 234 22222 12/05/2012 etudiant mathématique 04/04/2012 Fabre non oui 63802021 Dumont Tony 34 22 12/04/2012 etudiant mathématique 04/04/2012 Fabre oui non After the execution of a function that searches a number in the file my arduino reset.
Just taking a shot in the dark here, since there's no code to look at, but I'd guess you're reading a large amount of data into SRAM, running out of SRAM, and overwriting the stack. This is a very common cause of Arduino resets. I think I do not use any memory: Binary sketch size: 17932 bytes (of a 258048 byte maximum) Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 272
Posts: 25464
Solder is electric glue
|
 |
« Reply #5 on: May 07, 2012, 02:24:31 am » |
I think I do not use any memory: Yes you do, every variable and print string takes up memory. Why did you not use the code tags like it said in the link Nick pointed you to?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13896
Lua rocks!
|
 |
« Reply #6 on: May 07, 2012, 02:37:30 am » |
Please edit your post, select the code, and put it between [code] ... [/code] tags.
You can do that by hitting the # button above the posting area.
What does TAILLE_NUM_UTI look like? The declaration?
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #7 on: May 07, 2012, 09:41:25 am » |
char numString[TAILLE_NUM_UTI];
numString=myFile.read(); numString='\0';
numString being an array of chars, the above two are, let's say, inappropriate attempts at assignment.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #8 on: May 07, 2012, 09:50:49 am » |
numString being an array of chars, the above two are, let's say, inappropriate attempts at assignment. Perhaps you noticed the switch to italics midway through the (poorly posted) code? The assignment is valid, and would be properly apparent if the code was posted properly.
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #9 on: May 07, 2012, 10:26:58 am » |
numString being an array of chars, the above two are, let's say, inappropriate attempts at assignment. Perhaps you noticed the switch to italics midway through the (poorly posted) code? The assignment is valid, and would be properly apparent if the code was posted properly. You are foiling my attempted demonstration of one of the less obvious reasons why code tags are important. No worries, the point should be made anyways.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #10 on: May 07, 2012, 10:32:47 am » |
You are foiling my attempted demonstration of one of the less obvious reasons why code tags are important. Oops. Sorry about that. I think that subtlety is lost on people that can't even post code properly, though. A clue-by-four would be a better tool.
|
|
|
|
|
Logged
|
|
|
|
|
New Hampshire
Offline
God Member
Karma: 13
Posts: 776
There are 10 kinds of people, those who know binary, and those who don't.
|
 |
« Reply #11 on: May 07, 2012, 12:08:43 pm » |
A clue-by-four would be a better tool.
Haha. That's a new one to me, wasn't really sure what you meant, though what initially came to mind when I read it was 'four letter words'. After a quick google, I find I'm not all that far off the mark. I do like the two-by-four analogy more though.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #12 on: May 09, 2012, 10:30:19 am » |
Here is the function (with the right tags) that creates me this problem: int rechercheUtilisateur(char numUtilisateur[TAILLE_NUM_UTI]){ int i, ligne = 1; //declaration des tableaux locaux char numString[TAILLE_NUM_UTI];
//place le pointeur au debut du fichier myFile.seek(0); //retrieve the ID number of the line for(i=0; i<TAILLE_NUM_UTI-1; i++) numString=myFile.read(); numString='\0';
while(strcmp(numUtilisateur, numString)){ if(!sautDeLigne()){ //move to the next line myFile.seek(0); return 0; } ligne++; //retrieve the ID number of the line for(i=0; i<TAILLE_NUM_UTI-1; i++){ numString=myFile.read(); } numString='\0'; } //place le pointeur au debut de la ligne myFile.seek(myFile.position()-TAILLE_NUM_UTI); return ligne; } It looks in a text file by a user's ID number. Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #13 on: May 09, 2012, 10:40:02 am » |
int rechercheUtilisateur(char numUtilisateur[TAILLE_NUM_UTI]){ You STILL have not told us how TAILLE_NUM_UTI is defined or what its value is. Now, where did I put that clue-by-four?
|
|
|
|
|
Logged
|
|
|
|
|
Pennsylvania, USA
Offline
Newbie
Karma: 0
Posts: 29
|
 |
« Reply #14 on: May 09, 2012, 11:58:52 am » |
Take a closer look at this section of your code: char numString[TAILLE_NUM_UTI];
//place le pointeur au debut du fichier myFile.seek(0); //retrieve the ID number of the line for(i=0; i<TAILLE_NUM_UTI-1; i++) numString=myFile.read(); numString='\0';
Specifically: char numString[TAILLE_NUM_UTI]; for(i=0; i<TAILLE_NUM_UTI-1; i++) numString=myFile.read(); numString='\0';
Last I checked, read() doesn't return a pointer, it returns a single byte. That shouldn't even compile...
|
|
|
|
|
Logged
|
|
|
|
|
|