MAX6675

  • K-type thermocouple amplifier, 0–1024 °C, SPI output.
  • Module pins: GND, VCC, SCK, CS, SO.
  • Adafruit MAX6675 library 1.1.2.
SainSmart MAX6675 module with K-type thermocouple
SainSmart MAX6675 module and K-type thermocouple. Pins: GND, VCC, SCK, CS, SO. Source: Amazon listing
Adafruit MAX6675 library in the Arduino Library Manager Serial monitor showing alternating F and C readings
Library installed, example sketch running. The serial output alternates F and C.

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})"
Xcode showing a fatal error while unwrapping the parsed humidity value
Parsing the three values in the app. Line 168 crashed on a nil unwrap before the regex was fixed.

Logging

CSV log opened in a spreadsheet
CSV from the SD card on 2023-12-01: time, air temperature, relative humidity, reference temperature.
  • Some rows were wrong: -1, 1023.97, timestamps out of order.
Spreadsheet rows with -1 and 1023.97 values Reference temperature chart swinging between 0 and 90 degrees
Bad rows in the log and the reference temperature swinging 0–90 °C.
  • Reading the two devices on the shared bus is the likely cause. A slower logging interval is planned for the next test.

References