Pages: [1] 2 3 4   Go Down
Author Topic: Saving arrays in EEPROM using ARDUINOMEGA  (Read 6541 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear all, i need to save a 3 digit # and a 4 digit # in an array[3 digit #]  = (4 digit #) using the EEPROM since I am recieving this data using serial GUI.

Can anyone give any hints on how I can start since I have no idea how to bgin.
Tnx
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50842
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i need to save a 3 digit # and a 4 digit # in an array
The number of digits in the numbers is irrelevant, as long as the array type is correct (int, not byte).

Quote
array[3 digit #]  = (4 digit #)
Does this mean that you need an array whose size is somewhere between 111 to 999?

Quote
using the EEPROM
On which Arduino? You may or may not have enough room in EEPROM for a 1000 element int array.

Quote
I am recieving this data using serial GUI.
How? The Arduino doesn't have the native ability to display a GUI.
Logged

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

Also, are you using the ATMEGA's onboard EEPROM or external EEPROMs via I2C like 24LC512?
Logged


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

Yes i know the arduino doesn't have the GUI, but I managed to program it serailly using C# using forms.
That has been sorted out and PAULS, it is tnx to you that I managed it.

I am using the Arduino Mega, having an inbuilt 4kb EEPROM. 

Ok so the digits are irrelivant....

What I need is this:
Imagine I recieved an integer serially, say for example 323 (this has been converted from character to an array an to an integer.......) So we have an integer saved in the FLASH memory, i.e. 323.
An then I recieve another # say for example 1234(the same procedure from a char to int.....).So we have another integer saved in the FLASH.
i.e. eg   int reference_no = 323;
            int gas = 1234;
Therefore I need to save these integers in an array in the EEPROM.

This is what I had in mind:

EEPROM:
ADDRESS    VALUE
0               323
1               1234
2
.
.
.
4095

The problem I currently have is when writing for example 323 in the EEPROM in address 0, and when I read it, it isn't 323 saved but 67..???
Is this since the number is greater than 255????

How can I save 323 then??
TNX
Logged

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

Just to straight out the terms, FLASH you mentioned in NOT EEPROM.
You need to show the code. I suspect you only read one byte instead of two. I don't know if you wrote two bytes or not with your code. You know, 323 needs two bytes. If you only write the low byte, you get 323 chopped to fit within 255=67

It's probably that.
Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The problem I currently have is when writing for example 323 in the EEPROM in address 0, and when I read it, it isn't 323 saved but 67..???
323 - 256 = ?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Ok...so this is the code(it doesn't have the GUI and stuff just an short program...)
Code:
#include <EEPROM.h>

void setup()
{
  Serial.begin(9600);
  int reference = 323;
  int gas = 1234;
  int serial;
 
  EEPROM.write(0,323);
 
  serial =EEPROM.read(0);
 
  Serial.print(serial);
 
 
}
void loop()
{
  int reference = 323;
  int gas = 1234;
  int serial;
 
  EEPROM.write(0,323);
 
  serial =EEPROM.read(0);
 
  Serial.print(serial);
 
}

So how can I save 323 then??

tnx
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So how can I save 323 then??

As two bytes, aka "int".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

Sry this is the code..
Code:
#include <EEPROM.h>

void setup()
{
  Serial.begin(9600);
  int reference = 323;
  int gas = 1234;
  int serial;
  
  EEPROM.write(0,323);
  
  serial =EEPROM.read(0);
  
  Serial.print(serial);
  
  
}
void loop()
{
    
}
Logged

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

It is saved as int....
int reference = 323;
???
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It is saved as int....
int reference = 323;
But the EEPROM is only byte wide.

sizeof (byte) == sizeof (int) / 2  (for the Arduino)
« Last Edit: March 09, 2011, 03:15:03 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 651
Posts: 50842
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

EEPROM.write() and EEPROM.read() operate on bytes. To save an int:

Code:
EEPROM.write(0, highByte(reference));
EEPROM.write(1, lowByte(reference));

To read an int:

Code:
int val = (EEPROM.read(0) << 8) + EEPROM.read(1);

You might want to look at the EEPROM_readAnything() and EEPROM_writeAnything() functions:
http://www.arduino.cc/playground/Code/EEPROMWriteAnything
Logged

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

Ok didn't know this....
So I am using 2 addresses inside the EEPROM now?

That is a problem....
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26621
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So I am using 2 addresses inside the EEPROM now?
So you've got at least 510 more to play with

That's not a problem - read and understand reply #11
« Last Edit: March 09, 2011, 03:28:38 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

No it is a problem...
The integer of the reference # varies from 322 to 500 (so in this case it the above procedure needs to be done, if I am correctly understanding)
While the gas # varies from 500 to 1200. Which means I am taking more than one and more addresses

But I need to save these #s in an array which is proportional to the reference # and gas

meaning array[reference] = gas

So how can I know which address it is if each refernce # and gas amount is different entered by the user??

I don't know If I described it correctly....
Logged

Pages: [1] 2 3 4   Go Up
Jump to: