Store & Retrieve ULong using EEPROM.fcfx

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
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:

Store & Retrieve ULong using EEPROM.fcfx

Post by medelec35 »

I have attached a V6 flowchart for anyone who would like to store and retrieve a ULong number (0 to 4294967295) using EEPROM

The attached Flowchart stores the number 1234567890 from the cycles variable by breaking it down into for sets of bytes.
The bytes are then stored within EEPROM.
Finally the four bytes are retreived from EEPROM then assigned back to cycles variable = 1234567890.

Martin
Attachments
Store and Retrieve ULong within EEPROM V2.fcfx
(7.6 KiB) Downloaded 890 times
Martin

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: Store & Retrieve ULong using EEPROM.fcfx

Post by medelec35 »

Corrected an issue.
Store and Retrieve ULong within EEPROM V2.fcfx
Should now work within Flowcode simulator and on hardware.

Martin
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by electron67 »

Hello Martin,
excuse my ignorance,You can help me understand how to record the ULONG numbers in the EEPROM, as I understand you recorded in the EEPROM 1, 2, 3 and 4 numbers 73, 150, 2 and 210 but if you want to record, for example 25684, 698564 , 85247, and 985746 could show me how? :?:

Thanks
Enrique

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: Store & Retrieve ULong using EEPROM.fcfx

Post by medelec35 »

Hi Enrique,
You can only store bytes (0 to 255) in EEPROM with 8bit microcontrollers.
The number I was actually storing is 1234567890 which is assigned to Cycles variable.
Numbers 73, 150, 2 and 210 is the 1234567890 broken down into bytes to store within EEPROM.

If you want to store numbers from -32768 to 32767 then you only need two bytes instead of four bytes used with Ulong.

In your case the 5684, 698564 , 85247, and 985746 just replaces the 1234567890 within the flwochart I had posted.
Since they are within int range, just remove references to TotCycle3 & TotCycle4.

Martin
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by electron67 »

Hi Martin,
I take one day to know that you were saving was number 1234567890, I thought it was part of the formula to save EEPROM, thanks anyway, the forum is an excellent way to learn. :oops:

Enrique

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: Store & Retrieve ULong using EEPROM.fcfx

Post by medelec35 »

Hi Enrique,
Glad you are learning from what we post!

Thanks for your feedback.
I have now edited my first post in the hope of making it all clearer.

Martin
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by electron67 »

Thank you Martin and Benj the whole team of matrix, including all users wish you have a happy Christmas and a good year 2016


HAPPY HOLIDAYS !
Enrique

rudolfsteiner
Posts: 5
Joined: Fri Feb 06, 2015 5:54 pm
Has thanked: 1 time
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by rudolfsteiner »

Hi Martin,
I had the curiosity to put the ULong number on a display and it works nicely, but 4294967295 does not display it, the display shows -1, I can not handle it, I do not know what to do.
Thank you in advance!
Attachments
4294967295.png
(18.16 KiB) Downloaded 6364 times
1234567890.png
(18.09 KiB) Downloaded 6364 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: Store & Retrieve ULong using EEPROM.fcfx

Post by medelec35 »

Hi Rudolf,
I can't see all of your flowchart so will be difficult to say exactly.
I believe the issue is with Flowcode V5 & V6 the LCD can only display signed numbers.
I requested LCD in V7 to be able to display unsigned numbers like UInt & ULong.
So it was implemented

Martin
Martin

electron67
Posts: 311
Joined: Sat Jan 12, 2008 2:08 am
Has thanked: 104 times
Been thanked: 47 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by electron67 »

Hi

And you need to use the highest value number in Ulong :?:

rudolfsteiner
Posts: 5
Joined: Fri Feb 06, 2015 5:54 pm
Has thanked: 1 time
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by rudolfsteiner »

Hi Martin,
Thanks a lot for the answer, I attach a flowchart, maybe you will notice where I'm wrong.
Attachments
Store and Retrieve ULong within EEPROM V3.fcf
(11 KiB) Downloaded 368 times

rudolfsteiner
Posts: 5
Joined: Fri Feb 06, 2015 5:54 pm
Has thanked: 1 time
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by rudolfsteiner »

Hi Enrique,
And you need to use the highest value number in Ulong :?:
I do not need, I just noticed a possible bug in Flowcode.

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by AbhijitR »

Hello! Martin
medelec35 wrote: I have now edited my first post in the hope of making it all clearer.
Martin
My doubt is regarding the Store & Retrieve of INT to EEPROM, I can do it well using one of your posts/example from V5, my doubt is little different today, I hope you will help me to solve that

Case 1
If the INT value is 2570 then the breakup of this value to store in the EEPROM is 10 and 10 and
Case 2
If the INT value is 257 then the breakup of this value to store in the EEPROM is 1 and 1

I hope I have put my doubt correctly, my problem is in case 2, is it not possible to retrieve the number as 0257 the '0' is very important for me in this case.

I am converting the entire digit (2570) in case 1 to string and then comparing the same with the present value, it works as the present value is a f digit number, but if I convert the digit (257) like in case 2 then the comparison goes wrong as the first digit '0' is missing.

May be you have some other trick.

Thank you,

Regards
Abhi

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by kersing »

The obvious question would be why are you comparing strings and not numbers?

If you need to compare strings you could compare the number to see if it is < 10, add three zeros in front if the string, check < 100, add two zeros and compare < 1000 and add one zero.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by AbhijitR »

Hello! Kersing

Many thanks for the suggestion, actually the requirement for comparing the strings come from the below post from Ben

viewtopic.php?f=54&t=15948

In this example the saved password is as string of 4 digit number and then it is compared with the entered 4 digit number, on the keyboard, unfortunately I do not have a keyboard in my project but want the have a password to enter the programming mode using 3 keys (UP, DOWN and ENTER), what Ben suggested works well until the password to compare is mentioned in the calculation box as 4 digit number, I want to save the 4 digits password in EEPROM so can be changed when required.

Now when I try to retrieve the password as which is a 3 digit number then the comparison goes wrong.

What you suggested of adding a zero before the 3 digits is nice, but I do not find any post which can help me to add the zero before the number which is in NUMBER (INT) format or STRING format.

Can you help me in that.

Thank you.

Regards
Abhi

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by kersing »

To modify strings you can use the string manipulations available. One of them being concatenation.

The result would be something like:

Code: Select all

newString = "000" + smallString
Where smallString would be the one you previously created from the number stored in eeprom.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Store & Retrieve ULong using EEPROM.fcfx

Post by AbhijitR »

Hello! Kersing
good morning

First of all many many many thanks for that valuable input, it helped me a lot as well taught me a new lesson about String Manipulation, finally my access system/password entry using an OLED Display and 3 keys (UP, DOWN and ENTER) is working successfully, now I can change the password and also store the new one in the EEPROM.

Thanks to Ben and Martin too.

Regards
Abhi

Post Reply