Changes between Version 10 and Version 11 of MAX31855Sketch


Ignore:
Timestamp:
May 14, 2013 12:05:05 PM (11 years ago)
Author:
maris
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MAX31855Sketch

    v10 v11  
    44 * [wiki:MAX31855Instruction 作り方の説明はこちら。]
    55 * キットとして販売しています。
    6   * [http://www.switch-science.com/products/detail.php?product_id=864 3.3V版]
    7   * [http://www.switch-science.com/products/detail.php?product_id=1099 5V版]
     6  * [http://www.switch-science.com/catalog/864/ 3.3V版]
     7  * [http://www.switch-science.com/catalog/1099/ 5V版]
    88
    99どんなスケッチ(ソフトウェア)で使うのかを説明します。[[br]]
    10 MAX31855 5V版をお使いの場合は、[#スケッチについて]から読み始めてください。
    11 
    1210
    1311== 接続について ==
    14 MAX31855 K型熱電対温度センサ 3.3V版をArduinoに接続する方法について解説します。[[BR]]
    15 すでにモジュールが完成していて、Arduino UNOと写真のように接続してあるものとします。[[BR]]
    16 参考:/SSとSCKを1KΩと1.5KΩで抵抗分圧し5V→3.3V(3.0V)変換しています
     12MAX31855 K型熱電対温度センサの電源電圧とArduinoの電源電圧が同じで、SPIの信号がセンサの基板と同じに並んでいれば、Arduinoに直接挿し込んで使うことが出来ます。[[BR]]
     135V版はArduino Uno(初代/R2/R3)やArduino Duemilanove等、3.3V版はArduino Pro 328 - 3.3V/8MHz等に直接挿し込めます[[BR]]
     14Arduino LeonardoやArduino Mega等は写真の場所にSPIの信号が出ていないので、ジャンパワイヤやブレッドボードなどで配線してください
    1715
    18 [[Image(wiki:MAX31855:2.JPG, 500px)]]
    19 
    20 [[Image(wiki:MAX31855:4.JPG, 500px)]]
     16[[Image(MAX31855_5V_on_Uno.jpg, 500px)]]
    2117
    2218
     
    4440{{{
    4541#!c
     42// Arduinoボードの電源電圧がキットの電源電圧と同じ場合、
     43// 以下のマクロを有効にしてモジュールを直挿しできます。
     44// If working voltage of your arduino board is same as the kit,
     45// you can enable macro code next two lines
     46// to put the kit on your arduino directly.
    4647/*
    47 // Arduinoボードの電源電圧が3.3Vの場合、
    48 // 以下のマクロを有効にしてモジュールを直挿しできます。
    4948#define VCC  8
    5049#define GND  9
    5150*/
    5251}}}
    53 モジュールをデジタルの8番~13番に直結したい場合は、これらの定義を有効にしてください。[[BR]]
     52上の写真の様にモジュールをデジタルの8番~13番に直結したい場合は、これらの定義を有効にしてください。[[BR]]
    5453VCCおよびGNDの定義は、デジタルの8番および9番からモジュールに電源供給を行うためです。[[BR]]
    55 この方法が使えるのはArduinoの電源電圧が3.3Vの場合に限ります。Arduino UNOでは出来ません。[[BR]]
    5654
    5755{{{
     
    6361※このスケッチはArduinoIDE付属のSPIライブラリを使用しています。
    6462
    65 === max31855_example.pde (Arduino 1.0付属SPIライブラリ対応版) ===
     63=== max31855_example2.ino (Arduino 1.0付属SPIライブラリ対応版 2) ===
    6664{{{
    6765#!c
    68 // K型熱電対温度センサモジュールキット(SPI接続)MAX31855使用(3.3V版)サンプルスケッチ
    69 // switch-science 2012.2.8
     66// K型熱電対温度センサモジュールキット(SPI接続)MAX31855使用(5V版/3.3V版)サンプルスケッチ
     67// Example sketch for MAX31855 Type-K thermocouple sensor module (5V/3.3V)
     68// Switch-Science 2013.5.14(Tue)
    7069
    7170#include "SPI.h"
    7271
     72// Arduinoボードの電源電圧がキットの電源電圧と同じ場合、
     73// 以下のマクロを有効にしてモジュールを直挿しできます。
     74// If working voltage of your arduino board is same as the kit,
     75// you can enable macro code next two lines
     76// to put the kit on your arduino directly.
    7377/*
    74 // Arduinoボードの電源電圧が3.3Vの場合、
    75 // 以下のマクロを有効にしてモジュールを直挿しできます。
    7678#define VCC  8
    7779#define GND  9
    7880*/
    7981#define SLAVE 10
    80 
    81 byte enabled = 255;
    82 
    83 void SPI_disable() {
    84   if(enabled != 255) {
    85     digitalWrite(enabled,HIGH);
    86     enabled = 255;
    87   }
    88 }
    89 void SPI_enable(byte slaveselecter) {
    90   SPI_disable();
    91   digitalWrite(slaveselecter,LOW);
    92   enabled = slaveselecter;
    93 }
    94 
    95 byte SPI_read() {
    96   return SPI.transfer(0x00);
    97 }
    9882
    9983void setup() {
     
    122106
    123107  delay(500);
    124   SPI_enable(SLAVE);
    125   thermocouple = (unsigned int)SPI_read() << 8;
    126   thermocouple |= (unsigned int)SPI_read() ;
    127   internal = (unsigned int)SPI_read() << 8;
    128   internal |= (unsigned int)SPI_read();
    129   SPI_disable();
     108  digitalWrite(SLAVE, LOW);                             //  Enable the chip
     109  thermocouple = (unsigned int)SPI.transfer(0x00) << 8;   //  Read high byte thermocouple
     110  thermocouple |= (unsigned int)SPI.transfer(0x00);       //  Read low byte thermocouple
     111  internal = (unsigned int)SPI.transfer(0x00) << 8;       //  Read high byte internal
     112  internal |= (unsigned int)SPI.transfer(0x00);           //  Read low byte internal
     113  digitalWrite(SLAVE, HIGH);                            //  Disable the chip
    130114
    131115  if((thermocouple & 0x0001) != 0) {
     
    142126    Serial.println("");
    143127  } else {
    144     if((thermocouple & 0x8000) == 0){ // 0℃以上
     128    if((thermocouple & 0x8000) == 0){ // 0℃以上   above 0 Degrees Celsius
    145129      disp = (thermocouple >> 2) * 0.25;
    146     } else {                          // 0℃未満
     130    } else {                          // 0℃未満   below zero
    147131      disp = (0x3fff - (thermocouple >> 2) + 1)  * -0.25;
    148132    }
     
    153137    Serial.print(" // ");
    154138   
    155     if((internal & 0x8000) == 0){ // 0℃以上
     139    if((internal & 0x8000) == 0){ // 0℃以上   above 0 Degrees Celsius
    156140      disp = (internal >> 4) * 0.0625;
    157     } else {                          // 0℃未満
     141    } else {                          // 0℃未満   below zero
    158142      disp = (((0xffff - internal) >> 4) + 1)  * -0.0625;
    159143    }
     
    169153''(2009/4/5 - original text for MAX6675 kit by sgk)'' [[BR]]
    170154''(2012/2/15 - modified for MAX31855 kit by maris)'' [[BR]]
    171 ''(2013/2/7 - modified for MAX31855 5V kit by ohki)''
     155''(2013/2/7 - modified for MAX31855 5V kit by ohki)'' [[BR]]
     156''(2013/5/14 - modified for MAX31855 kit by maris)'' [[BR]]
     157
     158