MAX 31856 and Matlab

Hello all,

I'm working on a project including the measure of temperature and simultaneous control of current sources. For that I pilot an Arduino Uno board via matlab's Arduino Support Package. Most of the measures are made by K type thermocouples and collected via analog pins and no problem arose. One specific measure requires a T type thermocouple, for that I got a MAX 31856 breakout board. The measurements are totally fine with the Arduino code given in the examples but I can't seem to make the switch to matlab.

By looking around the forum I found a matlab code for MAX 31855:
Code: Select all | TOGGLE FULL SIZE
`%Thermocouple Dataclear alla=arduino('COM4','Uno','Libraries','SPI');therm = device(a,'SPIChipSelectPin','D10'); %Chip select pin D10, MISO is ICSP-1, SCK is ICSP-3, MOSI(not used)t=0;temp=0;time=0;x=[];for i=1:1000dataIn = [1 1]; %write 2 pieces of info in order to receive 2 pieces of infodataOut = writeRead(therm,dataIn,'uint16'); %uint16 is the largest integer you can use with this function therefore you need 2x= [ x ; dataOut];bytepack=uint32(dataOut(1)); %since there are two separate pieces you need to combine them to a 32-bit integerbytepack=bitshift(bytepack,16); %data(1) is the 1st half and is converted to uint32 and the data is shifted to the correct side.z = bitor(bytepack,uint32(dataOut(2))); %data(2) is the 2nd half and bitor() is used to place this into the correct side of uint32z = dec2bin(z,32); %create a 32-bit binary numbercentigrade=bin2dec(z(2:14))*0.25; %from the MAX31855 datasheet, bits 18-31 is the temperature in celcius. These number are referenced backwards in matlab.% I left out the 1st bit because it was the signed integer, which I didn't need.% Multiplied by 0.25 since the datasheet says the LSB is 0.25°C.%Check the adafruit Max31855 library for an in-depth look at processing these bits.temp = [temp, centigrade];t=t+1;time = [time, t];plot(time,temp);drawnow;end`

The resulting plot only gives a 0 value for "temp". By looking around the different variables I found that it is the first variable "dataOut" that gives a [0 0] vector (found with the x= [x ; dataOut] vector). So the problem apparently comes from either the writeRead function or the device function in itself.

If anybody have experience in this matter It'll be a huge help.

Carton

Posts: 1
Joined: Thu Feb 20, 2020 10:22 am

Re: MAX 31856 and Matlab

Hey, did you ever figure out what was going on with this?

jfindleyderegt

Posts: 2
Joined: Mon May 10, 2021 1:57 pm

Re: MAX 31856 and Matlab

I've gotten the above code block to work. First, I had to install the "Instrument Control Toolbox". Then I amended the "writeRead" statement. It refers to "therm", which was never defined in the context. This page: