본문 바로가기
정리, 공부/아두이노 & 회로구성

Thermocouple 여러개, 아두이노 연결, LCD display 사용, 액셀에 데이터 실시간 정리 PLX DAQ

by 쉬고 싶다 2020. 10. 4.
반응형

- Thermocouple

- Multi Thermocouple - Arduino Uno

- Thermocouple로 읽은 값 LCD display로 띠우기

- Thermocouple로 읽은 값 실시간으로 Excel에 저장

 

 

 

 Thermocouple

 

간단한 열전대에 관한 내용과

MAX31855를 사용하는 회로, 코딩 (라이브러리 추가) 관련 포스팅은 필요하시면 참고해주시면 됩니다.

2020/09/12 - [정리, 공부해요/전기, 전자, 통신] - 열전대(써모커플, Thermocouple) - 원리, 종류

 

열전대(써모커플, Thermocouple) - 원리, 종류

- 열전대(써모커플, Thermocouple) 원리 - Thermocouple type - Thermocouple 종류 열전대(써모커플, Thermocouple) 써모커플은 서로 다른 두 종류의 금속의 기전력을 이용한 온도센서입니다. 특성이 다른 두 종류..

setoo0922.tistory.com

2020/10/10 - [정리, 공부해요/아두이노] - Thermocouple(열전대, 써모커플), 아두이노로 값 읽기, MAX31855 증폭기 사용

 

Thermocouple(열전대, 써모커플), 아두이노로 값 읽기, MAX31855 증폭기 사용

- Thermocouple (열전대) - Thermocouple amplifier (MAX31855, 왜 필요한지) - Thermocouple with arduino (회로 연결 & 코딩)  Thermocouple (열전대) 열전대에 관한 간단한 내용들은 아래 글을 참고하면 좋을..

setoo0922.tistory.com

 

 Multi thermocouple - arduino uno

 

2개의 열전대를 아두이노 우노에 연결해 값 받기.

위의 두번째 링크에 라이브러리를 다운 받는 법을 포스팅 해뒀습니다.

기존의 라이브러리 예제인 열전대 하나를 운용하는 코드를 2개를 사용할 수 있게 수정한 것입니다.

3,4,5와 12,7,13 번 핀 사용.

#include <SPI.h>
#include "Adafruit_MAX31855.h"

// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO1   3
#define MAXCS1   4
#define MAXCLK1  5
#define MAXDO2   12
#define MAXCS2   7
#define MAXCLK2  13

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple1(MAXCLK1, MAXCS1, MAXDO1);
Adafruit_MAX31855 thermocouple2(MAXCLK2, MAXCS2, MAXDO2);

// Example creating a thermocouple instance with hardware SPI
// on a given CS pin.
//#define MAXCS   10
//Adafruit_MAX31855 thermocouple(MAXCS);

void setup() {
  Serial.begin(9600);

  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple1.begin()) {
    while (1) delay(10);
  }
  if (!thermocouple2.begin()) {
    while (1) delay(10);
  }
  Serial.println("DONE.");
}

void loop() {
  // basic readout test, just print the current temp
   Serial.println("Internal Temp = ");
   Serial.print(thermocouple1.readInternal());
   Serial.print("/");
   Serial.println(thermocouple2.readInternal());
   
   double c1 = thermocouple1.readCelsius();
   double c2 = thermocouple2.readCelsius();
   if (isnan(c1)) {
     Serial.println("Something wrong with thermocouple1");
   } 
   else if (isnan(c2)) {
     Serial.println("Something wrong with thermocouple2");
   }
   else {
     Serial.print("C=");
     Serial.print(c1);
     Serial.print("/");
     Serial.println(c2);
   }
   //Serial.print("F = ");
   //Serial.println(thermocouple.readFahrenheit());

   delay(1000);
}

스크린이 잘 보이진 않지만, 접촉부 온도에 따라 비교적 빠르게 반응하고 있습니다.

 

 Thermocouple로 읽은 값 LCD display로 띠우기

 

우선 LCD에 관한 글은 따로 포스팅하겠습니다.

2020/10/10 - [정리, 공부해요/아두이노] - LCD display, 아두이노 우노, 기본연결/I2C/가변저항의 필요. 회로&코드

간단히, I2C가 탑재된 LCD display를 사용하기 위한 라이브러리 다운

보라색 검색 후, 초록색 다운로드

그리고 코드는 아래의 Excel 저장을 함께 진행 가능한 것을 아래에 올리겠습니다 :)

 

 Thermocouple로 읽은 값 실시간으로 Excel에 저장

 

우선, 센서로 부터 읽은 값을 실시간으로 오래 기록하기 위해 우리가 DAQ를 사용해 주듯이,

PLX DAQ라는 프로그램을 다운받아야 합니다.

아래의 링크에 들어가서 두 파일을 모두 다운받고, 압축파일을 풀어주면 됩니다.

www.parallax.com/downloads/plx-daq

 

PLX-DAQ | Parallax Inc

You are hereHome › PLX-DAQ PLX-DAQ Download Summary Parallax Data Acquisition tool (PLX-DAQ) software add-in for Microsoft Excel acquires up to 26 channels of data from any Parallax microcontrollers and drops the numbers into columns as they arrive. PLX-

www.parallax.com

혹은 파일 아래의 파일 다운로드 후 알집풀기

plx-daq-release2b.zip
0.49MB
PLX-DAQ-v2.11.zip
0.48MB

압축을 풀면, (data1,2는 제가 따로 저장해둔 데이터 파일이고) 이를 제외한 파일들이 보일 것입니다.

(이름은 상관없습니다.)

엑셀 파일을 들어가시면

파란 창이 뜰 수 있고, 콘텐츠 사용을 허용할지 묻는 노란 알림이 뜰 수 있습니다. 허용해주시면 위의 파란 창이 뜹니다.

 

<<이 프로그램은 아두이노 스케치의 Serial Moniter와 함께 사용할 수 없습니다>>

 

사용법은 간단합니다. (프로그램 사용법 + 코드를 짜야하는데, 프로그램 사용법 먼저 다루자면.)

하늘색 상자의 포트와 Baud를 맞춰줍니다.

포트: 아두이노 우노와 연결된 포트 / Baud: Serial.begin( 숫자 ), 보통 9600을 사용합니다.

이렇게 세팅하고, 초록 상자의 Connect를 눌러주면 이 버튼이 Disconnect로 바뀌며 데이터가 코드에서 설정해준 Delay에 맞게 쌓이게 됩니다.

실시간으로 그래프가 변하는 것도 볼 수 있습니다.
녹색 박스에서 데이터가 몇 줄 쌓였는지 알 수 있습니다.

이제 코드를 알아보겠습니다.

코드만 알면 위처럼 세팅하고, Connect만 눌러주면 데이터가 쌓이게 됩니다.

(하지만,, 저는 초당 한줄씩 쌓았고, 5시간 뒤에 돌아오니 데이터가 싹 날아가고 프로그램은 꺼져 있었습니다.. 가급적 너무 쌓이지 않게 Delay 설정을 해주고, 불안하면 옆에서 지키길 바랍니다..)

#include <SPI.h>
#include <Wire.h>
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal_I2C.h>

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO1   3
#define MAXCS1   4
#define MAXCLK1  5
#define MAXDO2   12
#define MAXCS2   7
#define MAXCLK2  13

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple1(MAXCLK1, MAXCS1, MAXDO1);
Adafruit_MAX31855 thermocouple2(MAXCLK2, MAXCS2, MAXDO2);

// 0x27: address of I2C, 16x2 LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  #ifndef ESP8266
    while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  #endif
  Serial.begin(9600);
  // LCD initialize, turn on the backlight of LCD
  lcd.init();
  lcd.backlight();

  //set the start line of writing
  lcd.setCursor(0,0);
  lcd.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  
  if (!thermocouple1.begin()) {
    lcd.print("ERROR1 ");
    while (1) delay(10);
  }
  if (!thermocouple2.begin()) {
    lcd.print("ERROR2 ");
    while (1) delay(10);
  }
  lcd.print("DONE");
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,Int-T1,Int-T2,T1,T2");
}

void loop() {
  // basic readout test, just print the current temp
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("I.T=");
   lcd.print(thermocouple1.readInternal());
   lcd.print("/");
   lcd.println(thermocouple2.readInternal());
   

   double c1 = thermocouple1.readCelsius();
   double c2 = thermocouple2.readCelsius();
   lcd.setCursor(0, 1);
   if (isnan(c1)) {
     lcd.print("T1X");
     Serial.println("Something wrong with thermocouple1");
   } 
   else if (isnan(c2)) {
     lcd.print("T2X");
     Serial.println("Something wrong with thermocouple2");
   }
   else {
     lcd.print("C=");
     lcd.print(c1);
     lcd.print("/");
     lcd.println(c2);
     Serial.print("DATA,TIME,");
     Serial.print(thermocouple1.readInternal());
     Serial.print(",");
     Serial.print(thermocouple2.readInternal());
     Serial.print(",");
     Serial.print(c1);
     Serial.print(",");
     Serial.print(c2);
     Serial.println(",");
   }

   delay(2000);
}

 

Serial.println("CLEARDATA");

==> 엑셀에서 기존에 있던 데이터를 정리
Serial.println("LABEL,Time,Int-T1,Int-T2,T1,T2");

==> 액셀의 최상단에 라벨링. Time, 하고 4가지. ","로 종류를 나눕니다.

Serial.print("DATA,TIME,");

==> Time 줄에 시간을 기록합니다.

Serial.print(thermocouple1.readInternal());

==> 그 다음 줄에 기록할 데이터

Serial.print(",");

==> 다음 칸으로 넘어가겠다는 명령어로 보시면 됩니다. 콤마.

 

기존의 코딩에서 이정도의 내용만 추가하면 엑셀에 데이터를 쌓을 수 있습니다.

 

 

 

 

마무리

 

열전대 2개 연결, Serial Monitor

1번 열전대 잡아 온도 올리고
2번 열전대 잡아 온도 올리고
1번 열전대 놓아 떨어지는 온도 값 보고.

열전대 2개 연결, LCD display

1,2번 열전대 둘 다 잡아 온도를 올리면

 

반응형

댓글