Shop OBEX P1 Docs P2 Docs Learn Events
saving data in memory — Parallax Forums

saving data in memory

sharmaitsharmait Posts: 15
edited 2008-11-17 19:12 in General Discussion
Can somebody please help me on this ? I am new to Javelin.

Is there any way to download·programs on·Javelin to some specific address that I define? I know that using·EEPROM class I·can define the address where I·write a·value to EEPROM. Is this also possible for a program ? Can we write two programs in two different locations of the memory ? Or is it that the latest will always overwrite the formers ?

My problem is I have a robot driven by javelin to waypoints. Upon reaching the waypoint it should note down the time and save it some where in memory. But it seems the time data is overwriting the waypoint program, so to navigate to the other waypoints I am having to upload the program again...and this is erasing the time data......

Any help.....I will be thankful......smile.gif
·

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-04-13 06:21
    It is not possible to overwrite the javelin program by
    using EEPROM.write() method. Whenever you supply
    an address >= EEPROM.size() an exception is thrown.

    You can download only a single program (consisting of multiple classes)
    to the javelin, so your program must define an array of timestamp entries
    and also copy the latest index into that array to the eeprom, so that
    after powerup the already stored timestamps do not get overwritten.

    May I point out the rtc classes here:
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/peripheral/rtc/
    The Calender class offers methods for converting date and time to/from integers and ascii strings,
    so you could use a simple integer array to hold the timestamps.

    regards peter
    ·
  • BobValBobVal Posts: 48
    edited 2008-11-13 03:50
    I am a little confused.

    From posting I have read, I believe that while my program is running it can write to the Javelin EEProm and save memory variables that on a reboot (after a power outage) I could read in?

    Is this true or am I reading some of these posting wrong?

    If it is true does someone (I assume Peter you must) and a small example of writing and reading the EEProm.

    I just need to save maybe 32 bytes.

    I was going to use 93LC66 serial eproms but do not really need that much storage.

    Bob
  • jmspaggijmspaggi Posts: 629
    edited 2008-11-13 13:27
    Hi Bob,

    I have personnaly add 8 EEProm to my Javalin. It's using 4 wires. (+5V, 0V, Data, Clock). All the EEProm are on the same bus.

    The issue with an EEProm is that you can read/write it onyl a certain amount of time. So if you use the one from the Javelin board to much, you are simply going to burn it. So that'S why I will not recommand to write on the Javelin EEprom.

    The 24LC256 class is avaiable on the yahoo groups I think. And you can take a look here: http://forums.parallax.com/forums/default.aspx?f=8&m=268786

    Also, you have some free spaces on somne components like SHT11 or RTC chipsets. Maybe you can reuse that?

    JM
  • BobValBobVal Posts: 48
    edited 2008-11-13 14:26
    Hello:

    Well I wrote a little test program to read and write the Java EEProm (to say the least I was a little concerned - have already fried on of these chips) but it works.· Went to upload it using Upload Manager but it would not me upload a file with a Java extension (isn't that the type of files we are suppose to be sharing?).

    Anyway I will just past it below.· (but all the spacing and indenting will probably be lost).

    Bob


    ======== JavaTest Program Starts Here ============
    import stamp.core.*;
    import java.io.PrintStream;
    import stamp.util.text.Format;
    public class JavaTest {
    ······ static· EEPROM········ JavelinEEProm = new EEPROM();
    ······ static· char·········· MyHeader[noparse]/noparse··· = new char[noparse][[/noparse]7];
    ······ static· StringBuffer·· MyHeaderCmp;
    ······ //
    ······ //· main
    ······ //=================================================================================
    ······ //······ Main processing loop
    ······ //
    ······ public static void main() {
    ························· int i;
    ························· System.out.print("\n\nBytes available = ");
    ························· System.out.println(JavelinEEProm.size());
    ························· MyHeader[noparse][[/noparse]6] = 0x00;
    ························· for(i = 0;· i < 6;· i++)· {
    ····························· MyHeader[noparse][[/noparse]i] = (char)JavelinEEProm.read(i);
    ························· }
    ························· MyHeaderCmp = new StringBuffer();
    ························· MyHeaderCmp.clear();
    ························· MyHeaderCmp.append(MyHeader, 6);
    ························· if· (MyHeaderCmp.equals("~BOBs~"))· {
    ······························ System.out.println("Header Found");
    ························· }
    ························· else· {
    ······························ System.out.println("Header NOT Found - writing");
    ······························ MyHeaderCmp.clear();
    ······························ MyHeaderCmp.append("~BOBs~");
    ······························ for(i = 0;· i < 6;· i++)· {
    ·································· JavelinEEProm.write(i, (byte)MyHeaderCmp.charAt(i));
    ······························ }
    ························· }
    ························· System.out.println("\nJavaTest Completed");
    ······ }
    }
    ========· JavaTest Program Ends Here· ============
  • BobValBobVal Posts: 48
    edited 2008-11-13 14:27
    Well not bad the only thing lost was the BLANK lines between line of code
  • BobValBobVal Posts: 48
    edited 2008-11-13 17:49
    Well the reading and writing are working well, but I thought (probably something I am no longer really do well since retiring 8 years ago) that ever time I flashed my program to the Javelin it would clear the EEProm. This does not seem to be the case.

    Is there anyway to determine if the program was reflashed because when it is the data I am saving in the EEProm becomes invalid.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-14 08:15
    Bob,

    As it happens I am writing classes to support inivalues (eg. name = value)
    which are just ascii strings really. Having inivalues should make it possible
    to·let the javelin receive a .INI file. Normally .INI files have sections like
    [noparse][[/noparse]sectionname], however I do not support that. Using unique names is
    sufficient. With inivalues·it is easy to change startup/initialization values
    without reprogramming.
    I am also writing a class to support a·history log.
    Both these utilities are useful to be used with the free javelin eeprom
    as inivalues are written mostly once, and history messages are written
    using a round robin scheme so the same eeprom address is·not constantly
    overwritten. Like jmspaggi said, we have·to be careful not·to wear out the
    eeprom.

    The way I detect wether the javelin has been programmed (and so any
    data in the free area could be altered) is by storing the free size in address 0 and 1.
    Also, in addresses 2 and 3 I store the used size of the free area.

    static void main()·{
    · int·oldee = EEPROM.read(0) & 0xFF; //previous free size
    · oldee |= EEPROM.read(1)<<8;
    · int newee = EEPROM.size(); //current free size
    · if (newee != oldee) { //apparently javelin·has been reprogrammed with a new program of different size
    ····EEPROM.write(0,(byte)newee);
    ··· EEPROM.write(1,(byte)(newee>>>8);
    · }
    · initEEdata();
    · //continue with main
    }

    initEEdata() obviously must check the used size·(in address 2 and 3) against the new free size,
    and if the used size > free size than some of the data has been overwritten.
    My plan is to store history log messages at the end of the free area so all I would lose
    were some history messages. initEEdata() must in that case repair the datastructure
    if possible or recreate a new (but smaller) datastructure with default settings.

    I·will post my classes when I have them ready which could be some time.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-14 12:54
    Bob,
    Here is my JavEE.java class that provides additional·eeprom read/write methods
    and two methods (init and allocate) that manage the free·javelin eeprom space.
    Applications·that want to utilize the free eeprom space, can use this class to
    allocate blocks of free eeprom space. Blocks can only be allocated, not freed.
    Since the eeprom is used for persistent data there is no need, and it keeps
    the code quite small.
    The file goes into folder ...\lib\stamp\core


    regards peter


    Post Edited (Peter Verkaik) : 11/14/2008 1:04:02 PM GMT
  • BobValBobVal Posts: 48
    edited 2008-11-14 14:11
    Thanks guys, as always super answers.

    Right now I am using the Javelin EEprom, when we talk about wearing it out we are talking about millions of writes aren't we??

    Or is it something real small?

    Bob
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-14 14:19
    I believe the javelin eeprom supports over 100.000 writes.
    However, if·you overwrite·the same area once every second,
    it will wear out in about 100.000 seconds or about·28 hours.

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-17 14:11
    I have completed my message log class.
    I have changed the JavEE class so you can call JavEE.allocate() without
    the need for JavEE to initialize. Blocks are allocated from address 0x0000 upwards,
    which means the return value -1 (=0xFFFF) is now used to signal failure.
    Here is the output of the test program. Notice how after reset, the message
    table is restored and new messages can be added.
    SystemEepromHistory_test program.
    <eeprom message table>
    0000 : 12 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    0010 : 00 00 ..
    add message PPPP
    <messages>
    0000 : 50 50 50 50 PPPP
    add message QQQQ
    <messages>
    0000 : 50 50 50 50 PPPP
    0000 : 51 51 51 51 QQQQ
    Program finished.
    SystemEepromHistory_test program.
    <eeprom message table>
    0000 : 12 00 04 00 04 50 50 50 50 04 51 51 51 51 00 04 .....PPPP.QQQQ..
    0010 : 00 00 ..
    <messages>
    0000 : 50 50 50 50 PPPP
    0000 : 51 51 51 51 QQQQ
    add message RR
    <eeprom message table>
    0000 : 12 00 09 00 09 00 50 50 50 04 51 51 51 51 02 52 ......PPP.QQQQ.R
    0010 : 52 00 R.
    <messages>
    0000 : 51 51 51 51 QQQQ
    0000 : 52 52 RR
    Program finished.
    SystemEepromHistory_test program.
    <eeprom message table>
    0000 : 12 00 09 00 09 00 50 50 50 04 51 51 51 51 02 52 ......PPP.QQQQ.R
    0010 : 52 00 R.
    <messages>
    0000 : 51 51 51 51 QQQQ
    0000 : 52 52 RR
    add message RR
    <eeprom message table>
    0000 : 12 00 06 00 52 52 00 09 00 04 51 51 51 51 02 52 ....RR....QQQQ.R
    0010 : 52 02 R.
    <messages>
    0000 : 51 51 51 51 QQQQ
    0000 : 52 52 RR
    0000 : 52 52 RR
    Program finished.
    

    The JavEE class goes into folder ...\lib\stamp\core
    The classes History(), SystemEepromHistory() and SystemEepromHistory_test()
    go into folder ...\lib\stamp\util\history
    The classes SystemRamHistory() and SystemRamHistory_test() also go into the history folder.
    These classes use ram to setup the message table and therefore·these are always empty
    after reset.

    regards peter


    Post Edited (Peter Verkaik) : 11/17/2008 5:02:18 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-17 19:12
    Update for History.java (v1.1)
    I simplified some code by storing the address of the oldestMessage
    at address 2 which made a new entry consist of a single null byte.
    Just copy to folder history.

    regards peter

    Post Edited (Peter Verkaik) : 11/17/2008 9:00:35 PM GMT
Sign In or Register to comment.