Confusion on selecting pin

I'm using max 31855 module with arduino uno, what my doubt is can I use analog pin as do cs clk as all digital pins are used.

If the library will allow, then Yes.
How long would it take to find out?

I don't know how to check the libraries last time I tested module with digital io it's worked and now the temperature readings are 0c

The 'analog input' pins are good as "regular GPIO".
When using Wire.h, A4 and A5 are dedicated to I2C.

Yes Im using A4 and A5 for i2c oled display but I'm trying to use A1 A2 A3 pins as cs do and clk

Well, if it was working this way the last time you had it on, nothing got smoked because you were using the analog in as GPIO.

@harish0522 you posted this in the wrong section I have moved it here. If you don't now why it the wrong section read the description of the section and note it says not for your project.

Last time I removed every modules I used and only checked max 31855 connected to 3 4 5 as do cs and clk and the readings were perfect now I combined the module with my main project as im using 3 4 5 pins for other components I connected it to A1 A2 A3 now the readings are 0, I think im confusing myself that's why I try to explain what I'm doing and u guys may help me with a solution

"A1, A2 and A3" are also "15, 16, 17", but that should not make a difference.

Maybe you should Post Your Code (in code tags - research "code tags").

this is my code

// display

#include <Wire.h>
#include <Adafruit_SH1106.h>
#define OLED_RESET -1
Adafruit_SH1106 display(OLED_RESET);


//relay and thermocouple

#include <SPI.h>
#include "Adafruit_MAX31855.h"
int relayPin = A0;
#define MAXDO   A1
#define MAXCS   A2
#define MAXCLK  A3
int temp;

// initialize the Thermocouple

Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);



//vertical stepper motor (m1)

const int vertical_direction = 2;
const int vertical_step = 3;
const int vertical_step_per_revolution = 6400;
#define vertical_M 4

#define vertical_home_switch 7 // Pin 7 connected to Home Switch (MicroSwitch)
int vertical_steps;        // Used to set HOME position after Homing is completed

//rotatory stepper motor (m2)

const int rotatory_direction = 8;
const int rotatory_step = 9;
const int rotatory_step_per_revolution = 6400;
#define rotatory_M 10
#define rotatory_home_switch 13 // Pin 13 connected to Home Switch (MicroSwitch)
int rotatory_steps;        // Used to set HOME position after Homing is completed


//defining number of iterations
int iter = 0;
//defining number of increments
int incr = 0;
//defining time for ln2 pumping
int ln2_time = millis();


void setup() {

  // display setup

  Serial.begin(9600);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(18, 12);
  display.println("WELCOME");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(6, 32);
  display.println("BAP.C SAD");
  display.display();
  delay(3000) ;
  Serial.println("check 2");





  //setup for relay and thermocouple

  Serial.begin(9600);
  pinMode(relayPin, OUTPUT);

  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");


  // setup for vertical stepper
  // Declare pins as Outputs
  pinMode(vertical_step, OUTPUT);
  pinMode(vertical_direction, OUTPUT);
  pinMode(vertical_M, OUTPUT);
  pinMode(vertical_home_switch, INPUT_PULLUP);
  digitalWrite(vertical_M, HIGH);

  // setup for rotatory stepper
  // Declare pins as Outputs
  pinMode(rotatory_step, OUTPUT);
  pinMode(rotatory_direction, OUTPUT);
  pinMode(rotatory_M, OUTPUT);
  pinMode(rotatory_home_switch, INPUT_PULLUP);
  digitalWrite(rotatory_M, HIGH);

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(24, 12);
  display.println("Please");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(36, 40);
  display.println("Wait");
  display.display();
  Serial.print("homing");

  // homing vertical motor
  digitalWrite(vertical_direction, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
  while (!digitalRead(vertical_home_switch)) {  // Do this until the switch is not activated

    digitalWrite(vertical_step, HIGH);
    delayMicroseconds(50);                  // Delay to slow down speed of Stepper
    digitalWrite(vertical_step, LOW);
    delayMicroseconds(50);
  }
  digitalWrite(vertical_direction, HIGH);      // (HIGH = anti-clockwise / LOW = clockwise)
  while (digitalRead(vertical_home_switch)) {  // Do this until the switch is activated

    digitalWrite(vertical_step, HIGH);
    delayMicroseconds(500);                  // Delay to slow down speed of Stepper
    digitalWrite(vertical_step, LOW);
    delayMicroseconds(500);
  }
  delay(1000);
  motor_run(10000L, vertical_direction, 1, vertical_step, 100, 1500);
  delay(1000);

  // homing rotatory motor
  while (!digitalRead(rotatory_home_switch)) {  // Do this until the switch is not activated
    digitalWrite(rotatory_direction, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(rotatory_step, HIGH);
    delayMicroseconds(1000);                  // Delay to slow down speed of Stepper
    digitalWrite(rotatory_step, LOW);
    delayMicroseconds(1000);
  }
  while (digitalRead(rotatory_home_switch)) {  // Do this until the switch is activated
    digitalWrite(rotatory_direction, HIGH);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(rotatory_step, HIGH);
    delayMicroseconds(1800);                  // Delay to slow down speed of Stepper
    digitalWrite(rotatory_step, LOW);
    delayMicroseconds(1800);
  }
  delay(1000);
  motor_run(540L, rotatory_direction, 1, rotatory_step, 1000, 1000);
  delay(1000);
  motor_run(63800L, vertical_direction, 1, vertical_step, 100, 1000);


  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(30, 12);
  display.println("Place");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(6, 40);
  display.println("The Vials");
  display.display();
  delay(20000);

  Serial.println("homing completed");

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 25);
  display.println("Processing");
  display.display();


  // 1 cycle of motor moving process cold side
  motor_run(46000L, vertical_direction, 0, vertical_step, 100, 1000);
  motor_run(5200L, rotatory_direction, 1, rotatory_step, 1000, 1000);
  motor_run(46000L, vertical_direction, 1, vertical_step, 100, 1000);

  delay(1000);


  //turing on nitrogen pump for 10 minutes


  while (ln2_time <= 600000000) {
    double C = thermocouple.readCelsius();
    Serial.print("C = ");
    Serial.println(C);
    temp = C;

    if (C < -125) {
      digitalWrite(relayPin, HIGH);
      delay(60000);
    }
    else if (C >= -125) {
      digitalWrite(relayPin, LOW);
    }
    delay(10);
  }

  delay(2000);

}

void loop() {


  Serial.println("iter");
  Serial.print(iter);
  while (iter < 2) {



    // 1 cycle of motor moving process hot side
    motor_run(46000L, vertical_direction, 0, vertical_step, 100, 1000);
    motor_run(5251L, rotatory_direction, 0, rotatory_step, 1000, 1000);
    motor_run(46000L, vertical_direction, 1, vertical_step, 100, 1000);
    delay(60000);

    // 1 cycle of motor moving process cold side
    motor_run(46000L, vertical_direction, 0, vertical_step, 100, 1000);
    motor_run(5251L, rotatory_direction, 1, rotatory_step, 1000, 1000);
    motor_run(46000L, vertical_direction, 1, vertical_step, 100, 1000);

    delay(1000);

    //turing on nitrogen pump for 10 mins

    while (ln2_time <= 600000000) {
      double C = thermocouple.readCelsius();
      Serial.print("C = ");
      Serial.println(C);
      temp = C;

      if (C < -125) {
        digitalWrite(relayPin, HIGH);
        delay(60000);
      }
      else if (C >= -125) {
        digitalWrite(relayPin, LOW);
      }
      delay(10);
    }
  }


  while (incr < 1) {

    // 1 cycle of motor moving process hot side
    motor_run(46000L, vertical_direction, 0, vertical_step, 100, 1000);
    motor_run(5251L, rotatory_direction, 0, rotatory_step, 1000, 1000);
    motor_run(46000L, vertical_direction, 1, vertical_step, 100, 1000);
    incr++;

  }

  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(15, 12);
  display.println("Process");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(9, 40);
  display.println("Completed");
  display.display();


}
void motor_run(long steps, int motor_direction, int dir_hl, int motor_pin, int delay1, int delay2) {
  Serial.println(motor_direction);
  Serial.print(dir_hl);
  digitalWrite(motor_direction, dir_hl);
  // Spin motor slowly
  for (long x = 0; x < steps; x++)
  {
    digitalWrite(motor_pin, HIGH);
    delayMicroseconds(delay1);
    digitalWrite(motor_pin, LOW);
    delayMicroseconds(delay1);
  }
  delay(delay2);
}

I can confirm, having done so, that, with a UNO ─ the MAX31855 is definitely a Go with A1, A2, A3 (for DO, CS, CLK).

// the adafruit example sketch
// wire.h added (though not used)
#include <Wire.h>
#include <SPI.h>
#include "Adafruit_MAX31855.h"

// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO   A1
#define MAXCS   A2
#define MAXCLK  A3

// initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// Example creating a thermocouple instance with hardware SPI
// on a given CS pin.
//#define MAXCS   10
//Adafruit_MAX31855 thermocouple(MAXCS);

void setup() {
  Serial.begin(19200);

  while (!Serial) delay(1); // wait for Serial on Leonardo/Zero, etc

  Serial.println("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  Serial.print("Initializing sensor...");
  if (!thermocouple.begin()) {
    Serial.println("ERROR.");
    while (1) delay(10);
  }
  Serial.println("DONE.");
}

void loop() {
  // basic readout test, just print the current temp
   Serial.print("Internal Temp = ");
   Serial.println(thermocouple.readInternal());

   double c = thermocouple.readCelsius();
   if (isnan(c)) {
     Serial.println("Something wrong with thermocouple!");
   } else {
     Serial.print("C = ");
     Serial.println(c);
   }
   //Serial.print("F = ");
   //Serial.println(thermocouple.readFahrenheit());

   delay(1000);
}

Thankyou, but my temperature reading is 0 can you help me with the code

If the sketch I uploaded works then the problem lies elsewhere.

You have ln2_time declared as an int and equals millis().
i.e. //defining time for ln2 pumping
int ln2_time = millis();
That's wrong.

Then you use that 'variable' in your while loop
where are checking the thermocouple
i.e. while (ln2_time <= 600000000)
and then you use delay() in that same while loop.

Anything having to do with millis() is an
unsigned long.
And 'we' don't mix millis() and delay().

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