Build a Weather Station Part 2: Adding a K-Type Thermocouple (MAX6675)
MAX6675
- K-type thermocouple amplifier, 0–1024 °C, SPI output.
- Module pins: GND, VCC, SCK, CS, SO.
- Adafruit MAX6675 library 1.1.2.
Adafruit example sketch output:
F = 80.15
C = 26.75
F = 80.15
C = 27.00
SPI
- The Adafruit library uses software SPI (bit-bang).
- It cannot share the bus with the SD card module.
- Moved the thermocouple to its own pins.
| Signal | Pin |
|---|---|
| SCK | 8 |
| CS | 4 |
| SO (MISO) | 7 |
| VCC | 5 V |
| GND | GND |
- Software SPI takes 276 ms per reading. Hardware SPI takes 36–68 ms.
- At one reading per second this does not matter. Hardware SPI alternative: zhenek-kreker/MAX6675.
BLE Payload Limit
- Added the thermocouple as a third value:
H,T,C. - The app crashed on the longer string:
Thread 1: "-[__NSCFString substringWithRange:]: Range {9223372036854775807, 0} out of bounds; string length 20"
- BLE minimum ATT_MTU is 23 bytes. The payload was longer than 20.
- Cut to one decimal place and updated the regex.
Arduino:
String data = "H:" + String(h, 1) + " T:" + String(t, 1) + " C:" + String(c, 1);
iPhone:
// \\d in source → \d in regex engine
let pattern = "H:(\\d{1,2}\\.\\d{1,2}) T:(\\d{1,2}\\.\\d{1,2}) C:(\\d{1,2}\\.\\d{1,2})"
Logging
- Some rows were wrong:
-1,1023.97, timestamps out of order.
- Reading the two devices on the shared bus is the likely cause. A slower logging interval is planned for the next test.
References
- Adafruit MAX6675 library
- Alternative hardware-SPI implementations: zhenek-kreker/MAX6675, RobTillaart/MAX6675
- Transferring Data Between Bluetooth Low Energy Devices