Reading out SPI-Sensors via Arduino
9 次查看(过去 30 天)
显示 更早的评论
Hi Everyone,
i have an Issue using my Arduino with SPI K-Type Sensors for Temperature logging. Before I start explaining my Problem, i want to make shure, that using the Arduino IDE is no option for me. I want to use the Temperature Data for building a controller using MATLAB.
The code I'm using here actually does work, but the Data i want to read comes back in a form of a 1x2 uint8 Array. Reading my Datasheet, I assume, that a [0 0] means 0°C and [255 255] means 1023.75°C. Testing the Sensor with warm Hands leads to one of the numbers increasing fast to 255, one going 1 up every 256 the other one is increasing. According to this, i made this loop giving out a "guesstimated Temperature".
I also read the Datasheet ( https://datasheets.maximintegrated.com/en/ds/MAX6675.pdf ) and found out, the MAX6675 has integrated cold junction temperature compensation, but change in the ambient temperature changes the readings significantly (by 10-15°C).
May there be a thing about reading and interpreting the output or is there an option to activate/deactivate ambient temp. compensation I didn't see? Or is this just a Problem i've got to get along with?
best regards
clear
clc
a = arduino('COM3','Uno','Libraries','SPI');
dev = device(a,'SPIChipSelectPin','D10');
dataIn = [0 0];
dur=40; %Sampling Time
SRate=8; %Sampling Rate
t=[0:1/SRate:dur];
r2=zeros(1,SRate*(dur)+1);
for i=1:1:SRate*dur+1
rout = writeRead(dev,dataIn,'uint8'); %Read MAX6675
r0=255*double(rout(1))+double(rout(2)); %Make a Temperature-proportional reading out of whatever I get back from MAX6675
r1(i)=r0/24;
pause(1/SRate);
plot(t,r1)
end
1 个评论
Uwe Weltin
2023-1-27
be sure to 'shift out' the first three bits. They have nothing to do with the temperature. (Error Codes) See data sheet of the MAX6675
回答(1 个)
Uwe Weltin
2023-1-27
% Ktype_Max6675_Due.m
% Ktype Temperatur mit Arduino Due messen
clear all, close all
ComPort = getAvailableComPort
a = arduino(ComPort{1},'Due','Libraries','SPI')
% DUE Interface: ...,'Libraries','SPI')
% Supports hardware SPI: 6 extra Pins next to CPU
% MISO 'D74' Default SDIPin: 'SPI-1' SPI-Port
% 5V: 'SPI-2' |5 3 1|
% SCK 'D76' Default SCLPin: 'SPI-3' |6 4 2|
% MOSI 'D75' Default SDOPin: 'SPI-4'
% RESET: 'SPI-5'
% GND: 'SPI-6'
% CS: 'D10'
MAX6675 = device(a,'SPIChipSelectPin','D10')
tmax= 30;
fs = 1;
dt = 1/fs;
t = [dt:dt:tmax];
il = length(t);
T = zeros(il,1);
dummy = [uint8(0),uint8(0)];
for i=1:il
datOut = writeRead(MAX6675,dummy);
pause(0.5)
BINR = [dec2bin(datOut(1),8), dec2bin(datOut(2),8)];
disp(BINR)
DECR = bin2dec(BINR);
DECT = bitshift(DECR,-3);
BINT = dec2bin(DECT);
MP = 255/1023.75; % Wird 0 ausgelesen hats 0°C,
T(i,1) = MP*DECT; % wird 255 ausgelesen hats 1023.75°C
disp(T(i,:))
end
figure(1)
plot(t,T(:,1),'r')
xlabel('Zeit [s]')
ylabel('Temperatur [°C]')
legend('KTYP')
title('Temperaturmessungen mit DUE,KTYP')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!