11 | | [[Image(Thermocouple_shield1.jpg)]] |
| 13 | === 【1】 === |
| 14 | Arduino用シールドとして使用する場合はまずピンヘッダを実装して、Arduinoに接続できるようにします。[[BR]] |
| 15 | (ピンヘッダはコテ先温度計シールドには付属しません。)[[BR]] |
| 16 | シールドとして使わない場合J3を利用して別のマイコンと接続することもできます。 |
| 17 | (以降の組み立て説明の写真ではピンヘッダを省略しています。) |
| 18 | |
| 19 | === 【2】 === |
| 20 | ネジを3本通して、ナット二つで固定します。 |
| 21 | |
| 22 | [[Image(Thermocouple_shield2.jpg,500px)]] |
| 23 | |
| 24 | === 【3】 === |
| 25 | 熱電対の赤と青の端子を基板の文字に合わせてネジに通します。一番最後にあまった端子をネジに通します。 |
| 26 | |
| 27 | [[Image(Thermocouple_shield3.jpg,500px)]] |
| 28 | |
| 29 | これで組み立ては完成です。 |
| 30 | |
| 31 | === 基本設定 === |
| 32 | |
| 33 | [https://www.switch-science.com/catalog/789/ Arduino Uno R3]でコテ先温度計シールドを使用する場合特に変更は必要ありません。 |
| 34 | [https://www.switch-science.com/catalog/968/ Arduino Leonardo]等のSPI端子がICSP端子から出ているArduinoの場合にはショートジャンパSJ3とSJ4の接続の2-3をカットして1-2を接続する必要があります。 |
| 35 | [https://www.switch-science.com/catalog/2299/ Arduino M0 pro]や[https://www.switch-science.com/catalog/2210/ Arduino Yún]のようにI/Oの電圧が3.3VのArduinoの場合はSJ1とSJ2をショートさせる必要があります。 |
| 36 | |
| 37 | === サンプルスケッチ === |
| 38 | |
| 39 | {{{ |
| 40 | #include <Wire.h> |
| 41 | #include <SPI.h> |
| 42 | |
| 43 | #define SLAVE 10 |
| 44 | #define sdaPin 18 // ArduinoA4 |
| 45 | #define sclPin 19 // ArduinoA5 |
| 46 | #define I2Cadr 0x3e // 固定 |
| 47 | byte contrast = 35; // コントラスト(0~63) |
| 48 | char unit[3] = {0xF2,'C',0}; |
| 49 | |
| 50 | void setup() { |
| 51 | pinMode(SLAVE, OUTPUT); |
| 52 | digitalWrite(SLAVE, HIGH); |
| 53 | |
| 54 | Serial.begin(9600); |
| 55 | SPI.begin(); |
| 56 | SPI.setBitOrder(MSBFIRST); |
| 57 | SPI.setClockDivider(SPI_CLOCK_DIV4); |
| 58 | SPI.setDataMode(SPI_MODE0); |
| 59 | |
| 60 | |
| 61 | Wire.begin(); |
| 62 | lcd_cmd(0b00111000); // function set |
| 63 | lcd_cmd(0b00111001); // function set |
| 64 | lcd_cmd(0b00000100); // EntryModeSet |
| 65 | lcd_cmd(0b00010100); // interval osc |
| 66 | lcd_cmd(0b01110000 | (contrast & 0xF)); // contrast Low |
| 67 | lcd_cmd(0b01011100 | ((contrast >> 4) & 0x3)); // contast High/icon/power |
| 68 | lcd_cmd(0b01101100); // follower control |
| 69 | delay(200); |
| 70 | lcd_cmd(0b00111000); // function set |
| 71 | lcd_cmd(0b00001100); // Display On |
| 72 | lcd_cmd(0b00000001); // Clear Display |
| 73 | delay(2); |
| 74 | |
| 75 | |
| 76 | } |
| 77 | |
| 78 | void loop() { |
| 79 | unsigned int thermocouple; // 14-Bit Thermocouple Temperature Data + 2-Bit |
| 80 | unsigned int internal; // 12-Bit Internal Temperature Data + 4-Bit |
| 81 | float disp; // display value |
| 82 | delay(500); |
| 83 | lcd_clear(); |
| 84 | lcd_setCursor(0,0); |
| 85 | lcd_printStr("TEMP"); |
| 86 | lcd_setCursor(0,1); |
| 87 | |
| 88 | digitalWrite(SLAVE, LOW); // Enable the chip |
| 89 | thermocouple = (unsigned int)SPI.transfer(0x00) << 8; // Read high byte thermocouple |
| 90 | thermocouple |= (unsigned int)SPI.transfer(0x00); // Read low byte thermocouple |
| 91 | internal = (unsigned int)SPI.transfer(0x00) << 8; // Read high byte internal |
| 92 | internal |= (unsigned int)SPI.transfer(0x00); // Read low byte internal |
| 93 | digitalWrite(SLAVE, HIGH); // Disable the chip |
| 94 | |
| 95 | if((thermocouple & 0x0001) != 0) { |
| 96 | Serial.print("ERROR: "); |
| 97 | if ((internal & 0x0004) !=0) { |
| 98 | Serial.print("Short to Vcc, "); |
| 99 | lcd_printStr("Short Vc"); |
| 100 | } |
| 101 | if ((internal & 0x0002) !=0) { |
| 102 | Serial.print("Short to GND, "); |
| 103 | lcd_printStr("Short G"); |
| 104 | } |
| 105 | if ((internal & 0x0001) !=0) { |
| 106 | Serial.print("Open Circuit, "); |
| 107 | lcd_printStr("Open"); |
| 108 | } |
| 109 | Serial.println(); |
| 110 | } else { |
| 111 | if((thermocouple & 0x8000) == 0){ // 0℃以上 above 0 Degrees Celsius |
| 112 | disp = (thermocouple >> 2) * 0.25; |
| 113 | } else { // 0℃未満 below zero |
| 114 | disp = (0x3fff - (thermocouple >> 2) + 1) * -0.25; |
| 115 | } |
| 116 | Serial.print(thermocouple, HEX); |
| 117 | Serial.print(" : "); |
| 118 | Serial.print(disp); |
| 119 | |
| 120 | Serial.print(" // "); |
| 121 | |
| 122 | lcd_print(disp); |
| 123 | lcd_printStr(unit); |
| 124 | |
| 125 | if((internal & 0x8000) == 0){ // 0℃以上 above 0 Degrees Celsius |
| 126 | disp = (internal >> 4) * 0.0625; |
| 127 | } else { // 0℃未満 below zero |
| 128 | disp = (((0xffff - internal) >> 4) + 1) * -0.0625; |
| 129 | } |
| 130 | Serial.print(internal, HEX); |
| 131 | Serial.print(" : "); |
| 132 | Serial.print(disp); |
| 133 | |
| 134 | Serial.println(); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void lcd_cmd(byte x) { |
| 139 | Wire.beginTransmission(I2Cadr); |
| 140 | Wire.write(0b00000000); // CO = 0,RS = 0 |
| 141 | Wire.write(x); |
| 142 | Wire.endTransmission(); |
| 143 | } |
| 144 | |
| 145 | void lcd_contdata(byte x) { |
| 146 | Wire.write(0b11000000); // CO = 1, RS = 1 |
| 147 | Wire.write(x); |
| 148 | } |
| 149 | |
| 150 | void lcd_lastdata(byte x) { |
| 151 | Wire.write(0b01000000); // CO = 0, RS = 1 |
| 152 | Wire.write(x); |
| 153 | } |
| 154 | |
| 155 | // 文字の表示 |
| 156 | void lcd_printStr(const char *s) { |
| 157 | Wire.beginTransmission(I2Cadr); |
| 158 | while (*s) { |
| 159 | if (*(s + 1)) { |
| 160 | lcd_contdata(*s); |
| 161 | } else { |
| 162 | lcd_lastdata(*s); |
| 163 | } |
| 164 | s++; |
| 165 | } |
| 166 | Wire.endTransmission(); |
| 167 | } |
| 168 | |
| 169 | void lcd_clear() |
| 170 | { |
| 171 | lcd_cmd(0b00000001); |
| 172 | } |
| 173 | // 表示位置の指定 |
| 174 | void lcd_setCursor(byte x, byte y) { |
| 175 | lcd_cmd(0x80 | (y * 0x40 + x)); |
| 176 | } |
| 177 | |
| 178 | void lcd_print(float num) |
| 179 | { |
| 180 | char data[9]; |
| 181 | dtostrf(num,6,1,data); |
| 182 | lcd_printStr(data); |
| 183 | } |
| 184 | }}} |
| 185 | |
| 186 | サンプルスケッチをArduinoに書き込んでArduino IDEのシリアルコンソールを開きます。 |
| 187 | |
| 188 | |