Shop OBEX P1 Docs P2 Docs Learn Events
Event-triggered datalogger — Parallax Forums

Event-triggered datalogger

Pascal PPascal P Posts: 26
edited 2009-05-19 19:57 in BASIC Stamp
Hello,

I am building·a datalogger to timestamp events that occur at non regular intervals.
I guess another way to describe this application·would be to call it a portable punchclock, i.e. a·small device·with·one button. Everytime the button is pressed, the time at which the button is pressed is stored in·an EEPROM and a running total of the number of times the button has been pressed so far is displayed on a small LCD. Then,·at the end of the day, this datalogger is plugged in a computer·and·all the timestamps are turned into·a·.csv·file for analysis. I am using a Stamp BS2 to do that.

I've gone through·postings, appnotes, and·tech documentation and all the datalogger application I've seen·always seem to·be set to·record data at fixed intervals (e.g. every minutes).

So my question is: Has·anyone ever come accross an application like the one I'm building? I.e. a datalogger with non-regular intervals.

I'm enjoying·working on this·but if it's already out there, I would love it if I didn't have to re-invent the wheel.·Thank you for letting me know if you've come across·an application similar to the one I describe.

Cheers,
Pascal·

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-03-05 07:15
    In this case, it's not difficult at all to 'reinvent the wheel'. A simple loop like

    DO UNTIL IN8 = 1
    LOOP


    Will hold program execution until a button (in this case on pin 8) is pressed.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-05 07:50
    As SRLM says, then, in the loop, read the clock and log the time, and increment the EEPROM pointer to the location for the next record, and manage the LCD. Then wait for the button to return to the waiting state.

    SEROUT 16,$54,[noparse][[/noparse]"hit space to download data"]
    SERIN 16,$54,5000,ready2log,[noparse][[/noparse]char]   ' log data on timeout or any char except spacebar
    IF char=32 THEN  download     ' other options can be added to set the clock, etc.
    
    ready2log:
    DO
      DO : LOOP UNTIL IN8=1
        GOSUB read_time
        GOSUB log_time  ' includes updating the log pointer
        GOSUB lcd_service
      DO : LOOP UNTIL IN8=0  ' continue when the button is back in the resting state
    LOOP
    
    download:
      ' etc.
    


    If you have a real time clock chip with nonvolatile RAM, that is a good place to store the log pointer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com

    Post Edited (Tracy Allen) : 3/5/2009 4:36:18 PM GMT
  • Pascal PPascal P Posts: 26
    edited 2009-03-05 16:14
    Thank you both for your quick reply. Much appreciated.
    Cheers, Pascal
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-05 16:37
    One thing that may help with having your output go to a CSV file is to create it before it goes to the computer. If this will be a portable device and battery power is crucial then you will definitely want to log to EEPROM. A BS2PE would probably be best in this sense. However, to get the data to the PC an option is to use our Memory Stick Datalogger to write the data directly to a USB Thumb Drive in CSV format. I have done this myself and it is very easy. The documentation shows how to create the file on timed-intervals rather than event, however if you follow the above advice to simply dump the data to the Datalogger after you don’t have to worry about that part during the exchange. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Pascal PPascal P Posts: 26
    edited 2009-03-05 17:18
    That's a good idea Chris.
    Yes it will be a portable device. Plus we'll have a few of them in use outdoor and instead of having to bring them all back to a computer, I could just walk around with a memory stick and dump the data of each logger into the one stick and bring the stick back to the computer. I guess the only thing is to make sure each transfer doesn't overwrite the previous one but files are placed in the remaining empty part of the memory stick.
    Just to confirm, is this the memory stick datalogger you're refering to: http://www.parallax.com/Portals/0/Downloads/docs/prod/comm/MemoryStickDataloggerV1.1.pdf ?

    Cheers, Pascal
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-03-05 17:32
    There should be no problem with creating separate files on the memory stick datalogger. Each Stamp station would open or create a file with a unique name. As Chris says, the BS2pe would be a good option for this. It has 32 kbytes of eeprom, so if you use 1 slot of 2 kbytes for your program, that leaves 30 kbytes for your data. How much data will there be? I have made programs like this for logging the times of individual tips of a rain gage, for studies of rates of rainfall.

    Be aware that the memory stick data logger uses several Stamp pins and needs solid 5 volt power, so your field interface would need a plug for that. Transfer of a large amount of data takes time (which seems longer if you have to be standing there in the rain or hot sun!)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Pascal PPascal P Posts: 26
    edited 2009-03-05 18:37
    Thanks Tracy. In terms of memory space, each logger will have to store at most 5,000 entries, and each entry should contain time in a "HH:MM:SS", i.e. no need to store the day, and one second is all the accuracy I need. So I guess at 3 bytes per record, I am looking at 15 Kbytes (?). That's a good point about transfer time, I'll have to check that.
    Cheers,
    Pascal
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-05 20:34
    This project reminds me of the wand I used to carry around at one site as a Security Guard. On a ‘guard tour’ we’d have to swipe the reader past several magnetic strips located around the facility. At the end of the shift they would interface the device to a PC and download the data. The custom software they used would instantly red-flag certain behaviors such as unusually long delays between two scans or too long between tours. Anyway, what they used could easily be built using product we carry.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Pascal PPascal P Posts: 26
    edited 2009-03-05 21:16
    That's right. I looked into those patrol systems when I was checking what existed out there.
    What I am trying to do is I guess an hybrid between a tally counter and a punch clock. Hopefully this mixture will turn out alright [noparse]:)[/noparse]
    Thank you again for your input on this.
    Cheers, Pascal.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-05 21:57
    Are you trying to build such a system? I know if I was, I would probably use RFID tags and make the reader portable. I actually have an RFID Reader set up in a handheld case with an LCD and Keypad that was for a different system, but the case would be perfect for a portable system.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Pascal PPascal P Posts: 26
    edited 2009-03-07 21:19
    Hi Chris. Nope, the idea is to replace pen & paper to survey people movement like arrival at a bus stop for instance. It could probably be done by writting an application for a PDA, cell phone, or blackberry but I'm looking for something cheap, rugged and very easy to use.
    Cheers, Pascal.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-17 17:51
    Pascal said...
    I've now assembled the hardware·and it's is working. I.e. the·LCD displays a partial and a total tally that gets incremented everytime I press the "increment"·button,·the partial tally gets reset to 0 when I press the "reset" button, and the time when the "increment" button is pressed is read from the DS1302·and stored in a 16kB EEPROM. So I end up with a series of timestamps stored on my EEPROM.

    I now have to decide how to·transfer the data stored on my device onto a computer.

    I like the·Memory Stick Datalogger option because·after transferring the data from my handheld·device to a memory stick, the data stored in a .txt file could them be·read by any computer without any software.

    After reading the Memory Stick Datalogger & VINCULUM documentation, I still have one question:

    Does the Memory Stick Datalogger detects by itself when a memory stick gets plugged in?

    In other words, is there a way to detect when a memory sticks gets plugged in·by reading one of the four pins used to communicate with the Memory Stick Datalogger (TX,·RTS, RS, or CTS) and then start transferring data? Or do I need to have another button on my device that the user should press to start the transfer?

    The reason I'm asking is that I would prefer if I didn't need to have one·memory stick plugged in each one of·my devices all day long but rather have only·one memory stick, go around to plug it in each device,·end up with one memory stick with a series of files, one from·each device.

    Please let me know if this doesn't make sense.
    ·· First a suggestion...you can format the data going into the memory stick to make it friendly with any specific application on your PC.· For example, I have used it to generate a .KML file for a GPS tracker so that when I plug the memory stick into the PC I can simply click on the file and it will load right into the application.· For Excel files I save them as .CSV and use TAB delimiting.· Anyway, this makes it so you don't have to copy from a text file and paste into something else.

    ·· Now, the answer to your question is actually covered in·both of the programs I wrote for the datalogger.· The Demo in particular waits for the memory stick to be present before contuing on with the program.· It sends a command to the datalogger to see if it is ready.· This is easily done by sending a CR (ASCII 13) to the device and waiting to see if it replies with a prompt ">" symbol.· If you check the firmware spec you can see that different messages are returned when a drive is present as when·not.· We can simply check the first character to make this determination.

    ·· As a side note...your program should also make sure the drive is done being written to and has closed the file before you remove the memory stick.· Failure to observe this precaution could cause the data on the memory stick to become corrupted and/or lost.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Pascal PPascal P Posts: 26
    edited 2009-03-18 03:54
    Got it: "Send CR to see if drive is present", it was clearly indicated. Sorry about that.

    Hopefully my next post will be to announce the rest of the program is working [noparse]:)[/noparse] Thanks again for your help.

    Cheers, Pascal.
  • Pascal PPascal P Posts: 26
    edited 2009-05-17 19:31
    It's working [noparse]:)[/noparse]

    Hello.·I just want to thank you all for your help. My little·time logger is working. It stores in a .csv file the time at which a button is pressed and download the file on a memory stick. It's basic and could use some improvement I'm sure but it's a huge leap for me since I didn't know what a microcontroller was 4 months ago.

    In the spirit of sharing please find below the completed code.

    Cheers,

    Pascal
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-05-18 06:55
    Pascal P,
    ·
    Several years ago I was involved in a field study where we needed·a data logger to monitor the change of state·of a switch that would be·opened or closed.· The unit was battery·operated, and needed to last for about 4 months.· If you find the need to extend your battery life on your portable data logger, here is a possible hardware·solution that monitors a switch using only 160uA of quiescent current.· If·a Switch is opened or closed the circuit creates a pulse that powers up the BS2.· In my data logger, the BS2 also managed power to other connected devices.· When the BS2 was powered up it woke up an external RTC that otherwise would run in trickle charge mode.··The BS2 would read the time from the RTC and then the BS2 would shutdown the·RTC·back into a trickle charge mode.· Next the BS2 would turn on an external memory·where the time/date, and switch position were logged.· Following that, the BS2 would·power down the memory, and eventually the BS2·would power itself·off.· Another "switch event" would start the cycle all over again.
    ·
    Attached is a schematic of the 160uA·quiescent current·switch monitor I used in my data logger.
    ·



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    1063 x 797 - 258K
  • SRLMSRLM Posts: 5,045
    edited 2009-05-18 07:12
    @ Beau

    Neat! I was thinking along similar lines the other day: use a microcontroller I/O pin hooked up to a transistor which is on the power line. It's as if the BS2 was pulling itself up by shoestrings: it uses it's output into the input, which is to the output,... Glad to know that it is a valid approach.
  • Pascal PPascal P Posts: 26
    edited 2009-05-18 17:34
    Thank you Beau, that is very usefull because that's actually one of the feature I didn't know how to implement. For now my little 9V battery only lasts 1-2 days and I hoping to figure a way to make it last longer.

    And I think you also helped me with the RTC because I read about the trickle charge mode but I didn't know how to use it. Right now, I have to re-enter the "real" time in the RTC everytime I reset or turn on the unit but I was hoping the RTC could be powered separately and I would only have to set the time once. Is that what power trickle allows?

    Cheers,
    Pascal
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-05-18 20:25
    Pascal P,

    I had to double check.... I used a DS1302 for the timekeeping chip. Vcc1 (Pin8) was connected to the main power via a current limiting resistor and capacitor combination. Vcc2 (Pin1) was connected to one of the Stamp I/O's. The actual "trickle charge" feature of the DS1302 was not implemented, other than the availability of Vcc1 and Vcc2 and how the chip treats those two pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Pascal PPascal P Posts: 26
    edited 2009-05-18 23:16
    Thank you Beau,

    I also use a DS1302. I will rewire and have Vcc2 connected to a small battery that will only power the timekeeping chip when everything else is sleeping.· I really appreciate your help on this.

    Now that my prototype is working, I'd like to create a new version in which I replace the development board by the BS2 alone to save room. I ultimately would like this device to be hand held (e.g. the LCD strapped to the forearm and the switch attached to a glove) so that all the electronics·that is currently is in the big box (shown in the attached picture) ends up inside the enclosure where the LCD is. Would you have some recommendations on how to proceed on this?··

    Take care,
    Pascal
    800 x 600 - 80K
    800 x 600 - 109K
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-05-18 23:40
    Pascal P,

    Vcc1 connects to your battery for low power mode of the DS1302.... Vcc2 is when you want to wake it up.

    As far as size, our units fit into something about the size of a wrist watch but we didn't have an LCD to contend with.

    We used a pre-programmed BS2-interpreter chip with just the bare essentials. i.e. just memory, and Xtal ... no brownout, serial interface, or regulator. Unit was powered with a 3V lithium battery.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Pascal PPascal P Posts: 26
    edited 2009-05-19 01:27
    I see. That way you don't drain the battery connected to Vcc1 when you do the data transfer.
    For the BS2-interpreter, how do you go about pre-programming it? (that's where it's obvious I'm really new to this business, apologies if my questions are really dumb).
    Is it done by Parallax, or there is way for me to do it myself?
    Cheers,
    Pascal
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-05-19 02:44
    Pascal P,

    The BS2-Interpreter is programmed by Parallax and can be found here. You say that you are new at this, but are you new to electronics? That particular BS2-Interpreter was in surface mount, but a 28-pin DIP version also exists.

    When we were in the design phase we used the DIP version, and then found a local board house to fabricate and populate the boards for us with the surface mount components.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Pascal PPascal P Posts: 26
    edited 2009-05-19 16:29
    Hi Beau,

    To make a long story short, I think I may qualify as novice-intermediate in electronics. I'm a mechanical engineer and I had some basic training in electronics so I understand the basic concepts and components but I never had to apply it. So when I came up with the idea of this counter I bought the What's A Microcontroller? course from Parallax, went through the book (excellent by the way), then bought the components (RTC, EEPROM, Memory Stick Datalogger, LCD), wired everything on the development board and assembled the code that I posted. I'm still amazed that I managed to do it. I chose Parallax because I had found an article saying the Parallax development kit was the most user friendly and best for beginners and I am glad I went down that road, you guys have a really good product.

    Now, I vaguely remember how to make PCB from a junior high course and I've found a freeware that looks pretty good (http://www.expresspcb.com/) but there is still (at least) one thing I don't understand: If I get just the BS2-Interpreter in DIP version along with an 2kb EEPROM and a voltage regulator which seems to the bare minimum I need, how will I transfer the code I wrote? Can I use the development board to transfer my code? I'm not even sure where it goes, i.e. in the 2kb EEPROM? or in the interpreter itself? Right now, I'm bit lost and I'm not sure how to proceed.

    Cheers,
    Pascal
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2009-05-19 18:14
    Pascal P,

    Please refer to this schematic:
    www.parallax.com/Portals/0/Downloads/docs/prod/schem/BS2revJSchematic.pdf

    The schematic has the circuitry for the serial communication to the PC built in to the BS2-Module
    and requires a 4-pin (SOUT,SIN,ATN,VSS) programming connector. Optionally you can move the serial communication circuitry into the program connector itself. This would require a 5-pin connector(TX,RX,RST,VSS,VDD) to make the proper connections.

    All components can be purchased individually through Parallax.

    ExpressPCB is fine for PCB's but I don't think that they will populate the boards for you. Depending on how many units you want to have made this may or may not be a viable option.

    Your program is loaded into the EEPROM and is programmed through the serial connector to the PC in combination with the BS2-interpreter chip.



    First, I would do all of your debugging and make sure that everything works with the BS2 module. You may find that the BS2 module's size is just right for your application. In my data logger, we needed something about 1 square inch, so a re-work was necessary in order to get things to fit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Pascal PPascal P Posts: 26
    edited 2009-05-19 18:45
    Alright. I think I understand now. Thank you very much for your help Beau, I really appreciate it.
    Space is not that crucial at this point so I think I'll stick with the BS2 module for the next version.
    And thanks for the tip about debugging every first with the module and ExpressPCB.

    One last question and I will leave you alone:
    Cost-wise, a BS2 module is about $50 while a BS2-chip is $12, and the EEPROM, Resonator, Brown-Out Detector, & Voltage Regulator about $1 each.
    Am I correct that down the road if I assemble the microcontroller part of the device using the individual components instead of using a pre-assembled BC2 module, I could expect the cost to about $15 instead of $50? Or am I missing something here?

    Cheers,
    Pascal
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-19 19:31
    Pascal,

    That is correct and what is intended for commercial or at least production of an application. The BASIC Stamp Module itself is really a development tool. Production applications should utilize the components on the target board to reduce cost. In my applications before coming to Parallax I was able to keep the cost of the controller below $15.00 by integrating the Interpreter, Resonator and EEPROM onto my main board which also meant no additional regulator was required. Further cost savings were realized by using the USB2SER development tool for programming the boards. This meant not having to include RS-232 circuitry. Schematics for this are available in the Completed Projects Forum under the sticky thread. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Pascal PPascal P Posts: 26
    edited 2009-05-19 19:57
    Very well. I think I'm all set now. Thank you Chris & Beau for your help. You guys have been amazing.
    Cheers, Pascal.
Sign In or Register to comment.