Changes between Version 10 and Version 11 of MAX31855Sketch
- Timestamp:
- May 14, 2013 12:05:05 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
MAX31855Sketch
v10 v11 4 4 * [wiki:MAX31855Instruction 作り方の説明はこちら。] 5 5 * キットとして販売しています。 6 * [http://www.switch-science.com/ products/detail.php?product_id=8643.3V版]7 * [http://www.switch-science.com/ products/detail.php?product_id=10995V版]6 * [http://www.switch-science.com/catalog/864/ 3.3V版] 7 * [http://www.switch-science.com/catalog/1099/ 5V版] 8 8 9 9 どんなスケッチ(ソフトウェア)で使うのかを説明します。[[br]] 10 MAX31855 5V版をお使いの場合は、[#スケッチについて]から読み始めてください。11 12 10 13 11 == 接続について == 14 MAX31855 K型熱電対温度センサ 3.3V版をArduinoに接続する方法について解説します。[[BR]]15 すでにモジュールが完成していて、Arduino UNOと写真のように接続してあるものとします。[[BR]]16 参考:/SSとSCKを1KΩと1.5KΩで抵抗分圧し5V→3.3V(3.0V)変換しています。12 MAX31855 K型熱電対温度センサの電源電圧とArduinoの電源電圧が同じで、SPIの信号がセンサの基板と同じに並んでいれば、Arduinoに直接挿し込んで使うことが出来ます。[[BR]] 13 5V版はArduino Uno(初代/R2/R3)やArduino Duemilanove等、3.3V版はArduino Pro 328 - 3.3V/8MHz等に直接挿し込めます[[BR]] 14 Arduino LeonardoやArduino Mega等は写真の場所にSPIの信号が出ていないので、ジャンパワイヤやブレッドボードなどで配線してください。 17 15 18 [[Image(wiki:MAX31855:2.JPG, 500px)]] 19 20 [[Image(wiki:MAX31855:4.JPG, 500px)]] 16 [[Image(MAX31855_5V_on_Uno.jpg, 500px)]] 21 17 22 18 … … 44 40 {{{ 45 41 #!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. 46 47 /* 47 // Arduinoボードの電源電圧が3.3Vの場合、48 // 以下のマクロを有効にしてモジュールを直挿しできます。49 48 #define VCC 8 50 49 #define GND 9 51 50 */ 52 51 }}} 53 モジュールをデジタルの8番~13番に直結したい場合は、これらの定義を有効にしてください。[[BR]]52 上の写真の様にモジュールをデジタルの8番~13番に直結したい場合は、これらの定義を有効にしてください。[[BR]] 54 53 VCCおよびGNDの定義は、デジタルの8番および9番からモジュールに電源供給を行うためです。[[BR]] 55 この方法が使えるのはArduinoの電源電圧が3.3Vの場合に限ります。Arduino UNOでは出来ません。[[BR]]56 54 57 55 {{{ … … 63 61 ※このスケッチはArduinoIDE付属のSPIライブラリを使用しています。 64 62 65 === max31855_example .pde (Arduino 1.0付属SPIライブラリ対応版) ===63 === max31855_example2.ino (Arduino 1.0付属SPIライブラリ対応版 2) === 66 64 {{{ 67 65 #!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) 70 69 71 70 #include "SPI.h" 72 71 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. 73 77 /* 74 // Arduinoボードの電源電圧が3.3Vの場合、75 // 以下のマクロを有効にしてモジュールを直挿しできます。76 78 #define VCC 8 77 79 #define GND 9 78 80 */ 79 81 #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 }98 82 99 83 void setup() { … … 122 106 123 107 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 130 114 131 115 if((thermocouple & 0x0001) != 0) { … … 142 126 Serial.println(""); 143 127 } else { 144 if((thermocouple & 0x8000) == 0){ // 0℃以上 128 if((thermocouple & 0x8000) == 0){ // 0℃以上 above 0 Degrees Celsius 145 129 disp = (thermocouple >> 2) * 0.25; 146 } else { // 0℃未満 130 } else { // 0℃未満 below zero 147 131 disp = (0x3fff - (thermocouple >> 2) + 1) * -0.25; 148 132 } … … 153 137 Serial.print(" // "); 154 138 155 if((internal & 0x8000) == 0){ // 0℃以上 139 if((internal & 0x8000) == 0){ // 0℃以上 above 0 Degrees Celsius 156 140 disp = (internal >> 4) * 0.0625; 157 } else { // 0℃未満 141 } else { // 0℃未満 below zero 158 142 disp = (((0xffff - internal) >> 4) + 1) * -0.0625; 159 143 } … … 169 153 ''(2009/4/5 - original text for MAX6675 kit by sgk)'' [[BR]] 170 154 ''(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