Data Logging higher speed

Hi Guys

I am new to the forum but I have searched around and while I did find an answer that was close, I’m not experienced enough to apply it to my situation.

I am developing small rocket motors, the type used to launch model rockets a few hundred/thousand feet into the air. I have a dynamometer that measures rocket thrust over time, which I put together from a project on github. I had to make some changes because I wanted to do more than the original project did.

The original project used a PC/Laptop etc to connect to the USB port. Using Serial Monitor it displayed a list of the dyno readings over a 10 second period. It also listed the start time ( millis()) and end time for the data collection run. The dyno is set to produce 80 readings per second so the 800 reading run should take 10 seconds to complete and before I tried altering the code that was what happened. The idea is that the data from Serial Monitor is copied into Excel to produce a graph of thrust over time.

I wanted to be able to use the dyno in the field without a laptop and cable. For one thing, the cable length makes the laptop rather closer to the rocket motor than I’d like. What I did was include code to write to an SD card. The original section of the code that reads the data is here:

Serial.print("Start time, ms: “);
Serial.print (millis());
Serial.println(” ");
Serial.println();
for (int i=0; i <=800; i++){ //800 samples at 80sa/sec = 10 seconds theoretical
scale.set_scale(calibration_factor); //Adjust to the calibration factor
Serial.println(scale.get_units(), 1);
}
Serial.println();
Serial.print("Stop Time, ms: ");
Serial.print(millis());

My modified code is here :

Serial.print("Start time, ms: “);
Serial.print (millis());
Serial.println(” ");
Serial.println();
for (int i=0; i <=800; i++){ //800 samples at 80sa/sec = 10 seconds theoretical
scale.set_scale(calibration_factor); //Adjust to the calibration factor
File dataFile = SD.open(“datalog.txt”, FILE_WRITE);
dataFile.println(scale.get_units(), 1);
dataFile.close();
Serial.println(scale.get_units(), 1);
}
Serial.println();
Serial.print("Stop Time, ms: ");
Serial.print(millis());

So the addition of the lines that write to the SD card increase the collection to about 18 seconds. There are still 800 samples but the resolution is lower because there’s a delay between each reading.

I can still use the system as it is but as most rocket motors only run for a couple of seconds I’d rather have a shorter run-time. I’d be really grateful if someone could suggest a way to record to the SD more quickly, but in a way that a novice programmer can understand.

Thanks in advance.

Thermocline

Open and close your file once, not on every iteration of loop.

Hi Wildbill

Thanks for the suggestion.
I modified the code like this :

Serial.print (millis());
Serial.println(" ");
Serial.println();
File dataFile = SD.open(“datalog.txt”, FILE_WRITE);
for (int i=0; i <=800; i++){ //800 samples at 80sa/sec = 10 seconds theoretical
scale.set_scale(calibration_factor); //Adjust to the calibration factor
dataFile.println(scale.get_units(), 1);
Serial.println(scale.get_units(), 1);
}
dataFile.close();
Serial.print("Stop Time, ms: ");
Serial.print(millis());
digitalWrite (ledPin,LOW);
digitalWrite (igniterPin,LOW);
Serial.println();

It made a very slight difference. The run-time was down from about 18.5 seconds to 17.8 seconds.

Any other ideas ?

Thermocline

What baud rate is your serial port set to? Also, why are you printing anything in the loop? You can examine the data after the flight.

I suspect that the calibration only has to be done once, so you can move it out of the loop.

Hi Wildbill.

Baud rate is set to 9600
PS - I set the baud rate higher but it made no difference.

I guess the reason the write is done within the loop is to get the data to the laptop via the Serial Monitor screen, which was the way the original sketch was written.

Without the SD card write code included, the run-time is almost exactly 10 seconds. In fact if I just rem out the line :

dataFile.println(Scale.get_units(), 1);

The run-time reverts back to 10 seconds.

So is there a way to store the date during the run and then write it to the SD card later ? The data consists of 800 numbers between -100 to +10000.00

Thermocline

But that's the only important line isn't it?

Comment out the serial print and move the calibration above the for loop.

It won't make much difference, but you can substantially increase the serial baud rate too.

Hi Wildbill

OK that made a huge difference. The run-time is now 8.9 seconds. The code now looks like this:

File dataFile = SD.open(“datalog.txt”, FILE_WRITE);
digitalWrite(igniterPin, HIGH);
Serial.print("Start time, ms: “);
Serial.print (millis());
Serial.println(” ");
Serial.println();

scale.set_scale(calibration_factor); //Adjust to the calibration factor

for (int i=0; i <=800; i++){ //800 samples at 80sa/sec = 10 seconds theoretical
dataFile.println(scale.get_units(), 1);
}

dataFile.close();

Serial.print("Stop Time, ms: ");
Serial.print(millis());

digitalWrite (ledPin,LOW);
digitalWrite (igniterPin,LOW);
Serial.println();

}

The only concern with that solution is that I can no longer get a backup set of data on my laptop at the same time as the SD card is written. In the field i won’t be using the laptop but at home I have a decent shield and I like to control things from the laptop rather than the trigger board.

I think the problem is that because I’m using a UNO there isn’t any storage capacity big enough to write the 800 data to and then subsequently write them to the SD card. For the time being I have to rely on the data being written to the SD card and analysed later.

I’m also a little wondering why the data run-time is now less than 9 seconds where it was almost exactly 10 before. I tried it with various baud rates and that made no difference.

Thanks

Thermocline

It looks as though the thing taking the time is scale.get_units(). I think you can safely put the serial print back in the loop, especially if you jack up the baud rate.

What library are you using that provides the scale function?

Saving the data in RAM won’t get you much - the SD library is already buffering it for you in a 512 byte area.