Go Down

Topic: Rainfall data logging (Read 2614 times) previous topic - next topic

razadams

Aug 19, 2009, 01:06 pm Last Edit: Aug 19, 2009, 01:09 pm by razadams Reason: 1
Hi,

I have a rainfall meter that I have wired up with a reed switch and into the digital input of arduino duemilanove. I have it wirelessly transmitting the data back to pc via an Xbee shield and have it updating a counter, however the pc will not be running all the time.

I need the arduino to hold the counts in memory until I clear it after calling the count via VB6, and most importantly I need to associate the counts with a time. I need to know when it was that the rainfall occurred. I have to be careful about how much memory I am utilising by doing this and am worried adding time and date to each reading will  utilise all the memory in no time at all. I am a beginner when it comes to programming and need some guidance please.

Cheers

jluciani

#1
Aug 19, 2009, 03:04 pm Last Edit: Aug 19, 2009, 03:16 pm by jluciani Reason: 1
You do not need to add time and date to each reading. Pick a date and time
and count the number of seconds since that point in time. This is called the epoch. Your
count will be in epoch seconds. Using a long integer (4 bytes) should give you
2 billion seconds. You convert back to YY-MM-DD HH:MM:SS when you display the data.

There should be a VB library for converting from epoch-seconds to date-time. If you
choose the same epoch your conversions will be easier.

(* jcl *)


razadams

#2
Aug 19, 2009, 03:21 pm Last Edit: Aug 19, 2009, 03:22 pm by razadams Reason: 1
Cool so do I have to write say the current time to a variable when I start, and update that after each time I download to signal the start date and time? Also any pointers on setting up the array I write the data to? I actually have two arrays I need, one for an analogue sensor at pre defined times and one for the rainfall, which is erratic. I have searched and searched for an answer but I must be searching for the wrong thing. For instance, I think I
a) define the array, but should it be for both readings or have a seperate array for each
b) with rainfall do I say write variable for current time, then
    start counter
    when bucket tips write to array counter and maybe a "1" to indicate a tip has occured
    restart counter from 0
c) with other sensor, say is a temperature sensor I get temp every 15 minutes and need to write this to an array also, but I already know it will be every 15 minutes but do I do same thing for epoch timing?

Again I appologise for my questions which may seem very simple to you all but to me they are quite the opposite. I still have no idea how to get this to VB :) And yes I am in over my head

jluciani

What you need is a clock routine or a real-time-clock IC. It depends on how much
accuracy you need. It may be possible to just do a loop with a delay.
There are examples of integrating a RTC using the DS1337 IC on the Arduino site.

For an interrupt routine you would trigger every second. You synchronize the epoch-second count with your system after you download. The interrupt routines increments the epoch-second count by one every time it triggers. You will have to evaluate the accuracy.

For a loop you could do something like ---

while(1) {
 <read sensor>
 <store data record>
 <delay>
 <increment epoch-seconds count>
 <if time to download break>
}

Not very accurate but it could get you started quickly.

For the data storage I would use a struct. Something like --

struct datarec {
 unsigned char value;
 unsigned long timestamp;
};

Make an array of datarec.

(* jcl *)

razadams

Thanks heaps, I am more confused now but will go away and see if I cant get that much working, never heard of a struct before by the way so thanks. I do not need split second accuracy, within 15minutes is fine. Is indicative more than anything, just need to be able to say kind of when, not exactly when. Bit rough n ready but at the moment just want the bare bones working. Get data, store data until is called, get it to PC for analysing, make decisions.

Anyway thanks again.


jluciani

You're welcome.

For getting started in C I would get --

The C Programming Language
by Brian W. Kernighan, Dennis M. Ritchie
ISBN-10: 0131103628
ISBN-13: 978-0131103627

A much better reference but a more difficult read is --

C: A Reference Manual
by Samuel P. Harbison, Guy L. Steele
Prentice Hall; ISBN: 0133262243

(* jcl *)

razadams

#6
Aug 20, 2009, 03:23 am Last Edit: Aug 20, 2009, 03:30 am by razadams Reason: 1
For those that read this thread and may want to read the book suggested here is a link to the pdf.

The C Programming Language
by Brian W. Kernighan, Dennis M. Ritchie

http://www.lama.univ-savoie.fr/~theyssier/edocs/Prentice%20Hall%20-%20The%20ANSI%20C%20Programming%20Language%202nd%20ed.%20by%20Brian%20W.%20Kernighan%20and%20Dennis%20M.%20Ritchie.pdf

and "Learn C in 24 hours"....
http://aelinik.free.fr/c/

Go Up