Multiple Thermocouples on nano

Hi, I am new to Arduino and the forum. I have been fiddling for about a month now and one of my first projects is connecting a K type thermocouple to a Nano board to measure some temperatures on a piston engine. I have managed to copy/paste/modify code enabling me to read one thermocouple. I would be appreciate for a novice like myself if someone could advise how to connect multiple thermocouple (4 in my case) to a nano board with the additional code required. This is what I have successfully used so far
Average Thermocouple
Average Thermocouple

Reads a temperature from a thermocouple based
on the MAX6675 driver and displays it in the default Serial.

GitHub - YuriiSalimov/MAX6675_Thermocouple: [For Arduino] Library for working with a thermocouple based on the MAX6675 driver.

Created by Yurii Salimov, May, 2019.
Released into the public domain.
*/
#include <Thermocouple.h>
#include <MAX6675_Thermocouple.h>

#define SCK_PIN 6
#define CS_PIN 5
#define SO_PIN 4

Thermocouple* thermocouple;

// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);

thermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
}

// the loop function runs over and over again forever
void loop() {
// Reads temperature
const double celsius = thermocouple->readCelsius();
const double kelvin = thermocouple->readKelvin();
const double fahrenheit = thermocouple->readFahrenheit();

// Output of information
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.print(" C, ");
Serial.print(fahrenheit);
Serial.println(" F");

delay(500); // optionally, only to delay the output of information in the example.

Hello. Please read the forum rules, format your code, copy it for the forum and paste it here.

Based on the library source code, you need an individual pin for the CS (chip select) of each thermocouple; e.g.

#define SCK_PIN 6
#define SO_PIN 4

#define CS_PIN1 5
#define CS_PIN2 7

And you can create a couple of pointers to objects

Thermocouple* thermocouple1;
Thermocouple* thermocouple2;

In setup(), you can initialise them

thermocouple1 = new MAX6675_Thermocouple(SCK_PIN, CS_PIN1, SO_PIN);
thermocouple2 = new MAX6675_Thermocouple(SCK_PIN, CS_PIN2, SO_PIN);

And in loop() you can read each of them

double celsius = thermocouple1->readCelsius();
Serial.print("Temperature 1: ");
Serial.print(celsius);
Serial.print(" C, ");

celsius = thermocouple2->readCelsius();
Serial.print("Temperature 2: ");
Serial.print(celsius);
Serial.print(" C, ");

Not compiled, not tested. Give it a try, if it works as expected it can be optimised; each time you start numbering variables (like I did), you should start thinking about arrays.

// Edit
Changed the second double celsius = thermocouple2->readCelsius(); to celsius = thermocouple2->readCelsius();. Copy/paste error, sorry.

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