coding more than one instance of object

This is one of the few times that I have searched and studied a topic on this site (and google) that I came away more confused than when I started. I thought it would be a simple task given the library from Olimex, for their MOD-TC. I have attached the library and examples (I hope).
Here is the code for a single tc module. I changed the pins from the example using Vcc and Vss from the UNO and it works -for one module :-[

#include "max6675.h"

//Pins for the Olimexino-328
int thermoDO = 12;
int thermoCS = 7;
int thermoCLK = 13;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

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

  
  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print("C = "); 
   Serial.println(thermocouple.readCelsius());
   Serial.print("F = ");
   Serial.println(thermocouple.readFarenheit());
 
   delay(1000);
}

Then I changed the code to read 2 TCs like this but it isn't working...this is what I tried

// this example is public domain. enjoy!
// www.ladyada.net/learn/sensors/thermocouple

#include "max6675.h"

int thermoDO = 4;
int thermoCS = 5;
int thermo2CS = 6;
int thermoCLK = 7;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);  // these are the constructors
MAX6675 thermocouple2(thermoCLK, thermo2CS, thermoDO); // but clearly I am not executing them correvtly
  
void setup() {
  Serial.begin(9600);

  
  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print("C1 = "); 
   Serial.println(thermocouple.readCelsius());
 Serial.print("C2 = "); 
   Serial.println(thermocouple2.readCelsius());
 
   delay(1000);
}

I'm trying to read 2 TCs using only 4 digital pins by fanning out the CLK and DO pins and assigning 2 different pins for the CS.

As I stated before I don't understand how to code the library constructors. So I searched for C++ Classes, Arduino Library Tutorial, API tutorial as well as searching the forums and found lots of info but ... BTW I have posted this question here also
Arduino Forum > Using Arduino > Networking, Protocols, and Devices

Atmega ICSP header and Digital Pin assignments

But I'm still confused :disappointed_relieved: So if anyone can point to or show me an example of instantiating two instances in this case the MOD-TC modules I really need some help!
Gene

keywords.txt (508 Bytes)

max6675.cpp (1.09 KB)

max6675.h (362 Bytes)

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);  // these are the constructors
MAX6675 thermocouple2(thermoCLK, thermo2CS, thermoDO); // but clearly I am not executing them correvtly

First, do you count yes, 2, 3, 4? Or do you count 1, 2, 3, 4? If you are going to number on instance in a set, number ALL instances in the set.

Second, do you really think you can use the same clock pin for both? It's hard to guess what the third argument is, but it is unlikely that that can be the same for both instances.

I'm trying to read 2 TCs using only 4 digital pins by fanning out the CLK and DO pins and assigning 2 different pins for the CS.

Why do you assume that this is possible? Start with the simpler case of NOT trying to share a pin. Only when that works should you experiment with sharing a pin.

BTW I have posted this question here also

We HATE crossposting.

In what way is it not working? Compiler errors? Tell us them.

Hi PaulS thanks for the input

Second, do you really think you can use the same clock pin for both? It's hard to guess what the third argument is, but it is unlikely that that can be the same for both instances.

I'm sure that a digital output pin can be shared (fanned out) to 2 or 3 inputs.
The MAX 6675 uses 3 signals CS SCK and DO (data out) (plus Vcc and Gnd)

The code works for one I am just trying to read 2
Finally, I was unaware that cross posting is a no no - I apologize for the foe-pah

it compiles no errors but the data outputs:

MAX6675 test
C1 = 0.00
C2 = 0.00
C1 = 0.00

The MAX 6675 uses 3 signals CS SCK and DO (data out) (plus Vcc and Gnd)

So, you somehow expect to read data from two thermocouples on one pin, and know which you are reading from.

Have you tried using three pins for each one? That seems like such a simple thing to do.

PaulS, SPI works like that. You know which chip you're talking to because you know which CS line you pulled low. You've seen SPI before right?

Yes, I have. I figured that, sooner or later, OP would past a link, rather than a vague description of, the sensor, so we could easily check what form of communication was involved.

Hi everyone and thanks for the participation!
A few things have come to light. I've discovered that the 10 pin header on the Mod-TC units have different pin outs! Of course I was wiring both the same way. It was a very frustrating afternoon but alas, all is well now... got both working.
This works, it is a straight forward as I thought it would be

// this example is public domain. enjoy!
// www.ladyada.net/learn/sensors/thermocouple

#include "max6675.h"

int thermoDO = 7;
int thermoCS = 6;
int thermoCLK = 5;
int thermoCS1 = 4;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
MAX6675 thermocouple1(thermoCLK, thermoCS2, thermoDO);

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

  
  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {
  // basic readout test, just print the current temp
  
   Serial.print(" TC1 in Deg F = "); 
   Serial.print(thermocouple.readFahrenheit());
   Serial.print("  TC2 in Deg F = ");
   Serial.println(thermocouple1.readFahrenheit());
 
   delay(1000);
}//

All the studying to learn about C++ Classes and Libraries won't be wasted
Best regards
gene

Great Job GENE!!

It works great.
I am going to program 4 of them the same way I think it should work as well.