Pages: [1]   Go Down
Author Topic: Retaining Variable Value in Arduino - Possible?  (Read 1077 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way for a Variable declared in the program to retain it's value if it is change and the arduino is turned off then on again?

Example is that if "X" variable is declared as 0 from the start of the program, and then it became "X=1", is it possible when you turn off/on the arduino
the "X" retains it value change which is "1" ?
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No.  But you can store values in EEPROM and read them after a reboot.

Search the forum/playground for EEPROM and you'll find many examples.

-br
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EEPROM can be use for persistent storage. It has a finite number of write cycles, so you need to be judicious about when you write to it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much for the help.  smiley-grin
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a quick question to make sure, in the topic of powering the arduino,
HOW MUCH VOLTAGE WOULD YOU NEED TO TURN ARDUINO UNO ON IF NOT CONNECTED TO A PC via Cable?
Logged

California
Offline Offline
Faraday Member
**
Karma: 91
Posts: 3430
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HOW MUCH VOLTAGE WOULD YOU NEED TO TURN ARDUINO UNO ON IF NOT CONNECTED TO A PC via Cable?

http://arduino.cc/en/Main/arduinoBoardUno
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7243
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I use a 9V center positive ac adapter with 1A current rating. Make sure it is center positive.
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 107
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another possibility is check the peripheral chips you're using.  Sometimes they offer a place to stash a few bytes.  For instance, I use the DS1305 RTC in one of my projects.  it has 96 bytes of user RAM that is battery-backed.  No finite cycles to worry about.  I think the DS1307 and others have similar.  You could also consider adding a Serial ROM chip.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems that EEPROM only gives you a max of 256 value to store in each address.

IS THERE ANYWAY OF INCREASING IT TO 1000?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
IS THERE ANYWAY OF INCREASING IT TO 1000?
No. You can however store each byte of an int, and later reconstruct it. Look at highByte() lowByte() and word().
Logged

Pages: [1]   Go Up
Jump to: