Shop OBEX P1 Docs P2 Docs Learn Events
Can you discuss to me about EEPROM of BASIC STAMP 2 — Parallax Forums

Can you discuss to me about EEPROM of BASIC STAMP 2

Hi guys. I`m confuse about reading and writing in EEPROM. Can you teach me or explain to me differ about EEPROM. Because i have a project right now called "BELL RINGER", i can`t start my project because right now i`m still confused on EEPROM. My question is how can i store a ""HH:mm" format of time in EEPROM. For example the time of GPS antenna is "10:30" and there is stored "10:30" also in EEPROM. the basic stamp will be high and the bell will ring on that specific schedule. Can someone help me? Thanks in advance guys.
«1

Comments

  • Your other post has been removed as it is against forum rules to double post:
    No Cross-Posting:
    Cross-posting is: 1) submitting a post to one forum or thread, and then submitting a second linking to the original post (without changing content or intent), or 2) creating an identical post in more than one forum or thread. When the same content is found in more than one post, even under different subject lines, the forum moderator will remove one (or more) of the redundant posts and the posting account may be subject to moderation.
  • The Stamp Basic Syntax and Reference Manual has chapters on the READ and WRITE statements which read from EEPROM and write to EEPROM respectively. I assume your "HH:mm" is stored in a byte array as the 5 characters "H", "H", ":", "m", "m". This will use 4 locations in EEPROM (the ":" never changes, so it doesn't have to be saved). Look at the examples in the Manual.

    Remember that EEPROMs wear out, so you don't want to keep saving the same value over and over again at high speeds. Typically a location in EEPROM is good for 10^6 writes. A good way to help this is to read the location first and compare the new value to the saved value and only change it if the new value is different:

    READ location,temp
    IF temp <> newValue THEN WRITE location,newValue
  • kwinnkwinn Posts: 8,697
    If you want to save a table of times to ring a bell for coffee breaks and lunch, recesses and lunch, or similar schedules then you can save them in time order as Mike outlined, compare the table entries to the incoming GPS time, and ring the bell when the times match.
  • Thanks for the reply guys. Mr. Mike so i need 4 location for 1 schedule? is there a limit in writing on eeprom? sorry for my questions because im new in doing with eeprom. maybe can you give me more example to give me more knowledge about it. Thanks Again.
  • This is our existing vb program that can set schedules per day in a week. Maybe can help this to you guys so you can help me. Thanks
    1917 x 1019 - 192K
  • kwinnkwinn Posts: 8,697
    Thanks for the reply guys. Mr. Mike so i need 4 location for 1 schedule? is there a limit in writing on eeprom? sorry for my questions because im new in doing with eeprom. maybe can you give me more example to give me more knowledge about it. Thanks Again.

    You will need 4 locations (bytes) for each time, so for the schedule you posted you would need 24 bytes for each day and 168 bytes for the full week.

    There is a limit (typically about a million) to how many times you can write to the bytes but unless the schedule gets updated hundreds of times a day it is not a concern.
  • I see. thanks guys. i`ll update you if i will succeed or not.
  • Hi guys im back. I have a question, can basic stamp 2 read an external memory for additional memory in eeprom? Thanks in Advance
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    You can connect an external EEPROM to use for data storage, however it is not possible to use it for larger programs or to extend the range of existing memory past 2K.
  • While you can connect an external EEPROM for data storage, the code to do I2C for the EEPROM is quite large. The Basic Stamp 2 p series (p,pe,px) has built-in I2C statements which makes handling I2C EEPROM much easier. They also have a lot more program memory which can be used for data as well and that often is enough so you don't need the external EEPROM.
  • Hi guys. I have only a Basic Stamp 2. this all we have here. Is there any solution for Basic Stamp 2 to extend my memory?
  • kwinnkwinn Posts: 8,697
    The BS2 has 16 I/O pins so if you have enough pins left over you could use an external eeprom to hold the schedule. There might be enough internal eeprom (2k) left after the program to use that.
  • Thank kwinn. I`ll keep you in touch in my project. I`ll try it.
  • kwinnkwinn Posts: 8,697
    Another option would be to reduce the amount of data needed for the schedule.
  • What do you mean Mr. kwinn?
  • kwinnkwinn Posts: 8,697
    What do you mean Mr. kwinn?

    If your schedule has entries that do the same thing at the same time on several days you can set it up so you only need one table entry. Make the individual bits of the first byte of each time entry represent the days of the week, and the next four bytes the time. Then to ring the bell at 10:30 on Monday to Friday the data in the table would be:

    %00011111, "1", "0", "3", "0"
  • Hmmm i see Mr. kwinn i`ll try it.. I`ll keep in touch to you on my project. Right now i`m waiting for my mate to do the circuit. Thanks again.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    You can also reduce the current time into a single word value. There are 1440 minutes per day. You can represent any time in raw minutes with a small conversion.
  • kwinnkwinn Posts: 8,697
    You can also reduce the current time into a single word value. There are 1440 minutes per day. You can represent any time in raw minutes with a small conversion.

    I was thinking of suggesting something similar but held off doing so because it did not seem worth the effort in this particular case. It would cut table size by 50% at the cost of some extra code so it depends on how compact the compiled code would be.

    I think converting the time to four hex digits would make the code simpler and shorter while providing the same space saving. I am tempted to get a Basic Stamp with my next order to see.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    The reason I have used this code in the past was for a BBS I wrote back in the 90s. It made it much easier in code to calculate differences in time, elapsed time and when the time rolled over midnight. Dealing with individual chunks of time for that is clunky when you're working on a microcontroller.
  • Can you explain little bit more Mr. Chris? It will help me a lot. Thanks
  • kwinnkwinn Posts: 8,697
    The reason I have used this code in the past was for a BBS I wrote back in the 90s. It made it much easier in code to calculate differences in time, elapsed time and when the time rolled over midnight. Dealing with individual chunks of time for that is clunky when you're working on a microcontroller.

    I understand. There really is no universal "best way" to do a lot of things, including time/date applications. What I was suggesting works well for this particular application where there are a small number of events, very limited memory to work with, and dealing with time being input in ascii format, but it would not work well in a lot of other cases.
  • Mr. kwinn do you think how many schedule can i save to eeprom of basic stamp 2? if i`ll alot a 4location per alarm?
  • kwinnkwinn Posts: 8,697
    Mr. kwinn do you think how many schedule can i save to eeprom of basic stamp 2? if i`ll alot a 4location per alarm?

    That depends on how complicated your software needs to be. If it is as simple as parsing the GPS data to get the time and reading the schedule to ring the bells you could probably get two hundred or more entries in the eeprom.

    The best way to figure that out would be to write the software to do what you want and see how much memory is left over for data. Even if you find you need to add an external eeprom almost all of the software could be re-used.
  • kwinn wrote: »
    Mr. kwinn do you think how many schedule can i save to eeprom of basic stamp 2? if i`ll alot a 4location per alarm?

    That depends on how complicated your software needs to be. If it is as simple as parsing the GPS data to get the time and reading the schedule to ring the bells you could probably get two hundred or more entries in the eeprom.

    The best way to figure that out would be to write the software to do what you want and see how much memory is left over for data. Even if you find you need to add an external eeprom almost all of the software could be re-used.

    I see Mr. kwinn.. I`ll keep in touch in you guys... because my team is making our hardware first...
  • Hello guys im back.. Mr. kwin can u give me a sample of code that your thinking on how the program works? Thanks in advance.
  • kwinnkwinn Posts: 8,697
    The actual code would depend on the specific hardware you are using, the format of the GPS data, and whether you are loading the schedule table as part of the program load or by serial data using a subroutine in the program. The way I would approach receiving the time and scanning through the schedule would be:
    DO
    IF time = oldtime THEN GOSUB getgpstime
    ELSE
    	oldtime = time
    	GOSUB scantable
    LOOP
    
    getgpstime:	‘ get the time from the gps serial data
    		‘ code depends on format of gps data
    RETURN
    
    scantable:	‘ scan the schedule and ring the bell if there is a match
    

    Need some details to be of any more help.
  • kwinn wrote: »
    The actual code would depend on the specific hardware you are using, the format of the GPS data, and whether you are loading the schedule table as part of the program load or by serial data using a subroutine in the program. The way I would approach receiving the time and scanning through the schedule would be:
    DO
    IF time = oldtime THEN GOSUB getgpstime
    ELSE
    	oldtime = time
    	GOSUB scantable
    LOOP
    
    getgpstime:	‘ get the time from the gps serial data
    		‘ code depends on format of gps data
    RETURN
    
    scantable:	‘ scan the schedule and ring the bell if there is a match
    

    Need some details to be of any more help.

    Im using only the NMEA format that recieving by basic stamp. Usually this is the format:

    $GNRMC,235951.800,V,2307.120372,N,12016.442898,E,0.00,0.00,050180,,,N*69
  • by the way mr. Kwinn i just need a clear sample. Can u make me one? ignore the format of time that getting on GPS antenna. Just a clear sample and it may help me a lot. Thanks for the help :smile:
  • kwinnkwinn Posts: 8,697
    by the way mr. Kwinn i just need a clear sample. Can u make me one? ignore the format of time that getting on GPS antenna. Just a clear sample and it may help me a lot. Thanks for the help :smile:

    I will see what I can do to help. Just keep in mind that I do not have a BS2 to test the code with.
Sign In or Register to comment.