Hey guys, I thought I would share this with everyone. I was originally looking to write a csv file and import it to excel to plot or otherwise manipulate the data however that proved a bit more difficult than I previously thought so I found and modified some code online which allows the Matlab to read the serial output. I believe octave is very close to Matlab's syntax so you may be able to use that if you don't have or want to purchase Matlab. So basically you set the circuit as described by Adafruit using the max31855 breakout board and a K type thermocouple. load this code into the arduino and leave the usb connected to the computer
Arduino:
#include <SPI.h>
#include "Adafruit_MAX31855.h"
// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:
// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define DO 3
#define CS 4
#define CLK 5
Adafruit_MAX31855 thermocouple(CLK, CS, DO);
void setup() {
Serial.begin(9600);
// wait for MAX chip to stabilize
delay(3000);
}
void loop() {
double c = thermocouple.readCelsius();
if (isnan(c)) {
Serial.println("Something wrong with thermocouple!");
} else {
// Comment out if you want Farenheit
Serial.println(c);
}
// Uncomment below to read in Farenheit
//Serial.println(thermocouple.readFarenheit());
// For longer test increase delay to avoid memory problems
delay(0);
}
then copy this script into a matlab I believe the only thing you will need to change is the COM port you are currently using.
Matlab:
% MatLab <--> Arduino ,datalogger
tic;
clc;
numSec = 120; % Controls duration of test in seconds
Time = [];
Temp = [];
s1 = serial('COM4'); % define serial port (COM#)
s1.BaudRate = 9600; % define baud rate
set(s1, 'terminator', 'LF'); % define the terminator for println
fopen(s1);
try % use try catch to ensure fclose
% signal the arduino to start collection
w = fscanf(s1,'%g'); % must define the input %d,%g, or %s, etc.
if (w == 'A')
display('Collecting data');
fprintf(s1,'%s\n','A');
end
i=0;
t0=tic;
while (toc(t0) <= numSec)
i = i + 1;
Time(i) = toc(t0);
Time(i) = Time(i) - Time(1);
Temp(i) = fscanf(s1,'%g'); % must define the input %d, %g or %s, etc.
end
fclose(s1);
% Plot Temp Vs Time with parameters
figure
plot(Time , Temp)
title('Temp Vs. Time')
xlabel('Time [Sec]')
ylabel('Temp [Deg C]')
axis([0 numSec min(Temp)-10 max(Temp)+10])
catch me
fclose(s1);
end
toc
couple of quick notes on settings:
-
The delay at the bottom of the Arduino sketch controls the frequency in which data points are sent to Matlab
-
In Matlab the duration of the test is selected (in seconds) by the variable numSec. With the current settings it takes 1776 data points in a 2 min time frame. So this two settings may need to be adjusted for longer duration tests.
In the future I would like to get the everything to run of a GUI which can control start, stop, and different trials. It would also be nice if it had a graph which can be cycled through a few different graphs.
Thanks for reading, hopefully this post will help someone trying to tackle a similar project. I also welcome any feedback.