Matlab cannot read data from MAX6675 through Arduino

25 ビュー (過去 30 日間)
OSCAR BELLON-HERNANDEZ
OSCAR BELLON-HERNANDEZ 2019 年 9 月 18 日
コメント済み: Atta Wasay 2023 年 11 月 8 日
I tested a MAX6675 module using "max6675.h" library on Arduino IDE to measure temperature with type K thermocouple. It worked well.
Then I connected Arduino UNO with Arduino Support Package in Matlab to read data from the MAX6675 module.
a=arduino('com4','uno','Libraries','SPI');
And I set SPI object:
max6675=spidev(a,'D10')
This was what command window showed:
Matlab support 01.png
I tested the reading with these commands:
din=zeros(1,2);
dato=writeRead(max6675,din,'uint16')
And the result was:
Matlab support 02.png
It is not possible those values. Temperature in the room is tipically 19°C. The result must be [0 76] or something like that. I used a digital multimeter to test "CS" and "D10" pins and voltage remained in high state while "writeRead" function was executed. It should change from high to low level according to SPI protocol during reading operation on MAX6675.
What am I doing wrong?
  1 件のコメント
OSCAR BELLON-HERNANDEZ
OSCAR BELLON-HERNANDEZ 2019 年 12 月 4 日
As I needed to read the temperature from module MAX6675, and I had no time, I decided no to use the Arduino Support Package in Matlab. Instead, I wrote a code directly on the Arduino IDE to communicate it with a PC. In that sketch, Arduino acquires temperature value from the module, and then it sends it to the PC via the serial port. In Matlab, I used the "serial" function to manage the data interchange.
I hope someone with time and knowledge can solve the problem with the MAX6675 and SPI object of the Arduino Support Package, and then share the solution with us.

サインインしてコメントする。

回答 (3 件)

Uwe Weltin
Uwe Weltin 2023 年 1 月 23 日
% KTYPE.m This example is based on the reference manual of the MAX6675 amplifier
% LED Versuch
clear all, close all
ComPort=getAvailableComPort
a = arduino(ComPort{1},'Uno','Libraries','SPI')
tmax= 30;
fs = 8;
dt = 1/fs;
t = [dt:dt:tmax];
il = length(t);
T = zeros(il);
dummy = [uint8(0),uint8(0)];
for i=1:il
datOut = writeRead(MAX6675,dummy); % Read MAX6675
pause(0.5)
BINR = [dec2bin(datOut(1),8), dec2bin(datOut(2),8)]; % Show the bits of the read
DECR = bin2dec(BINR);
DECT = bitshift(DECR,-3); % Shift by 3 bits to the right
BINT = dec2bin(DECT); % Just to show the change
MP = 255/1023.75; % Reading 0 means 0°C,
% Reading 255 its hot as 1023.75°C
T(i) = MP*DECT; % Factor to get °C
disp(T(i))
end

Daniel Melendrez
Daniel Melendrez 2019 年 12 月 4 日
編集済み: Daniel Melendrez 2019 年 12 月 4 日
Oscar
I am working at the moment on a big project that uses the MAX6675. Here are some pieces of advice based on my experience:
  1. I would delegate the full data conversion to the Arduino itself. Do not use Matlab to convert the data. Meaning that I would only use Matlab for reading the converted value and displaying it in the console or in a plot.
  2. Don't forget that each conversion time is about 250 ms (read the datasheet, page 2), therefore, you need to query Arduino if the conversion is ready after this time. In my application I implemented a serial query routine that "spits out" the temperature value once it's ready.
Hope this helps for now
Daniel
  2 件のコメント
Yo
Yo 2021 年 3 月 31 日
Daniel,
I see this is an old question. Is it possible to read the thermocouple temperature from simulink?
Marco
Atta Wasay
Atta Wasay 2023 年 11 月 8 日
Here is the simulink model.
Simulink Model
SPI Reading
Data Conversion

サインインしてコメントする。


gdz
gdz 2022 年 12 月 13 日
I have done something the similar, dato give [4 4], the second run dato give [63491,63491], and the following run repeated with [4,4], [63491,63491], and [2052,2052]. Does anyone know what's happenning here?

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by