Popcorn coffee roaster

I'm building this coffee roaster from a YouTube video from Ben Eagen and the code isn't working with my setup. My setup is exactly like his but I'm getting multiple errors can anyone help me out?

Here is the code I've put it IDE

#include "MAX31855.h"

const int doPin = 7;
const int csPin = 6;
const int clPin = 5;
const int relayPin = 13;

MAX31855 tc(clPin, csPin, doPin);

float getTemp() {
float temp = 0;
for (int i = 0; i < 3; i++) {
temp += tc.getTemperature();
delay(5);
}
return temp / 3;
}

int getSecondsSinceStart() {
return millis() / 1000;
}

int getHeaterOffTime(float targetTemp, int maxDelay) {
int status = tc.read();

if (status != 0) {
Serial.print("Error status in probe, disabling heater: ");
Serial.println(status);
return maxDelay;
}

float currentTemp = getTemp();

// Error describes how far off the target temperature are. This should scale how long heater stays on, or off.
float error = max(0, currentTemp) / targetTemp;
float scalingFactor = 2;

float heatDelay = error * error * error * (maxDelay/scalingFactor) - maxDelay*0.2;

// make sure delay says between 0 and maxDelay
heatDelay = max(0, min(maxDelay, heatDelay));

// Serial.println("Current Temp, Target Temp, Cooling Period");
Serial.print(currentTemp);
Serial.print(",");
Serial.print(targetTemp);
Serial.print(",");
Serial.print(heatDelay);
Serial.println();
return heatDelay;
}

// This function allows a warm up phase, first target temp, and second target temp,
// and finally sets target temp to zero to allow the fan to cool the beans
float getTargetTemp() {
//Time to bring roaster and beans up to a casual warm temp
const int preHeatTimeSeconds = 120;
float preHeatTemp = 120;
//Time at the first roast temp
const int firstTempTimeMins = 9;
float firstRoastTemp = 150;

//Time at the second roast temp
const int secondTempTimeMins = 4;
float secondRoastTemp = 200;

int secondsSinceStart = getSecondsSinceStart();
bool startRoast = secondsSinceStart > preHeatTimeSeconds;
bool preheat = !startRoast;
bool startSecondPhase = secondsSinceStart > preHeatTimeSeconds + firstTempTimeMins * 60;
bool cooldown = secondsSinceStart > preHeatTimeSeconds + (firstTempTimeMins + secondTempTimeMins) * 60;

// Check roasting conditions in reverse order because once these bool values are true,
// they remain true even as subsequent phases start

if (cooldown) {
return 0;
} else if (startSecondPhase) {
return secondRoastTemp;
} else if (startRoast) {
return firstRoastTemp;
} else if (preheat) {
return preHeatTemp;
}
return 0;
}

void setup()
{
Serial.begin(115200);
Serial.print("Starting loop: ");
Serial.println(MAX31855_VERSION);
Serial.println();
tc.begin();
pinMode(relayPin, OUTPUT);
}

void loop()
{
float targetTemp = getTargetTemp();
int updateInterval = 500;
int heaterOffDelay = getHeaterOffTime(targetTemp, updateInterval);
int heaterOnDelay = updateInterval - heaterOffDelay;

// Turn on heater
digitalWrite(relayPin, HIGH);
delay(heaterOnDelay);
delay(5);
digitalWrite(relayPin, LOW);
delay(heaterOffDelay);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Your topic was MOVED to its current forum category which is more appropriate than the original

Please post the full error messages copied from the IDE using the "Copy error message" button and use code tags when you post them

Not much use as the OP didn't use any indentation. So I did it.

#include "MAX31855.h"

const int doPin = 7;
const int csPin = 6;
const int clPin = 5;
const int relayPin = 13;

MAX31855 tc(clPin, csPin, doPin);

float getTemp() {
  float temp = 0;
  for (int i = 0; i < 3; i++) {
    temp += tc.getTemperature();
    delay(5);
  }
  return temp / 3;
}

int getSecondsSinceStart() {
  return millis() / 1000;
}

int getHeaterOffTime(float targetTemp, int maxDelay) {
  int status = tc.read();

  if (status != 0) {
    Serial.print("Error status in probe, disabling heater: ");
    Serial.println(status);
    return maxDelay;
  }

  float currentTemp = getTemp();

  // Error describes how far off the target temperature are. This should scale how long heater stays on, or off.
  float error = max(0, currentTemp) / targetTemp;
  float scalingFactor = 2;

  float heatDelay = error * error * error * (maxDelay / scalingFactor) - maxDelay * 0.2;

  // make sure delay says between 0 and maxDelay
  heatDelay = max(0, min(maxDelay, heatDelay));

  // Serial.println("Current Temp, Target Temp, Cooling Period");
  Serial.print(currentTemp);
  Serial.print(",");
  Serial.print(targetTemp);
  Serial.print(",");
  Serial.print(heatDelay);
  Serial.println();
  return heatDelay;
}

// This function allows a warm up phase, first target temp, and second target temp,
// and finally sets target temp to zero to allow the fan to cool the beans
float getTargetTemp() {
  //Time to bring roaster and beans up to a casual warm temp
  const int preHeatTimeSeconds = 120;
  float preHeatTemp = 120;
  //Time at the first roast temp
  const int firstTempTimeMins = 9;
  float firstRoastTemp = 150;

  //Time at the second roast temp
  const int secondTempTimeMins = 4;
  float secondRoastTemp = 200;

  int secondsSinceStart = getSecondsSinceStart();
  bool startRoast = secondsSinceStart > preHeatTimeSeconds;
  bool preheat = !startRoast;
  bool startSecondPhase = secondsSinceStart > preHeatTimeSeconds + firstTempTimeMins * 60;
  bool cooldown = secondsSinceStart > preHeatTimeSeconds + (firstTempTimeMins + secondTempTimeMins) * 60;

  // Check roasting conditions in reverse order because once these bool values are true,
  // they remain true even as subsequent phases start

  if (cooldown) {
    return 0;
  } else if (startSecondPhase) {
    return secondRoastTemp;
  } else if (startRoast) {
    return firstRoastTemp;
  } else if (preheat) {
    return preHeatTemp;
  }
  return 0;
}

void setup()
{
  Serial.begin(115200);
  Serial.print("Starting loop: ");
  Serial.println(MAX31855_VERSION);
  Serial.println();
  tc.begin();
  pinMode(relayPin, OUTPUT);
}

void loop()
{
  float targetTemp = getTargetTemp();
  int updateInterval = 500;
  int heaterOffDelay = getHeaterOffTime(targetTemp, updateInterval);
  int heaterOnDelay = updateInterval - heaterOffDelay;

  // Turn on heater
  digitalWrite(relayPin, HIGH);
  delay(heaterOnDelay);
  delay(5);
  digitalWrite(relayPin, LOW);
  delay(heaterOffDelay);
}

Did you install the MAX31855 library?

The OP may find that doing this float temp = 0; does not produce the desired result. Use float temp = 0.0;, a 0 is not a 0.0. A 2 is not a 2.0.

I did install the library that he asked for and the thermocouple works in Celsius in the graph with an example program but not with this. I'm at work at the moment and I'll post errors when I get home tonight thanks for all the help so fast!!

While this is a good programming practice, it's not strictly necessary in this case. The 'float' type declaration forces the initialization to be performed as a 'float' type.

You say you are getting mulitiple error messages. Please copy, paste and share the error messages.

I've found that not too always be the case in my early days of using a Uno.

That's extremely weird.

I'll paste em when I get home thank u guys for your help

Here are the errors I have

/private/var/folders/yw/c2_9vgts08n8n6sv1kydy62c0000gn/T/.arduinoIDE-unsaved2022916-41098-15k3kro.m1wn/sketch_oct16a/sketch_oct16a.ino:8:32: error: no matching function for call to 'MAX31855::MAX31855(const int&, const int&, const int&)'
MAX31855 tc(clPin, csPin, doPin);
^
In file included from /private/var/folders/yw/c2_9vgts08n8n6sv1kydy62c0000gn/T/.arduinoIDE-unsaved2022916-41098-15k3kro.m1wn/sketch_oct16a/sketch_oct16a.ino:1:0:
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:67:3: note: candidate: MAX31855::MAX31855()
MAX31855();
^~~~~~~~
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:67:3: note: candidate expects 0 arguments, 3 provided
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:63:7: note: candidate: constexpr MAX31855::MAX31855(const MAX31855&)
class MAX31855
^~~~~~~~
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:63:7: note: candidate expects 1 argument, 3 provided
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:63:7: note: candidate: constexpr MAX31855::MAX31855(MAX31855&&)
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:63:7: note: candidate expects 1 argument, 3 provided
/private/var/folders/yw/c2_9vgts08n8n6sv1kydy62c0000gn/T/.arduinoIDE-unsaved2022916-41098-15k3kro.m1wn/sketch_oct16a/sketch_oct16a.ino: In function 'void setup()':
/private/var/folders/yw/c2_9vgts08n8n6sv1kydy62c0000gn/T/.arduinoIDE-unsaved2022916-41098-15k3kro.m1wn/sketch_oct16a/sketch_oct16a.ino:95:12: error: no matching function for call to 'MAX31855::begin()'
tc.begin();
^
In file included from /private/var/folders/yw/c2_9vgts08n8n6sv1kydy62c0000gn/T/.arduinoIDE-unsaved2022916-41098-15k3kro.m1wn/sketch_oct16a/sketch_oct16a.ino:1:0:
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:70:12: note: candidate: void MAX31855::begin(uint8_t)
void begin(uint8_t select);
^~~~~
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:70:12: note: candidate expects 1 argument, 0 provided
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:72:12: note: candidate: void MAX31855::begin(uint8_t, uint8_t, uint8_t)
void begin(uint8_t clock, uint8_t select, uint8_t miso);
^~~~~
/Users/owner/Documents/Arduino/libraries/MAX31855_RT/MAX31855.h:72:12: note: candidate expects 3 arguments, 0 provided

exit status 1

Compilation error: no matching function for call to 'MAX31855::MAX31855(const int&, const int&, const int&)'

Lmao I don't know how to format this [EXPLETIVE DELETED] I'm sorry guys

That message does not have any meaning to you?

I take it you are using this library, GitHub - Zanduino/MAX31855: Read thermocouple temperature using a MAX31855 converter?

Here is the setup from the example, MAX31855.begin(SPI_CHIP_SELECT) the constructor only takes 1 argument.

The library I'm using is MAX31855 by Rob Tillaart and yes I'm using a MAX31855

When you fix the constructor issue, post the new code and new error messages.

I don't know what constructor part you're talking about I don't program in C++

@anon86329941 this forum is a resource for Arduino users of all ages. Please refrain from using profanity.

This is not the constructor

MAX31855 tc(clPin, csPin, doPin);
// this argument expects 0 parameters, but you provided 3
tc.begin();
// this argument expects 3 parameters, but you give 0

See a pattern?