├── README.md └── MAX6675 └── MAX6675.ino /README.md: -------------------------------------------------------------------------------- 1 | # MAX6675 2 | MAX6675 Thermocouple Adapter Library 3 | -------------------------------------------------------------------------------- /MAX6675/MAX6675.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #define SS_PIN (10) 4 | //#define DEBUG_EN 5 | void setup() 6 | { 7 | Serial.begin(9600); 8 | SPI.begin(); 9 | SPI.setClockDivider(SPI_CLOCK_DIV32); 10 | pinMode(SS_PIN,OUTPUT); 11 | digitalWrite(SS_PIN, HIGH); 12 | 13 | } 14 | 15 | void loop() 16 | { 17 | uint16_t temperature=0; 18 | uint8_t buffer[2]; 19 | 20 | digitalWrite(SS_PIN, LOW); 21 | buffer[0]=SPI.transfer(0xaa); 22 | buffer[1]=SPI.transfer(0xaa); 23 | digitalWrite(SS_PIN, HIGH); 24 | 25 | temperature = (buffer[0]&0x7F); 26 | temperature = temperature<<8; 27 | temperature &= 0xff00; 28 | temperature |= (buffer[1]>>3); 29 | Serial.println("***************"); 30 | #ifdef DEBUG_EN 31 | Serial.print("B0-B7 "); 32 | Serial.println(buffer[1],HEX); 33 | Serial.print("B8-B15 "); 34 | Serial.println(buffer[0],HEX); 35 | #endif 36 | 37 | if ((buffer[1]&0x04)!=0) { 38 | Serial.println("!!!!!Thermocouple OPEN!!!!!"); 39 | Serial.println("Following reading may be invalid"); 40 | } 41 | Serial.print("Ambient Temperature is "); 42 | Serial.println((float)temperature*1024/32768,DEC); 43 | Serial.println("***************"); 44 | 45 | delay(1000); 46 | 47 | 48 | } 49 | --------------------------------------------------------------------------------