Ardunio Memory

Sayed: thanks, i just note that i am missing unsigned before long, and about the string when i change it to small letter it dose not work for me, any idea?

Use Google to learn about the difference between the String class and strings.

...R

Delta_G: No, again this is a misunderstanding of the problem with ints and longs.

Then I'll leave it to you to explain, repeatedly, to newbies why their code doesn't work, because they don't understand when they NEED to add the L and when they don't. If they get into the habit of using it whenever they have a literal that is, or might be, too big to fit into an int, they'll have FAR fewer problems, and it costs them nothing except one more keystroke. Why not help them develop "safer" habits, that will help them avoid confusing errors, until they achieve true understanding?

Regards, Ray L.

Delta_G: string with a small letter is spelled char*.

thanks very much i just try to apply what in this tutorial about data logger, i define char* to replace the the String but i note that not allow + and converting the temperature value to the char. https://www.arduino.cc/en/Tutorial/Datalogger

and about the multiplication if

if (timenw - timepr1 >= 3600000)
  {

if both timenw and timepr1 are unsigned long will solve the problem if there value become large? thanks all, am happy to get your support

Sayed: if both timenw and timepr1 are unsigned long will solve the problem if there value become large?

I really think you need to do some studying using the many tutorials that are available online. It is not reasonable to expect people here to be unpaid teachers.

You have been given several suggestions. Now you do some work to learn more about them.

...R

Robin2: I really think you need to do some studying using the many tutorials that are available online. It is not reasonable to expect people here to be unpaid teachers.

You have been given several suggestions. Now you do some work to learn more about them.

...R

thanks very much, i just use the unsigned long, i am asking to know if will result problem, am not employee or have recourse to pay for coding, that why i think i will get help on arduino forum, maybe am wrong, am very sorry about that, thanks very much

RayLivingston: Then I'll leave it to you to explain, repeatedly, to newbies why their code doesn't work, because they don't understand when they NEED to add the L and when they don't. If they get into the habit of using it whenever they have a literal that is, or might be, too big to fit into an int, they'll have FAR fewer problems, and it costs them nothing except one more keystroke. Why not help them develop "safer" habits, that will help them avoid confusing errors, until they achieve true understanding?

Regards, Ray L.

I agree that developing good habits is to be encouraged, but stating, as @holmes4 did that this was "Wrong", and suggesting an experiment that would have left one wondering what exactly it was that was "wrong", when the experiment would have provided the result any reasonable person would have expected, is simply confusing.

Delta_G:
No, again this is a misunderstanding of the problem with ints and longs.

If one of the numbers is a long, then the math gets done with longs and you’re OK. The problem is when all of the numbers are ints. When you do the comparison with a literal value of 3600000 then the compiler knows up front that has to be a long since it is bigger than will fit into an int and it handles that without the L subscript.

For example, this code:

void setup(){

Serial.begin(9600);
  delay(20);
  Serial.println(100 * 100000);
  Serial.println(100000 * 100);
  unsigned long a = 100 * 100000;
  Serial.println(a);
  if(a < 20000000){
    Serial.println(“It’s less than”);
  } else {
    Serial.println(“Something failed”);
  }
}
 
void loop(){}




Produces this result:


10000000
10000000
10000000
It’s less than





The compiler has no problems with literal numbers larger than will fit into an int.

The problem arises when there isn't a number like that in the expression but the result or some intermediate result is. For example, this would have failed:



if(a < (20 * 1000 * 1000))




because none of those numbers is too large to fit into an int so the math is all done with ints. This is the case where you must tell the compiler to use a long for one of those variables. 



if(a < (20ul * 1000 * 1000))

thank you very much Delta_G i just understand that multiplication will carry out in integer with -32,768 to 32,767 while long from -2,147,483,648 to 2,147,483,647 and unsigned long can take 0 to 4,294,967,295
i rewrite my code based on that, and i hope it work without problem, now only what remain is the replacement of String, am trying to find how to combine two char* together with variable value,
thanks again,

Sayed: am not employee or have recourse to pay for coding,

There are dozens or hundreds of free online tutorials.

But perhaps reading them and thinking about stuff uses up more of YOUR time than getting answers from the Forum using other people's time.

...R

Robin what is wrong if some one help me? what will happen to you? is there any problem? if you didn't like to give any help to other people please don't ask other to be similar to you, sorry about that, but that what i note from your many post that repeat same thing! i didn't ask you to help me! there are many people here want to help other, and if i am asking for help that dose not mean i didn't read and go through online tutorials, some time people understand tutorial in wrong way as what happen to me here,

Sayed: Robin what is wrong if some one help me? what will happen to you? is there any problem? if you didn't like to give any help to other people please don't ask other to be similar to you, sorry about that, but that what i note from your many post that repeat same thing! i didn't ask you to help me! there are many people here want to help other, and if i am asking for help that dose not mean i didn't read and go through online tutorials, some time people understand tutorial in wrong way as what happen to me here,

I think what Robin is saying is that he doesn't mind helping so long as you are willing to try to help yourself. If you just want us to do all the work for you then you are in the wrong place. Someone else has already taken the time to write out a beautiful tutorial. Why would any of us waste our time trying to recreate that here just for you?

If you read it and there is some part you don't understand, then ask questions. But don't think that anyone here is going to spoon feed you an education in computer science if you're not willing to go and do a little light reading on your own. That would be wasting our time.

thanks Delta_G but every one see it from different point of view of there post and that my point of view since they repeat every time,
initially i didnt know what cause this problem in my code since i follow most of tutorials in the arduino, except i am missing the Unsigned in the long for doing multi task using millis, and about string that i do it as in many tutorials that use for data logger, nobody say it may cause problem!
and i note also LCD code that in most of tutorials use lcd.print(""); as string, i modify it to
disp = “Temperature Setting”;
lcd.print(disp);
where disp i make it as Char* and now my code run for 2 hour and 45 minute then it fail the problem as i see it is not from the millis() or unsigned long, and not from the SD card where i remove SD card code.
that is why i am thinking is the memory problem,

Sketch uses 28,168 bytes (87%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,581 bytes (77%) of dynamic memory, leaving 467 bytes for local variables. Maximum is 2,048 bytes.

i make this post not to ask some one to do it for me but to guide me to know the problem if possible.

iBirdDevice1.ino (17.3 KB)

  if (millis() <= 2000) {

millis() will only be less than 2000 for the first 2 seconds after you restart your Arduino. Is that what you want ?

What is the code in timer1() and in timer2() supposed to do?
It looks suspiciously like delay() to me.

…R

unsigned int PinNo1e = 1;       // relay 1 Pin
unsigned int PinNo2e = 1;       // relay 2 Pin
unsigned int PinNo3e = 1;       // relay 3 Pin
unsigned int PinNo4e = 1;       // relay 4 Pin
unsigned int PinNo5e = 1;       // relay 5 Pin
unsigned int PinNo6e = 1;       // relay 6 Pin
unsigned int PinNo2 = 2;        // Setting Button Pin
unsigned int PinNo3 = 3;        // Ok Button Pin
unsigned int PinNo4 = 4;        // plus Button Pin
unsigned int PinNo5 = 5;        // Minus Button Pin

Wasteful. Should be "const uint8_t"

disp = "Temperature Setting";etc More wasted RAM. If you've got some kind of fixed memnu system, leave the constant strings in flash memory where they belong, and just pass around their index.

Robin2:

  if (millis() <= 2000) {

millis() will only be less than 2000 for the first 2 seconds after you restart your Arduino. Is that what you want ?

What is the code in timer1() and in timer2() supposed to do?
It looks suspiciously like delay() to me.

…R

yes it is delay at startup of the program, in order to load the setting from EEPROM one time only,
timer1 are used to time turning of motor to two side,
and timer2 are used to run ventilation at setting time,
now am trying to run the device with every time disable some code until i reach to the cause of the fault
thanks very much Roben,

AWOL:

unsigned int PinNo1e = 1;       // relay 1 Pin

unsigned int PinNo2e = 1;      // relay 2 Pin
unsigned int PinNo3e = 1;      // relay 3 Pin
unsigned int PinNo4e = 1;      // relay 4 Pin
unsigned int PinNo5e = 1;      // relay 5 Pin
unsigned int PinNo6e = 1;      // relay 6 Pin
unsigned int PinNo2 = 2;        // Setting Button Pin
unsigned int PinNo3 = 3;        // Ok Button Pin
unsigned int PinNo4 = 4;        // plus Button Pin
unsigned int PinNo5 = 5;        // Minus Button Pin



Wasteful.
Should be "const uint8_t"

` disp = "Temperature Setting";`etc 
More wasted RAM.
If you've got some kind of fixed memnu system, leave the constant strings in flash memory where they belong, and just pass around their index.

but if i use const unit8_t will be as you said in old post in 2012 “quicker and consuming less program and RAM memory” about ‘uint8_t’ instead ‘Int’ but cause me problem where i can not use digitalRead(); to read the status of the pin,
it show error if i replace it with unit8_t "error: assignment of read-only variable ‘PinNo2e’ "
thanks very much

it show error if i replace it with unit8_t "error: assignment of read-only variable ‘PinNo2e’ "

OK then, drop the “const”

but if i use const unit8_t will be as you said in old post in 2012 “quicker and consuming less program and RAM memory” about ‘uint8_t’ instead ‘Int’

I ignored that because I didn’t understand it.

Your code would be a lot easier to read if you used sensible variable names and/or comments.

Sayed: timer1 are used to time turning of motor to two side, and timer2 are used to run ventilation at setting time,

I guess I did not ask my question clearly.

I would like you to explain how the code in those functions is intended to work - because I suspect it does not do what you think it does.

...R

AWOL:
OK then, drop the “const”
I ignored that because I didn’t understand it.

Your code would be a lot easier to read if you used sensible variable names and/or comments.

thanks very much AWOL,

Robin2:
I guess I did not ask my question clearly.

I would like you to explain how the code in those functions is intended to work - because I suspect it does not do what you think it does.

…R

timer1 in first lines this if statement i use it to rest the previous time for the first timer which in minute and second timer which in second and third and forth to avoid over flow in case of time deference become negative

  if ((timenw - timepr1) < 0 || (timenw - timepr2) < 0) {
    timepr1 = 0;
    timepr2 = 0;
    timepr3 = 0;
    timepr4 = 0;
  }

then if the time in second minus the previous run time greater than the setting time in minute of the timer
they go into the condition and they test for which side the turn and then run the target relay at pin 5 or 6 and stop it after time in second pass, SetTimer2 then stop the relay and save the current value in millis in the previous run timepr1,
similarly in timer2 for ventilation, which it will run for SetVent in minute for SetVent2 in second then it will stop,
i hope it is clear and it correct,
thanks again Roben,

Sayed: timer1 in first lines this if statement i use it to rest

Thanks for the info.

I won't be able to study this until late today or tomorrow. I will make a note to do so.

...R

I have now had a look at your timer code. I can't say I understand it, but I don't think it has the problem I thought it had. I suspect "timer1()" is not a very meaningful name because the function seems to do things and not just provide a time interval.

I note that you have

  if (timenw - timepr1 >= interval) {
    rtimer = 0;
    
     ....SNIP.....
     
    if (rtimer == 0) {
      interval = SetTimer1 * 60ul + SetTimer2;
      
      if (timenw - timepr1 >= interval) {

in which you have a second identical interval test is inside the first one. As I say, I can't figure what the code is supposed to do but I am doubtful if those nested IFs will work as you expect.

I think your code would be much easier to follow if you just use millis() rather than converting them to seconds.

...R

thank you very much Robin, for that long time i order Arduino mega 2560, and i connect the existing connection to it and the code with some modification in the pins, the code work fine with SD card and other thing for days without problem when the relay board not connected,

i just add some code which turn off 4 relay in the board at same time on and off based on push button and from this ( when relay connected ), just two or three pressing on the push button the screen corrupt and then some pressing on the push button the arduino restart, and some time directly restart, i think the problem with relay board wiring, this is the same board |356x500 i wire it with arduino direct with Vcc to +5 and ground, is there way for this?