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!