Grove I2C Thermocouple Amplifier (MCP9600) Errors

Hi!

I am having issues with running the example code for the Thermocouple Amplifier. I originally was running into an issue where it said it could not detect any ".h" files, so I moved the file and that was resolved (for the time being). However, I have another issue with the code specifically one that says "note: this is the location of the previous definition #define SERIAL 0x0". I'm not quite sure how to work with this because I am simply just trying to see if the code for the example works before tackling my own project.

Any help would be appreciated!

Thanks!

Please, we don't know anything about your project. Please supply links to the amplifier, and the project code. If you have written code, please post it in code tags in a new message.

Hi!

Right now, I am just trying to get the example code to work. The code that I am trying to use is the basic demo code below.

#include "Seeed_MCP9600.h"

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif

MCP9600 sensor;

err_t sensor_basic_config() {
err_t ret = NO_ERROR;
CHECK_RESULT(ret, sensor.set_filt_coefficients(FILT_MID));
CHECK_RESULT(ret, sensor.set_cold_junc_resolution(COLD_JUNC_RESOLUTION_0_25));
CHECK_RESULT(ret, sensor.set_ADC_meas_resolution(ADC_14BIT_RESOLUTION));
CHECK_RESULT(ret, sensor.set_burst_mode_samp(BURST_32_SAMPLE));
CHECK_RESULT(ret, sensor.set_sensor_mode(NORMAL_OPERATION));
return ret;
}

err_t get_temperature(float* value) {
err_t ret = NO_ERROR;
float hot_junc = 0;
float junc_delta = 0;
float cold_junc = 0;
CHECK_RESULT(ret, sensor.read_hot_junc(&hot_junc));
CHECK_RESULT(ret, sensor.read_junc_temp_delta(&junc_delta));

CHECK_RESULT(ret, sensor.read_cold_junc(&cold_junc));

// SERIAL.print("hot junc=");
// SERIAL.println(hot_junc);
// SERIAL.print("junc_delta=");
// SERIAL.println(junc_delta);
// SERIAL.print("cold_junc=");
// SERIAL.println(cold_junc);

*value = hot_junc;

return ret;

}

void setup() {
SERIAL.begin(115200);
delay(10);
SERIAL.println("serial start!!");
if (sensor.init(THER_TYPE_K)) {
SERIAL.println("sensor init failed!!");
}
sensor_basic_config();
}

void loop() {
float temp = 0;
get_temperature(&temp);
SERIAL.print("temperature ===================>");
SERIAL.println(temp);
SERIAL.println(" ");
SERIAL.println(" ");
delay(1000);
}

Here is a link to the amplifier which links to documentation.

Again, the error that I get is "note: this is the location of the previous definition
#define SERIAL 0x0".

What board are you using? Can you give us a screen shot of the error. posting the error in text is technically correct but with a screenshot its easier to get a better sense of what is going on.

Hi, @dr05
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

This will help with advice on how to present your code and problems.

Tom... :smiley: :+1: :coffee: :australia:

I'm not positive but I think "serial" cannot be used as a variable, regardless of capitalization.

Would be easy to check. Change all "SERIAL" to SerialA or something. If it compiles without error you have your answer.

Hi everyone!

Thanks for all the insight and help with the example code. I tried the suggestion of changing SERIAL to SerialA and I no longer run into that error, so thank you for that. Now I guess I can explain what I'm actually working on.

I am working on a temperature reader where the thermocouple amplifier is used to detect the temperature of food (the range is 140-160). I am trying to create a project that will buzz at the user if the food is not in this range and gives a blinking LED when the temperature reading is within the range. I also have my project set up so that you can turn the buzzer on and off so it's not constantly buzzing when it can't detect a temperature in that range.

I am running into the problem that either the thermocouple amplifier is not detecting when the temperature is in the range or something is wrong with my code in the fact that the buzzer doesn't go off even when the probe is placed in something that should be within the given range (e.g. boiling water).

Here is what I have thus far:

#include "Seeed_MCP9600.h"

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIALA SerialUSB
#else
#define SERIALA Serial
#endif

MCP9600 sensor;

err_t sensor_basic_config() {
  err_t ret = NO_ERROR;
  CHECK_RESULT(ret, sensor.set_filt_coefficients(FILT_MID));
  CHECK_RESULT(ret, sensor.set_cold_junc_resolution(COLD_JUNC_RESOLUTION_0_25));
  CHECK_RESULT(ret, sensor.set_ADC_meas_resolution(ADC_14BIT_RESOLUTION));
  CHECK_RESULT(ret, sensor.set_burst_mode_samp(BURST_32_SAMPLE));
  CHECK_RESULT(ret, sensor.set_sensor_mode(NORMAL_OPERATION));
  return ret;
}


err_t get_temperature(float* value) {
  err_t ret = NO_ERROR;
  float hot_junc = 0;
  float junc_delta = 0;
  float cold_junc = 0;
  CHECK_RESULT(ret, sensor.read_hot_junc(&hot_junc));
  CHECK_RESULT(ret, sensor.read_junc_temp_delta(&junc_delta));

  CHECK_RESULT(ret, sensor.read_cold_junc(&cold_junc));

  // SERIAL.print("hot junc=");
  // SERIAL.println(hot_junc);
  // SERIAL.print("junc_delta=");
  // SERIAL.println(junc_delta);
  // SERIAL.print("cold_junc=");
  // SERIAL.println(cold_junc);

  *value = hot_junc;

  return ret;
}

const int buttonPin = 6;
const int ledPin = 4;
int buzzerPin = 5;
int buttonState = 0;
int led = 0;

void setup() {
  SERIALA.begin(115200);
  delay(10);
  SERIALA.println("serial start!!");
  if (sensor.init(THER_TYPE_K)) {
    SERIALA.println("sensor init failed!!");
  }
  sensor_basic_config();
  pinMode(ledPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  float i = 0;
  get_temperature(&i);
  SERIALA.print("temperature ===================>");
  SERIALA.println(i);
  SERIALA.println(" ");
  SERIALA.println(" ");
  delay(1000);
  buttonState = digitalRead(buttonPin);

  //if i is not found in given range, then return 0
  //if 0, then buzzer is on high (on)
  //if 0, then led off
  //if i is found in given range, return 1
  //if 1, then buzzer is on low (0)
  //if 1, then turn led on to blink

  if (buttonState == HIGH) {
    if (led == 0) {
      led = 1;
      digitalWrite(ledPin, HIGH);
    }
    else {
      led = 0;
      digitalWrite(ledPin, LOW);
    }
    delay (50);
  }


  if (i > 140 && i < 160) {
    analogWrite(buzzerPin, 0);
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
    delay(1000);
  }
  else {
    analogWrite(buzzerPin, 127);
    digitalWrite(ledPin, LOW);
  }

}

I'm not sure if I simply patched instead of solved the issue with the thermocouple amplifier earlier because while I don't run into that error anymore when I run even the example code, the serial monitor gives me a bunch of gibberish rather than temperature readings. Also, before I forget, I am using an Arduino Uno Board that is a part of the Grove Beginner Kit.

Thanks again! I really do appreciate it!

Also I am reposting the Thermocouple Amplifier code in code tags since I did not do that previously.

#include "Seeed_MCP9600.h"
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIALA SerialUSB
#else
#define SERIALA Serial
#endif

MCP9600 sensor;

err_t sensor_basic_config() {
  err_t ret = NO_ERROR;
  CHECK_RESULT(ret, sensor.set_filt_coefficients(FILT_MID));
  CHECK_RESULT(ret, sensor.set_cold_junc_resolution(COLD_JUNC_RESOLUTION_0_25));
  CHECK_RESULT(ret, sensor.set_ADC_meas_resolution(ADC_14BIT_RESOLUTION));
  CHECK_RESULT(ret, sensor.set_burst_mode_samp(BURST_32_SAMPLE));
  CHECK_RESULT(ret, sensor.set_sensor_mode(NORMAL_OPERATION));
  return ret;
}


err_t get_temperature(float* value) {
  err_t ret = NO_ERROR;
  float hot_junc = 0;
  float junc_delta = 0;
  float cold_junc = 0;
  CHECK_RESULT(ret, sensor.read_hot_junc(&hot_junc));
  CHECK_RESULT(ret, sensor.read_junc_temp_delta(&junc_delta));

  CHECK_RESULT(ret, sensor.read_cold_junc(&cold_junc));

  // SERIAL.print("hot junc=");
  // SERIAL.println(hot_junc);
  // SERIAL.print("junc_delta=");
  // SERIAL.println(junc_delta);
  // SERIAL.print("cold_junc=");
  // SERIAL.println(cold_junc);

  *value = hot_junc;

  return ret;
}


void setup() {
  SERIALA.begin(115200);
  delay(10);
  SERIALA.println("serial start!!");
  if (sensor.init(THER_TYPE_K)) {
    SERIALA.println("sensor init failed!!");
  }
  sensor_basic_config();
}



void loop() {
  float temp = 0;
  get_temperature(&temp);
  SERIALA.print("temperature ===================>");
  SERIALA.println(temp);
  SERIALA.println(" ");
  SERIALA.println(" ");
  delay(1000);
}

Please let me know if there is any other information I can provide :slightly_smiling_face:

Check to verify the IDE Serial monitor baud rate matches the baud rate you set in your program.

As far as the serial monitor is concerned you SHOULD at the very least be seeing one of the messages from setup{}
If its garbage, as @JohnRob says its almost certainly that the monitor rate doesnt match the selected baud rate (115200)

I cant see any code to operate a buzzer or led.

If the most important variable is the temperature, could you give it a proper name, for example: float temperature;

When you mention a temperature, could you tell which temperature that is ?

  • 140 - 160 °C   Celsius
  • 140 - 160 °F   Fahrenheit
  • 140 - 160 °K   Kelvin

0 voters

The MCP9600 returns the temperature in Celsius, but then I don't understand why you want to measure fruit above boiling point.

Hi everyone!

Again thank you for all the help! I ended up changing the baud and it works now! This was just a fun project trying to create something that can detect the temperature of warm food and make sure it is within a range that can be eaten. I appreciate you all helping along the way and teaching me some new things about coding and the amplifier. If I have any more questions I will definitely post them here but in the meantime have a great day!

Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.