Running a Datalogger in different Modes

Hi all,

I am pretty new to the Arduino so be a little patient if the question has been asked may times. I have looked thru many pages but were unable to find an answer to my question.

I have a datalogger made up which saves data to an SD card.It works fine in its basic form. Now I have a sketch that can read data from the SD card and output it to a terminal program which saves the data to a txt file on the computer.

What I want to do is start basically merging them into one. I was thinking of using a switch as sort of a mode switch so that Serial is not enabled all the time just sitting there waiting for a command from a terminal program.

Would it be easier to make the 2 programs into like 2 separate functions and the loop basically directed which to use depending on the mode switch.

Or would there be a better way?? Any help would be appreciated.

Thanks in advance.

Craig

Sounds like a perfectly plausible method, although I'm not quite clear why you need a switch and a command from the terminal program. I'd have the system default to recording data to the sd card. When the terminal command arrives, stop recording and send the file, then continue recording. Perhaps I didn't quite get the requirement.

so that Serial is not enabled all the time just sitting there waiting for a command from a terminal program.

I don't follow this. In order to ever be able to send/receive serial data, you'll need Serial.begin() in setup.

Reading the state of a switch on each pass through loop takes longer than calling Serial.available() to see if there is serial data to read.

Reading serial data, and deciding what to do, requires less hardware, and has less impact on the speed of the program than reading a switch.

Oh ok I thought that the Serial operation would be a lot slower operation and use more power that a switch would. I was thinking that the serial mode would be used to set RTC, copy file, erase file and general stuff like that. Ok will have to play around some more.

Thanks very much for you input it was much appreciated.

Hi,

something basic that I have done in the past is have the sketch output the contents of the SD Card in the set up function. As a serial connection resets an UNO anyway, it will run setup and output the logged data automatically everytime it is connected to the serial monitor. It only does this for new connections, so you can leave the sketch running and logging data after the initial connection.

This is how I transfer logged data from my RC cars to the PC, by running the UNO in the car, then after a session I connect a USB cable start the serial monitor and upload the data.

Very simple and does what you want.

Duane B

rcarduino.blogspot.com