Go Down

Topic: Making an Arduino-based Vehicle Data Acquisition (DAQ) module (Read 1 time) previous topic - next topic

VroomVroom

Thanks Paul, I had a look at ring buffers . Would you store all the values from the sensors as a string then store that into one element of the ring buffer array or have the integers read from analogread each stored to one element of the array? Any good examples you know? I saw one that was pretty complex and daunting but will try to learn how it works. I guess the main problem I've run into now is that when I pull the power, nothing is written! (as the close file command is after the loop). So I think I should have two loops and write regularly to SD card.. otherwise whenever the car is turned off the data logger will die and all data since the last file close command will be lost :~.

PaulS

Quote
Would you store all the values from the sensors as a string then store that into one element of the ring buffer array or have the integers read from analogread each stored to one element of the array?

Depends on the purpose of the file. If the file is to be used on a PC, it needs to be a text file. Converting the data from integer to string format takes time and more memory, so I would do that only at the time that I was writing the data to the file.

I'd have a ring buffer of type struct XXX, where the structure had members for each of the sensor's output. Advancing the pointers is just the same as using a collection of ring buffers of type int, and the data access is only marginally more difficult (x.y[n] instead of x1[n], x2[n], x3[n], ...).

If you can afford to loose any data, you could, on each pass through loop, write the next record if there is one, and see how long the file has been open. If more than x seconds, close the file, and reopen it.

Are you using an interrupt to know when it is time to sample the sensors again?

VroomVroom

Using structures is definitely a good idea. Losing data is not ideal as the data just before a power loss is probably the most important - however I have worked around this to ensure that when the mains power goes off there is a backup supply that will be able to power the logger for a few seconds (enough to detect a power failure and close the file on sd).

At this stage I am not using interrupts but just sampling as quick as it will let me inside a loop with analogreads. I will need to use interrupts to sample pulses from my digital sensors. Not entirely sure how I go about using interrupts to sample analog channels (timer interrupts?)

retrolefty

Quote
Not entirely sure how I go about using interrupts to sample analog channels (timer interrupts?)


I found the mstimer2 library to be a easy way to get started and comfortable using arduino user interrupts avalible on pins 2 and 3.

http://www.arduino.cc/playground/Main/MsTimer2

VroomVroom

Thanks, I had a look at Mstimer2 however, it didn't really work for me as it kept repeating even when I specified it to only run for one second inside a while loop. Firstly, not entirely sure it does work properly on a mega2560 (doesn't say it does anywhere although it does for other chips).

I went back to trying to figure out a simpler scheme with analogreads and digital interrupts - and a more complex buffering scheme which will hopefully make it faster. Arrays and structures are making things tricky though (tried linklists with malloc etc.). Will continue to work on it and keep updating progress..

Go Up