Clear Filters
Clear Filters

Temperature Measurements with MATLAB

46 views (last 30 days)
Jana Schröder
Jana Schröder on 22 Apr 2022
Answered: Ayush on 30 Nov 2023
Hello,
i want to measure temperatures with MATLAB. I uses a PT100 and the MAX31865 Amplifier from Adafruit. I have tested it with the arduino IDE and an Programmcode found through research in the internet.
But I want to use my temperature sensor with matlab. Is it possible? Do you have an programmcode example for the Adafruit MAX 31865 ?
I can show you the programmcode from the Arduino IDE, which is used at the moment.
/***************************************************
This is a library for the Adafruit PT100/P1000 RTD Sensor w/MAX31865
Designed specifically to work with the Adafruit RTD Sensor
----> https://www.adafruit.com/products/3328
This sensor uses SPI to communicate, 4 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_MAX31865.h>
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31865 sensor1 = Adafruit_MAX31865(10, 11, 12, 13);
Adafruit_MAX31865 sensor2 = Adafruit_MAX31865(9, 11, 12, 13);
Adafruit_MAX31865 sensor3 = Adafruit_MAX31865(8, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
//Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);
// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF 430.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL 100.0
void setup() {
Serial.begin(115200);
Serial.println("Die Temperatursensoren sind aktiv! Messung läuft...");
Serial.print("\n");
delay(3000);
sensor1.begin(MAX31865_2WIRE); // set to 2WIRE or 4WIRE as necessary
sensor2.begin(MAX31865_2WIRE);
sensor3.begin(MAX31865_2WIRE);
}
void loop() {
uint16_t rtd = sensor1.readRTD();
//Serial.print("RTD value: "); Serial.println(rtd);
float ratio = rtd;
ratio /= 32768;
//Serial.print("Ratio = "); Serial.println(ratio,8);
Serial.print("Resistance in OHM = "); Serial.println(RREF*ratio,8);
Serial.print("Temperature1 in °C = "); Serial.println(sensor1.temperature(RNOMINAL, RREF));
Serial.print("\n");
uint16_t rtd2 = sensor2.readRTD();
//Serial.print("RTD value: "); Serial.println(rtd);
float ratio2 = rtd2;
ratio2 /= 32768;
//Serial.print("Ratio = "); Serial.println(ratio2,8);
Serial.print("Resistance in OHM = "); Serial.println(RREF*ratio2,8);
Serial.print("Temperature2 in °C = "); Serial.println(sensor2.temperature(RNOMINAL, RREF));
Serial.print("\n");
uint16_t rtd3 = sensor3.readRTD();
//Serial.print("RTD value: "); Serial.println(rtd);
float ratio3 = rtd3;
ratio3 /= 32768;
// Serial.print("Ratio = "); Serial.println(ratio3,8);
Serial.print("Resistance in OHM = "); Serial.println(RREF*ratio3,8);
Serial.print("Temperature3 in °C = "); Serial.println(sensor3.temperature(RNOMINAL, RREF));
Serial.print("\n");
delay(30000);
}
If it is not possible to use my sensor with MATLAB, is there any possibility to read out Code from the arduino IDE with MATLAB? Because if it is possible i will use two arduinos, one for my temperature meaurment and one for my other code which I have developed in MATLAB.
Thank you so much!
Regards.

Answers (1)

Ayush
Ayush on 30 Nov 2023
Hey Jana,
I understand that you want to switch from using Arduino to measuring temperatures with MATLAB using an Adafruit MAX31865 RTD amplifier and a PT100 sensor. You also want to know if you can directly use the MAX31865 with MATLAB and if there's a sample program available. Additionally, they want to know if it's possible to read data from an Arduino using MATLAB. The user is also considering using two Arduinos, one for temperature measurement and another for other tasks, and then transferring the sensor data to MATLAB.
Yes, it is indeed possible to use the Adafruit MAX31865 RTD amplifier with MATLAB. You can communicate with the MAX31865 over SPI using MATLAB and read the temperature sensor data.
To achieve this, you would need to use MATLAB's Instrument Control Toolbox to communicate with the MAX31865 over SPI. Here's a simple example of how you might accomplish this in MATLAB:
% Create a connection to the MAX31865 over SPI
rtd = spi('comPort', 'PortNumber', mode, speed, bits, 'BitOrder', 'MSBFirst');
% Assuming you've connected the MAX31865 to SPI and configured the pins
% Read the RTD value
rtdValue = read(rtd, 'uint16');
% Calculate the temperature
resistance = RREF * double(rtdValue) / 32768.0;
temperature = resistance / RNOMINAL;
% Display the temperature
disp(['Temperature: ' num2str(temperature) ' °C']);
% Close the connection
delete(rtd);
Please replace “comport”, “PortNumber”, “mode”, “speed”, and “bits” with the appropriate values for your setup.
If you prefer to use the Arduino to read the temperature sensor data and then communicate that data to MATLAB, you can use MATLAB Support Package for Arduino. This package allows you to communicate with an Arduino board from MATLAB and Simulink. You can read sensor data from the Arduino and process it in MATLAB.
Here's a simple example of how to read sensor data from Arduino using MATLAB Support Package for Arduino:
a = arduino();
temperature = readVoltage(a, 'A0') * 100; % Assuming the temperature sensor is connected to analog pin A0
disp(['Temperature: ' num2str(temperature) ' °C']);
You can use this approach to read sensor data from an Arduino and then process it in MATLAB. This way, you can use one Arduino for temperature measurement and another for your other code while processing the data in MATLAB.
To learn more about using support package and “spi” in MATLAB, refer to the MathWorks documentation link below:
  1. https://www.mathworks.com/help/supportpkg/arduinoio/index.html
  2. https://www.mathworks.com/help/instrument/spi.html
Hope this helps!
Regards,
Ayush Goyal

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!