Trouble getting data from a thermocouple via raspberry pi

2 views (last 30 days)
I've been unable to get a full read a type K thermocouple via a MAX6675 digitizer. I am able to get data via the SPI channel of my raspberry pi 3. I belive the issue is that Matlab is not reporting the full data from the digitizer.
I'll share the code I've been using:
mypi = raspi
myspidevice = spidev(mypi, 'CE0',0)
data = [0,0];
count = 3
i = 1
while i < count
count = count + 1;
output = writeRead(myspidevice, data, 'uint16');
x(i) = count;
y(i) = output(1,1);
t(i) = i;
plot(x,y,'x');
xlabel('Time(s)')
ylabel('output')
pause(1);
i = i + 1;
end
end
There's a couple odd things that are happening. First, you can see from the plot below that the output trends down as the temperature goes up. In the plot below, I grabbed the thermocouple in my hand to track the output over time. There's a real response, and if I let go it slowly drifts back in the opposite dirrection. The issue is that it's cycling through values from 0-64000. As the temperature goes up, the reported value drops and if it dropps past 0, it cycles up to 64000 and starts dropping again. I suspect that the data is someone cutting off and not all of it is being reported. The other odd thing is that I would have expected values to rise since at 0 degrees celsius the digitizer is supposed to report a value of all zeros and max out at +1023.75 celsius with all ones reported. According to the datasheet that came with the thermocouple(attached), it takes the analoug signal and spits out a 12 bit digital signal.
I'm confident in my hardware setup. I spent a couple weeks troubleshooting things on that end, but I am getting a real response so I'm resigned to the idea that the built in SPI functions in matlab aren't processing the 12 bit input correctly. Digging into some of the functions, it looks like the SPI channel is looking for 8 bit words. I don't know if that's an issue in this case. I'm constrained in this project to use the raspberry pi, so I need to figure out how to make it read correctly on Matlab's side.
Apart from the oddness that the data output tends in the opposite dirrection that I expected it to do, I wonder if Matlab isn't somehow truncating the data as it comes in. I really can't see what's so special about the data range of 0-64000.

Answers (0)

Categories

Find more on Raspberry Pi Hardware in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!