Arduino is resetting..

Hi,

Im doing a project of wireless dictionary.It uses 5 arduino modules at which in each module we can select a letter.1st module will transmit its letter to 2nd,2nd module wll transmit its and the previous modules letter to 2nd and so on.. In the last module we have a 5letter word inwhich we are comparing its with a built n dictionary.If the word is there present in the dictionary then the display will show an indication.
My problem is that 5th module will get reset after some time. i think the code is working fine because its recognising valid words and shows me an indication. But its resetting after some time.

Is there because of power shortage because im using the power from arduino board to drive a 8*8 dot matrix display,2 IR transmitters,IR receivers.

Any idea???

But its resetting after some time.

Could be a memory problem, but without much more detail, it isn't sensible to speculate further.

I had the same sorta problem...and just maybe I could help if you posted your code

I think about a problem of memory addressing after a while.

Your program tempts to read or write in memory location that means nothing.

The best to trag the bug is to post your source code !

Im attatching my code below. Please tell me what went wrong.

changedModule5.pde (16.9 KB)

byte letter[26][8][8]= 1664 bytes

char *wordd= another 350 bytes.

Suggest you either put these all into progmem, or bit-pack the letter array.

find it !

You are declaring i as a global variable.

And your are using it (i) in several functions !!!!

So value of i change every time.

You must use local variable each time you are using loop variable in each function. So that it stays local !!!

Example :

void alphadisplay4017()
{
int i, j;
....

}

byte dictionary()
{
int i;

....
}

And if you find yourself running short of program memory:

char convtochar(byte bt)
{
  char character;
  if(bt==0){character='A';}
  else if(bt==1){character='B';}
  else if(bt==2){character='C';}
  else if(bt==3){character='D';}
  else if(bt==4){character='E';}
  else if(bt==5){character='F';}
  else if(bt==6){character='G';}
  else if(bt==7){character='H';}
  else if(bt==8){character='I';}
  else if(bt==9){character='J';}
  else if(bt==10){character='K';}
  else if(bt==11){character='L';}
  else if(bt==12){character='M';}
  else if(bt==13){character='N';}
  else if(bt==14){character='O';}
  else if(bt==15){character='P';}
  else if(bt==16){character='Q';}
  else if(bt==17){character='R';}
  else if(bt==18){character='S';}
  else if(bt==19){character='T';}
  else if(bt==20){character='U';}
  else if(bt==21){character='V';}
  else if(bt==22){character='W';}
  else if(bt==23){character='X';}
  else if(bt==24){character='Y';}
  else if(bt==25){character='Z';}
  return(character);
  
 
}

try

char convtochar(byte bt)
{
  return (bt >= 0 && bt < 26) ? bt + 'A' : 0;
}

find it !

You are declaring i as a global variable.

And your are using it (i) in several functions !!!!

Yes, I would recommend using a local "i", but I don't think it is the problem here, because I don't see any of the offending functions being nested.

Some improvments you can also do :

receiveddata[0]='1';
receiveddata[1]='A';
receiveddata[2]='A';
receiveddata[3]='A';
receiveddata[4]='A';
receiveddata[5]='A';
receiveddata[6]='\0';

can be replaced by :

#include <stdio.h>
#include <string.h>

strcpy(receiveddata,"1AAAAA"); // strcpy add itself the '\0' !

other thing :

char convtochar(byte bt)
{
char character;

ch = 'A'+bt;

if(bt==0){character='A';}
else if(bt==1){character='B';}
else if(bt==2){character='C';}
else if(bt==3){character='D';}
else if(bt==4){character='E';}
else if(bt==5){character='F';}
else if(bt==6){character='G';}
else if(bt==7){character='H';}
else if(bt==8){character='I';}
else if(bt==9){character='J';}
else if(bt==10){character='K';}
else if(bt==11){character='L';}
else if(bt==12){character='M';}
else if(bt==13){character='N';}
else if(bt==14){character='O';}
else if(bt==15){character='P';}
else if(bt==16){character='Q';}
else if(bt==17){character='R';}
else if(bt==18){character='S';}
else if(bt==19){character='T';}
else if(bt==20){character='U';}
else if(bt==21){character='V';}
else if(bt==22){character='W';}
else if(bt==23){character='X';}
else if(bt==24){character='Y';}
else if(bt==25){character='Z';}
return(character);
}

can bé replaced by :

char convtochar(byte bt)
{
if (bt>=0 && bt<=25)
{
return ('A'+bt); // Add bt to letter 'A' so from if bt=5 'A'+5 = 'E' !!!
}
else
return 0;
}

and at last !

byte convtobyte(char charlength)
{
byte num;
if(charlength=='1'){num=1;}
else if(charlength=='2'){num=2;}
else if(charlength=='3'){num=3;}
else if(charlength=='4'){num=4;}
else if(charlength=='5'){num=5;}
else if(charlength=='6'){num=6;}
else if(charlength=='7'){num=7;}

return(num);
}

can be replaced by :

byte convtobyte(char charlength)
{
byte num;

num = charlenght-'0'; // '0' is ascii code of 48 if charlength = '7' (wich is ascii 55) then charlength-'0' means 55-48 = 7 !!!

return num;
}

can be replaced by :

#include <stdio.h>
#include <string.h>

strcpy(receiveddata,"1AAAAA"); // strcpy add itself the '\0' !

Or even more simply (and without header files you don't need)

char receiveddata[8] = "1AAAAA"; // unused elements padded with zero

Another thing that can be a bug...

in loop :

length=convtobyte(temp);
temp=Serial.read();

the first line is used with a temp variable that never been initialized. So from at the first call temp can be any of a value... let's say 128 because in the convtobyte function you dont also initialize num variable, and even if you digit is segment out of 1-7 segment, num will return an unitialised value !

so from when you reach

lengthreference=length;
templength=1;
while(templength<=lengthreference)
{
temp=Serial.read();
if(temp>='A'&&temp<='Z')
{
receiveddata[templength]=temp;
templength++;
Serial.println(temp);
changedata=1;
}....

receivedata will be overflow and cause crash of your arduino.

So you mmsut init length or swap the 2 lines above !

and int convtobyte function :

byte convtobyte(char ...)
{
byte num=0;

...
...

@grag38

the first line is used with a temp variable that never been initialized. So from at the first call temp can be any of a value... let's say 128...

Let us not say 128, let us say zero, when it was initialised here:

char receiveddata[8],moduledata,temp; // << All set to zero

I think also that after 80-odd posts, it isn't unreasonable to expect you to post code in proper code boxes.

I agree that the code could do with some tidying and rationalisation, but pointing out non-existent "bugs" is unhelpful.

what is meant by bit packing the array?

I think the problem is with declaration char *wordd[] because after commenting that its working fine.
Whats behind this problem.Its not showing any error when compiling.Is there any runtime error?

I'm sorry but until a variable is initialized with a value, you know nothing about it !!!

I'm sorry too, but you're wrong.

All variables with global or static scope are initialised to zero (unless another value is specified) before "main" runs.

what is meant by bit packing the array?

You currently have 1664 bytes of RAM, holding 26 * 8 = 208 bytes worth of data.
Instead of

{{{1,1,1,1,1,1,1,1},
                        {1,0,0,0,0,0,0,1},
                        {1,1,1,0,1,1,0,1},
                        {1,1,1,0,1,1,0,1},
                        {1,1,1,0,1,1,0,1},
                        {1,1,1,0,1,1,0,1},
                        {1,0,0,0,0,0,0,1},
                        {1,1,1,1,1,1,1,1}},

you could encode the values as:

0xff, 0x81, 0xED, 0xED

and so on.
This save 1456 bytes of RAM, for a trivial amount of extra code.

I'm sorry but every time we write :

int a, b, c, d;

you never know what is the values of a, b, c, d because the compiler does not assign 0 tho these values

No need to apologise, just read what I wrote about global and static variables.
The argument does not apply to automatic variables, but "temp" was not defined as an automatic.

Sorry missed this bit:

I think the problem is with declaration char *wordd[] because after commenting that its working fine.
Whats behind this problem.Its not showing any error when compiling.Is there any runtime error?

Think of it as the straw that broke the camel's back.
With the 1664 bytes of letter table plus 350 bytes of dictionary, plus the hidden serial buffer plus stack, plus variables, you're well over 2K of RAM.
Those strings all use up RAM, which is why I suggested putting them into PROGMEM.
The compiler can't check RAM usage, so no compile-time error.

It seems to me you may also be wasting a little bit of RAM putting the string length into it, when you could calculate this on-the-fly.

byte dictionary()
{
for(i=1;i<50;i++)
{
if((strcmp(receiveddata,wordd*))==0)*

  • {*

  • return 1;*

  • break;*

  • }*

  • }*

  • return 0;*
    }[/quote]
    Now the restting problem is solved.But now the problem is string compare is not working.i.e if i got the received data as "5APPLE" which is inthe wordd[],its not recognised.

Now the restting problem is solved

How did you solve the problem?

Did you put the dictionary in PROGMEM?
strcmp won't work with strings in PROGMEM, you need to use (IIRC) strcmp_p