// https://wokwi.com/projects/472618374755844097
// for
// https://forum.arduino.cc/t/i-need-some-assistance-with-changing-a-library-initialize-commandd/1455956
// cobbled together multiplexed
// started with this example
/*
**************************************************
This is an example for the Adafruit Thermocouple Sensor w/MAX31855K
Designed specifically to work with the Adafruit Thermocouple Sensor
----> https://www.adafruit.com/products/269
These displays use SPI to communicate, 3 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************
*/
# include <SPI.h>
# include <Wire.h>
# define TWELVE 16
# include <Adafruit_MAX31855.h>
#define DO 3
#define CS 4
#define CLK 5
// Ordinary Adafruit object
Adafruit_MAX31855 thermocouple(CLK, CS, DO);
const byte A0pin = A0;
const byte A1pin = A1;
const byte A2pin = A2;
const byte A3pin = A3;
// Our wrapper
class ThermocoupleMux {
public:
ThermocoupleMux(Adafruit_MAX31855 &tc,
byte a0, byte a1, byte a2, byte a3)
: tc(tc), a0(a0), a1(a1), a2(a2), a3(a3) {}
bool begin() {
pinMode(a0, OUTPUT);
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);
pinMode(a3, OUTPUT);
select(0);
return tc.begin();
}
double readCelsius(byte channel) {
select(channel);
return tc.readCelsius();
}
double readInternal(byte channel) {
select(channel);
return tc.readInternal();
}
private:
void select(byte channel) {
channel = ~channel; // invert for sole zero 1, 2, 4 and 8
digitalWrite(a0, bitRead(channel, 0));
digitalWrite(a1, bitRead(channel, 1));
digitalWrite(a2, bitRead(channel, 2));
digitalWrite(a3, bitRead(channel, 3));
}
Adafruit_MAX31855 &tc;
byte a0, a1, a2, a3;
};
// Give the wrapper the Adafruit object and the four 4515 address pins
ThermocoupleMux thermocouples(
thermocouple, A0pin, A1pin, A2pin, A3pin
);
void setup() {
Serial.begin(9600);
delay(500);
if (!thermocouples.begin()) { // all thermocouples, just one object
Serial.println("\nERROR.");
while (1) delay(10);
}
Serial.println("\nDONE.");
}
byte list[4] = {1, 2, 4, 8};
void loop() {
static int tcIndex;
double c = thermocouples.readCelsius(list[tcIndex]);
Serial.print("Thermocouple ");
Serial.print(list[tcIndex]);
Serial.print(" Temp = * ");
Serial.println(c);
delay(177);
if (++tcIndex >= 4) tcIndex = 0;
}
Loading
cd74hc4067
cd74hc4067