Hello.
I'm trying to send thermocouple measurements to a file on my computer and measure the time response of the sensor by dumping it in ice-water. I have been successful (sort of) but there are a couple areas I don't understand and would like some assistance.
Below is my current code (thanks in large part to Adafruit). I am using a program called "Gobetwino" to save the recorded data to a text file on my computer.
I would like to sample and send data to Gobetwino as fast as possible without messing with the default Arduino clock speeds. I have only been successful, however, in recording 1 temp measurement every 67 milliseconds.
Gobetwino requires the serial message to be sent as a string in a very specific format. I am sending both the measurement and the millis() to Gobetwino as a message. I have a high level of confusion in understanding how many bits this means I am actually sending.
For example, the temperature measurement is usually in the form of "25.34" or "0.03" while the millis() variable might equal "564" or "1113456". My confusion is that if more or less integers are present, I don't understand how many bits of data these values represent?
I did a sizeof() command on both the millis() and temperature strings and both returned a "6" each. I believe this means I am sending a total of 12 BYTES (which would equal 12 x 8 = 96 BITS per message).
Taking 9600 BAUD, (or 9600 bits/sec) and dividing by 96 bits/message = 100 messages/sec
Dividing 1 second (1000 milliseconds) by 100 messages = 10 milliseconds/message
This is nowhere near the 67 milliseconds per message I'm actually recording. I understand the code itself will take some time to run, but I don't believe it should take that much time? I'm missing something crucial here in my understanding of strings, bits, and bytes, so any help is greatly appreciated. The strange part is that the 67 milliseconds between readings doesn't change when I change the BAUD to 115200 either.
Finally, it's really annoying that I'm sending the temp reading and the millis() as basically one string of numbers. It's not a huge deal because when I import the text file into excel I can delineate the data columns by fixed width. The problem, however, is when the temp drops from a two digit number to a 1 digit number (such as from 25 to 1), the text file doesn't add a leading zero to the single digit number (01) so the column spacing gets off and I have to manually go through all the data and add leading zeros.
EXAMPLE:
TEMP|MILLIS
25.43|564
22.32|668
4.687|69 -----> Column now off by 1 position
0.029|09
The solution, I think, would be to add a "deliminator" such as a "," between the strings when it is sent to Gobetwino. Unfortunately, I can't figure out how to do this in Arduino code.
Any and all help is greatly appreciated. I'm also extremely open to suggestions on how to make this code run and capture data more effectively.
Thanks in advance.
Respectfully,
Chase Brumfield
APOLOGIES: Just realized I left out a crucial piece of informaiton. I am using the MAX31855K found HERE.
/***************************************************
This is an example for the Adafruit Thermocouple Sensor w/MAX31855K
Designed specifically to work with the Adafruit Thermocouple Sensor
----> https://www.adafruit.com/products/269
These displays use SPI to communicate, 3 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
//The original Adafruit code has been edited by Chase Brumfield for this particular
//application
//Calibrate the thermocoupple and change variable "correction factor" as needed
//for more accurate readings
#include <SPI.h>
#include "Adafruit_MAX31855.h"
// Create a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO 3
#define MAXCS 4
#define MAXCLK 5
int correction_factor = 2; //specific to thermocouple used, amount the thermocouple
//is reporting higher than real temp [C] (for calibration)
unsigned long time; //used for millis() at bottom of code
int num; //used as variable to display length of strings sent to "Gobetweeno"
// initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);
void setup() {
while (!Serial); // wait for Serial on Leonardo/Zero, etc
Serial.begin(9600);
Serial.println("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
}
void loop() {
double c = thermocouple.readCelsius()-correction_factor;
if (isnan(c)) {
Serial.println("Something wrong with thermocouple!");
} else {
/////////////////////////////////////////////////////////
//Below are commands for saving data with "Gobetweeno"
/////////////////////////////////////////////////////////
time = millis();
String stringTime = String(time); //converts "time" variable (milliseconds elapsed) into a string
String stringC = String(c, 2); //Converts variable "c" to a string type and names it "stringC"
//Serial.println(stringC);
//num = sizeof(stringC); //trying to understand the number of bytes sent to serial
//Serial.println(num);
//Serial.println(stringTime);
//num = sizeof(stringTime); //trying to understand the number of bytes sent to serial
//Serial.println(num);
Serial.print("#S|TEMPDATA|["); //The next 3 lines are for sending to "Gobetwino"
Serial.print(stringC); //See "Gobetwino" .pdf manual for clarification
Serial.print(stringTime); //See "Gobetwino" .pdf manual for clarification
Serial.println("]#"); //See "Gobetwino" .pdf manual for clarification
//delay(10);
}
}