How to save ULong variable value in EEPROM?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
kg300
Posts: 31
Joined: Thu May 31, 2018 6:25 am
Has thanked: 5 times
Been thanked: 1 time
Contact:

How to save ULong variable value in EEPROM?

Post by kg300 »

Hi, I want to save a Ulong Variable (06 digits) in EEPROM, any example for me.?
I get a code from Arduino forum, writing in the eeprom memory locations is ok, but when i tried to get back data from these locations variable only show the value less then 65000. mean only get back Unint value from eeprom. any help pleas...

long EEPROMReadlong(long address) {
long four = EEPROM.read(address);
long three = EEPROM.read(address + 1);
long two = EEPROM.read(address + 2);
long one = EEPROM.read(address + 3);

return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}

void EEPROMWritelong(int address, long value) {
byte four = (value & 0xFF);
byte three = ((value >> 8) & 0xFF);
byte two = ((value >> 16) & 0xFF);
byte one = ((value >> 24) & 0xFF);

EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);
}

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: How to save ULong variable value in EEPROM?

Post by Benj »

Hello,

Maybe try this instead.

Read

Code: Select all

byte four = EEPROM.read(address);
byte three = EEPROM.read(address + 1);
byte two = EEPROM.read(address + 2);
byte one = EEPROM.read(address + 3);

return = one
return = return << 8
return = return | two
return = return << 8
return = return | three
return = return << 8
return = return | four
Write

Code: Select all

byte four = value;
value = value >> 8;
byte three = value;
value = value >> 8;
byte two = value;
value = value >> 8;
byte one = value;

EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);

kg300
Posts: 31
Joined: Thu May 31, 2018 6:25 am
Has thanked: 5 times
Been thanked: 1 time
Contact:

Re: How to save ULong variable value in EEPROM?

Post by kg300 »

Its working ok. thanks Benj :D

Sashinda
Posts: 1
Joined: Wed Sep 02, 2020 12:35 pm
Contact:

Re: How to save ULong variable value in EEPROM?

Post by Sashinda »

hi,
How to write this in calculation block?

EEPROM Read;-
return = one
return = return << 8
return = return | two
return = return << 8
return = return | three
return = return << 8
return = return | four

EEPROM Write :-

byte four = value;
value = value >> 8;
byte three = value;
value = value >> 8;
byte two = value;
value = value >> 8;
byte one = value;

Please help me...
Attachments
Flow1.JPG
Flow1.JPG (11.87 KiB) Viewed 3322 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: How to save ULong variable value in EEPROM?

Post by medelec35 »

Hi Sashinda,
Welcome to the forums.
I have attached a flowchart that works the way Ben suggested.
I have also included two alternative ways of saving and retrieving ULongs(disabled icons).
Attachments
Store & Retrieve ULong within EEPROM v3.fcfx
(14.77 KiB) Downloaded 218 times
Martin

Sashinda
Posts: 1
Joined: Wed Sep 02, 2020 12:35 pm
Contact:

Re: How to save ULong variable value in EEPROM?

Post by Sashinda »

hello...Medelec35
It's working super... :D
Thanks a lot. :)
I will never forget your help...
Last edited by Sashinda on Thu Sep 03, 2020 7:24 pm, edited 1 time in total.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: How to save ULong variable value in EEPROM?

Post by medelec35 »

Hi Sashinda ,
You're welcome.
I'm pleased you have your project working super.
Thank you for letting us know, really appreciate it.
Martin

User avatar
AbhijitR
Posts: 299
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 280 times
Been thanked: 79 times
Contact:

Re: How to save ULong variable value in EEPROM?

Post by AbhijitR »

Hello! Martin

Many thanks for this post, you are too good.
medelec35 wrote:
Wed Sep 02, 2020 5:11 pm
I have also included two alternative ways of saving and retrieving ULongs(disabled icons).
Finally I got the opportunity to thank you.

Abhi

Post Reply