0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« on: March 09, 2011, 10:05:09 am » |
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
Brattain Member
Karma: 335
Posts: 36459
Seattle, WA USA
|
 |
« Reply #1 on: March 09, 2011, 10:59:41 am » |
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). array[3 digit #] = (4 digit #) Does this mean that you need an array whose size is somewhere between 111 to 999? using the EEPROM On which Arduino? You may or may not have enough room in EEPROM for a 1000 element int array. 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
Faraday Member
Karma: 38
Posts: 6050
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #2 on: March 09, 2011, 01:00:18 pm » |
Also, are you using the ATMEGA's onboard EEPROM or external EEPROMs via I2C like 24LC512?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #3 on: March 09, 2011, 01:49:42 pm » |
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
Faraday Member
Karma: 38
Posts: 6050
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
|
 |
« Reply #4 on: March 09, 2011, 02:40:48 pm » |
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
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: March 09, 2011, 02:50:41 pm » |
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.
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #6 on: March 09, 2011, 03:08:08 pm » |
Ok...so this is the code(it doesn't have the GUI and stuff just an short program...) #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
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: March 09, 2011, 03:09:39 pm » |
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.
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #8 on: March 09, 2011, 03:09:54 pm » |
Sry this is the 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
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #9 on: March 09, 2011, 03:12:06 pm » |
It is saved as int.... int reference = 323; ???
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #10 on: March 09, 2011, 03:12:59 pm » |
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.
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 335
Posts: 36459
Seattle, WA USA
|
 |
« Reply #11 on: March 09, 2011, 03:13:41 pm » |
EEPROM.write() and EEPROM.read() operate on bytes. To save an int: EEPROM.write(0, highByte(reference)); EEPROM.write(1, lowByte(reference)); To read an int: 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
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #12 on: March 09, 2011, 03:23:51 pm » |
Ok didn't know this.... So I am using 2 addresses inside the EEPROM now?
That is a problem....
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #13 on: March 09, 2011, 03:26:16 pm » |
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.
|
|
|
|
0
Offline
Full Member
Karma: 1
Posts: 110
Arduino rocks
|
 |
« Reply #14 on: March 09, 2011, 03:38:08 pm » |
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
|
|
|
|
|
|