max6675 thermocouple issues on CS pin

Hello,

I made a solder hot plate thingy, using this link:

https://github.com/makermoekoe/Hotplate-Soldering-Iron/blob/master/Code/hotplate_poti.ino

Conponments;
5v psu - input to the nano, everything else is running from 3.3v
ssr
oled
nano
max6675 module
k type thermos
iron base

The purpose is to solder smd conponets. It consists of two displays, one being a temp which the user selects using the pot and another screen which shows whether the device is ‘off’ ‘preheat’ and ‘reflow’ and shows the current temp from the thermos. So, one oled is used with two different screen, showing which state it is in or another screen comes up when the pot is adjusted.

A push button is pressed and the relay is powered, letting 230VAC power the iron, this is until the temp reaches 150C and then the button is pressed when ready, with the temp being raised to the set point. As the screen is flickering between displays, the button can not be selected.

It all worked perfectly until I switched the thermocouple out for a shorter one, which didn’t work. So I put the original thermos back and now the display flicks between both displays and I’m unable to start the process as the screen will not settle. No idea what has happened. I checked all of the connections, gnd, vcc etc.

Now, when I remove the cs from the max6675 module, the screen settle on the correct screen. Reattatch and again, it bounces between both screens. I resoldered the connection but nothing. Is this a clock issue?

code below - I’m using different dig pins but the CS is connected to 10.

#include <SPI.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#include "max6675.h"





#define COOLDOWN_TIME 60 //60

#define PREHEAT_TIME 60

#define REFLOW_TIME 60





#define OLED_RESET 0  // GPIO0

Adafruit_SSD1306 display(OLED_RESET);



int thermoDO = 12;

int thermoCS = 13;

int thermoCLK = 14;



MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);



const int button = 2;

const int solidstate = 15;

const int poti = A0;





const int temp_preheat = 150;

const int temp_reflow = 240;



int temp_now = 0;

int temp_next = 0;

int temp_poti = 0;

int temp_poti_old = 0;

String state[] = {"OFF", "PREHEAT", "REFLOW", "COOLING"};

int state_now = 0;



int time_count = 0;

int perc = 0;



int offset = 0;



void setup() {

  pinMode(button, INPUT);

  pinMode(solidstate, OUTPUT);

  digitalWrite(solidstate, LOW);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

  display.clearDisplay();

  display.display();

}



long t = millis();

long t_solder = millis();



void loop() {

  temp_now = thermocouple.readCelsius();



  temp_poti = map(analogRead(poti), 1023, 0, temp_preheat, temp_reflow);



  if (temp_poti != temp_poti_old) {

    int v = 0;

    display.fillScreen(WHITE);

    display.setTextColor(BLACK);

    display.setTextSize(1);

    display.setCursor(X(1, 7), Y(1, 0.1));

    display.println("PREHEAT");

    display.setTextSize(2);

    display.setCursor(X(2, 3), Y(2, 0.5));

    while (v < 100) {

      temp_poti = map(analogRead(poti), 1023, 0, temp_preheat, temp_reflow);

      if (temp_poti > temp_poti_old + 1 || temp_poti < temp_poti_old - 1) {

        display.fillScreen(WHITE);

        display.setTextSize(1);

        display.setCursor(X(1, 6), Y(1, 0.1));

        display.println("REFLOW");

        display.setTextSize(2);

        display.setCursor(X(2, 3), Y(2, 0.5));

        display.println(String(temp_poti));

        display.display();

        temp_poti_old = temp_poti;

        v = 0;

      }

      v++;

      delay(20);

    }

    temp_poti_old = temp_poti;

  }



  if (millis() > t + 200 || millis() < t) {

    PrintScreen(state[state_now], temp_next, temp_now, time_count, perc);

    t = millis();

  }





  if (digitalRead(button) == 0) {

    delay(100);

    int c = 0;

    while (digitalRead(button) == 0) {

      c++;

      if (c > 150) {

        digitalWrite(solidstate, LOW);

        state_now = 0;

        display.fillScreen(WHITE);

        display.setTextColor(BLACK);

        display.setTextSize(2);

        display.setCursor(X(2, 3), Y(2, 0.5));

        display.println("OFF");

        display.display();

        while (digitalRead(button) == 0) delay(1);

        return;

      }

      delay(10);

    }



    t_solder = millis();

    perc = 0,

    state_now++;

    if (state_now == 0) temp_next = 0;

    else if (state_now == 1) temp_next = temp_preheat;

    else if (state_now == 2) temp_next = temp_poti;

    else if (state_now == 3) temp_next = 0;

    else if (state_now == 4) {

      state_now = 0;

      temp_next = 0;

    }

  }





  if (state_now == 1) { //PREHEAT

    regulate_temp(temp_now, temp_next);



    perc = int((float(temp_now) / float(temp_next)) * 100.00);

  }

  else if (state_now == 2) { //REFLOW

    regulate_temp(temp_now, temp_next);



    perc = int((float(temp_now) / float(temp_next)) * 100.00);

    if (perc >= 100) {

      state_now = 3;

      t_solder = millis();

      perc = 0;

      temp_next = 0;

    }

  }

  else if (state_now == 3) { //COOLING

    digitalWrite(solidstate, LOW);



    time_count = int((t_solder + COOLDOWN_TIME * 1000 - millis()) / 1000);

    if (time_count <= 0) {

      state_now = 0;

    }

  }

  else {

    digitalWrite(solidstate, LOW);

    time_count = 0;

  }



  delay(30);

}









void regulate_temp(int temp, int should) {

  if (should <= temp - offset) {

    digitalWrite(solidstate, LOW);

  }

  else if (should > temp + offset) {

    digitalWrite(solidstate, HIGH);

  }

}





void PrintScreen(String state, int soll_temp, int ist_temp, int tim, int percentage) {

  display.clearDisplay();

  display.setTextColor(WHITE);

  display.setTextSize(1);

  display.setCursor(0, 0);

  display.println(state);



  display.setCursor(80, 0);

  String str = String(soll_temp) + " deg";

  display.println(str);



  if (tim != 0) {

    display.setCursor(0, 50);

    str = String(tim) + " sec";

    display.println(str);

  }



  if (percentage != 0) {

    display.setCursor(80, 50);

    str = String(percentage) + " %";

    display.println(str);

  }



  display.setTextSize(2);

  display.setCursor(30, 22);

  str = String(ist_temp) + " deg";

  display.println(str);



  display.display();

}





int X(int textgroesse, int n) {

  //gibt die X koordinate aus, damit text mit n zeichen mittig ist



  return (0.5 * (display.width() - textgroesse * (6 * n - 1)));

}//end int X



int Y(int textgroesse, float f) {

  //gibt die Y koordinate aus, damit text mittig ist



  return (f * display.height() - (textgroesse * 4));

}//end int Y

Just thinking aloud here, as at work and unable to check. I wonder if this is causing a clash

#define OLED_RESET 0  // GPIO0

The code was written for a D1 mini, which I changed for a Nano. Normall I use OLED_RESET 4.

This thread is not needed now, it turns out the problem lies within the supply, which I've discussed here, for further help.

https://forum.arduino.cc/index.php?topic=662196.0

This thread can be deleted or archived please, thank you