I'm trying to read in 8 thermocouples on an Ocean Controls KTA 259 board, along with two additional Max31856 thermocouple amplifier boards and send the data to MATLAB. The first time each thermocouple is read everything works fine, but in each additional read the temperatures associated with "B" and "C" read Nan and 256 respectively, which are definitely not correct. I think the multiplexer code is what is causing the problems, but I cannot find any libraries in Arduino that have code for this specific multiplexer. I'm not the best at Arduino so some of the code came from online libraries.
int flowmetervalue;
int powervalue;
long t;
int incomingByte=10;
bool delaysetflag=false;
float flowmetervoltage;
float powervoltage;
float tccj1;
float tctemp1;
float tccj2;
float tctemp2;
long tz;
int m=1; //1 is slow (for setting up measurement), 0 is fast
bool stop=0; //data is sent while stop=0, data is not sent when stop=1
// int modePin=8;
// int stopPin=10;
// int incomingByte=10;
// bool delaysetflag=false;
#include <Adafruit_MAX31856.h>
#include "TCMuxShield.h"
TCMuxShield tc = TCMuxShield(9);
Adafruit_MAX31856 tc1 = Adafruit_MAX31856(5, 2, 3, 4);
Adafruit_MAX31856 tc2 = Adafruit_MAX31856(6, 2, 3, 4);
void setup() {
// put your setup code here, to run once:
Serial.begin(500000);
tz=micros();
tc1.begin();
tc1.setThermocoupleType(MAX31856_TCTYPE_K);
tc2.begin();
tc2.setThermocoupleType(MAX31856_TCTYPE_K);
}
void loop() {
//Aqcuire Data
flowmetervalue=analogRead(0);
powervalue=analogRead(1);
flowmetervoltage = flowmetervalue * 5.0/1023;
powervoltage = powervalue * 5.0/1023;
tccj1=tc1.readCJTemperature();
tctemp1=tc1.readThermocoupleTemperature();
// if (tctemp1>1){}
// else {tctemp1=0.1;}
tccj2=tc2.readCJTemperature();
tctemp2=tc2.readThermocoupleTemperature();
//Acquire Time
t=micros();
//Send data
if (true){
Serial.print('X'); Serial.print(flowmetervoltage);
Serial.print('Y'); Serial.print(powervoltage);
Serial.print('A'); Serial.print(tccj1);
Serial.print('B'); Serial.print(tctemp1);
Serial.print('C'); Serial.print(tccj2);
Serial.print('D'); Serial.print(tctemp2);
//Serial.print('T'); Serial.print(t);
//Serial.print('!'); // "!" is playing the role of termination character
for (char i = 1; i < 9; i++)
{
tc.readTemperature(i);
float temp = tc.temperature;
Serial.print('E');
Serial.print(temp);
}
Serial.print('T'); Serial.print(t);
Serial.print('!'); // "!" is playing the role of termination character
}
//Recieve data
if (Serial.available()>0){
incomingByte=Serial.read();
delaysetflag=true;
}
//Delay
if (incomingByte>0){
delay(incomingByte*4);
}
//Closed State, what does this do?
if(incomingByte==255){
}
else {
}
}
Not enough information, but thank you for posting the code correctly on your first post.
this specific multiplexer
What multiplexer?
Forum members will need to see a complete wiring diagram of the setup, with pins, connections and parts clearly labeled (hand drawn is preferred). Also post links to the product pages or manuals for the external components.
Additional advice can be found in the "How to get the best out of this forum" post.
I noticed that when you are establishing serial communication, you are setting the speed to 500000. As far as I know this isn't a standard value. Having an inconsistency between your declared serial speed and the speed that your slave device is looking for can definitely cause the sort of errors you are seeing.
I would recommend checking your KTA 259 board for what baud rate it actually is expecting, then set your Serial.begin statement to match.
These are what actuall set what channel is read from to the single Max31856 on the KTA board, I havent used this before but you cycle through the 8 combinations to read from the 8 sensors with the A0/1/2 using BCD to set the channel
A0/1/2 = 000 ; Set to read input 1, Read with the Max31856 and store.
A0/1/2 = 100 ; Set to read input 2, Read with the Max31856 and store.
I think I'm using some of those pins to read in data from the Max31856 boards that are reading thermocouples separate from the KTA 259. The KTA 259 is attached directly to an Arduino Uno, the KTA 259 is directly on top on the Uno and is attached with pins that go into all of the Arduino's digital and analog input pins.
#include "TCMuxShield.h"
TCMuxShield tc = TCMuxShield(9);
// the setup function runs once when you press reset or power the board
void setup()
{
// initialize Serial
Serial.begin(9600);
while(!Serial) {;}
}
// the loop function runs over and over again forever
void loop()
{
// Measure all thermocouple inputs, and display temperatures and error codes over serial
for (char i = 1; i < 9; ++i)
{
int err_code = tc.readTemperature(i);
Serial.print("-------------------\nThermocouple ");
Serial.println(i, DEC);
Serial.print("Temperature = ");
Serial.println(tc.temperature);
Serial.print("Error Code = ");
Serial.println(err_code);
}
delay(5000);
}
This code works for my set up, but my main issue is that I want to read in two additional thermocouples on separate Max31856 boards. Whenever I try to add that into my code, it doesn't work.
Posting an annotated schematic will help sort out your problems. Be sure to show all connections, power sources, grounds, etc. Post links to technical information on the hardware.