Sparkfun product: https://www.sparkfun.com/products/16295
Board: Official Arduino Nano
Library: https://github.com/sparkfun/SparkFun_MC … no_Library
I checked out the examples and learned how to use this amplifier before implementing it in my program. I noticed that unless I had a Serial.print immediately before getting the reading, the reading would just return 0. After confirming that it really was because I was removing the serial line, I went back to the sparkfun MCP9600 library example and tried the same. The BasicReadings example works fine, but if you comment out this line the reading will fail:
Serial.print("Thermocouple: ");
I’ve tried replacing it with delays of various lengths and it still fails. It has to be a serial.print with at LEAST 5 characters. Any less and the problem persists so it makes me think it is some kind of timing issue.
Can someone with one of these sensor boards confirm this? Here is the library example:
This code will work:
/*
Temperature Measurements with the MCP9600 Thermocouple Amplifier
By: Fischer Moseley
SparkFun Electronics
Date: July 8, 2019
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware License).
This example outputs the ambient and thermocouple temperatures from the MCP9600 sensor.
Hardware Connections:
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
Plug the sensor onto the shield
Serial.print it out at 115200 baud to serial monitor.
*/
#include <SparkFun_MCP9600.h>
MCP9600 tempSensor;
void setup(){
Serial.begin(115200);
Wire.begin();
Wire.setClock(100000);
tempSensor.begin(); // Uses the default address (0x60) for SparkFun Thermocouple Amplifier
//tempSensor.begin(0x66); // Default address (0x66) for SparkX Thermocouple Amplifier
//check if the sensor is connected
if(tempSensor.isConnected()){
Serial.println("Device will acknowledge!");
}
else {
Serial.println("Device did not acknowledge! Freezing.");
while(1); //hang forever
}
//check if the Device ID is correct
if(tempSensor.checkDeviceID()){
Serial.println("Device ID is correct!");
}
else {
Serial.println("Device ID is not correct! Freezing.");
while(1);
}
}
void loop(){ //print the thermocouple, ambient and delta temperatures every 200ms if available
if(tempSensor.available()){
Serial.print("Thermocouple: ");
Serial.print(tempSensor.getThermocoupleTemp());
Serial.print(" °C Ambient: ");
Serial.print(tempSensor.getAmbientTemp());
Serial.print(" °C Temperature Delta: ");
Serial.print(tempSensor.getTempDelta());
Serial.print(" °C");
Serial.println();
delay(20); //don't hammer too hard on the I2C bus
}
}
Output:
Device will acknowledge!
Device ID is correct!
Thermocouple: 20.62 c Ambient: 66.09 c Temperature Delta: 34.81 c
Thermocouple: 20.50 c Ambient: 65.86 c Temperature Delta: 34.81 c
Thermocouple: 20.44 c Ambient: 65.75 c Temperature Delta: 34.81 c
Thermocouple: 20.56 c Ambient: 65.97 c Temperature Delta: 34.81 c
Thermocouple: 20.44 c Ambient: 65.75 c Temperature Delta: 34.81 c
Thermocouple: 20.75 c Ambient: 66.20 c Temperature Delta: 34.93 c
Thermocouple: 20.69 c Ambient: 66.09 c Temperature Delta: 34.93 c
Thermocouple: 20.69 c Ambient: 66.09 c Temperature Delta: 34.93 c
Thermocouple: 20.56 c Ambient: 65.86 c Temperature Delta: 34.93 c
Thermocouple: 20.69 c Ambient: 66.09 c Temperature Delta: 35.04 c
Thermocouple: 20.69 c Ambient: 66.09 c Temperature Delta: 35.04 c
Thermocouple: 20.56 c Ambient: 65.86 c Temperature Delta: 35.04 c
Thermocouple: 20.56 c Ambient: 65.86 c Temperature Delta: 35.04 c
This will NOT work:
/*
Temperature Measurements with the MCP9600 Thermocouple Amplifier
By: Fischer Moseley
SparkFun Electronics
Date: July 8, 2019
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware License).
This example outputs the ambient and thermocouple temperatures from the MCP9600 sensor.
Hardware Connections:
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
Plug the sensor onto the shield
Serial.print it out at 115200 baud to serial monitor.
*/
#include <SparkFun_MCP9600.h>
MCP9600 tempSensor;
void setup(){
Serial.begin(115200);
Wire.begin();
Wire.setClock(100000);
tempSensor.begin(); // Uses the default address (0x60) for SparkFun Thermocouple Amplifier
//tempSensor.begin(0x66); // Default address (0x66) for SparkX Thermocouple Amplifier
//check if the sensor is connected
if(tempSensor.isConnected()){
Serial.println("Device will acknowledge!");
}
else {
Serial.println("Device did not acknowledge! Freezing.");
while(1); //hang forever
}
//check if the Device ID is correct
if(tempSensor.checkDeviceID()){
Serial.println("Device ID is correct!");
}
else {
Serial.println("Device ID is not correct! Freezing.");
while(1);
}
}
void loop(){ //print the thermocouple, ambient and delta temperatures every 200ms if available
if(tempSensor.available()){
//Serial.print("Thermocouple: ");
Serial.print(tempSensor.getThermocoupleTemp());
Serial.print(" °C Ambient: ");
Serial.print(tempSensor.getAmbientTemp());
Serial.print(" °C Temperature Delta: ");
Serial.print(tempSensor.getTempDelta());
Serial.print(" °C");
Serial.println();
delay(20); //don't hammer too hard on the I2C bus
}
}
output:
Device will acknowledge!
Device ID is correct!
20.19 c Ambient: 65.97 c Temperature Delta: 34.14 c
0.00 c Ambient: 65.75 c Temperature Delta: 32.00 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.36 c
0.00 c Ambient: 65.75 c Temperature Delta: 34.36 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.36 c
0.00 c Ambient: 65.86 c Temperature Delta: 34.47 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.36 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.47 c
0.00 c Ambient: 65.97 c Temperature Delta: 32.00 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.47 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.47 c
0.00 c Ambient: 65.75 c Temperature Delta: 34.47 c
0.00 c Ambient: 65.97 c Temperature Delta: 34.47 c