run two temperature probes at the same time

how can i edit my sketch so that i can get readings from two different thermocouples? i know that they cannot run at the same time, would like to have them alternate back and forth.

// this example is public domain. enjoy!
// Thermocouple sensor tutorial

#include <max6675.h>
#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };

/**

  • Modbus object declaration
  • u8id : node id = 0 for master, = 1..247 for slave
  • u8serno : serial port (use 0 for Serial)
  • u8txenpin : 0 for RS-232 and USB-FTDI
  • or any pin number > 1 for RS-485
    */
    Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI

int thermoDO = 2;
int thermoCS = 3;
int thermoCLK = 4;
int thermoD1 = 8;
int thermoCS1 = 9;
int thermoCLK1 = 10;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 5;
int gndPin = 6;

MAX6675 thermocouple1(thermoCLK1, thermoCS1, thermoD1);
int vccPin1 = 11;
int gndPin1 = 12;

int led = 9;

void setup() {
slave.begin( 19200);// 19200 baud, 8-bits, none, 1-bit stop
// use Arduino pins
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
pinMode(vccPin1, OUTPUT); digitalWrite(vccPin1, HIGH);
pinMode(gndPin1, OUTPUT); digitalWrite(gndPin1, LOW);
pinMode(led, OUTPUT);
delay(500);

}

void loop() {
// basic readout test, just print the current temp
//Serial.print("C = ");

au16data[2] = (uint16_t) (thermocouple.readCelsius()*100);
au16data[3] = (uint16_t) (thermocouple1.readCelsius()*100);

slave.poll( au16data, 16 );

for(int i=1; i<=99; i++) {
if(i<=au16data[4])
digitalWrite(led, HIGH);
else
digitalWrite(led, LOW);

delay(5);}
}

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 5;
int gndPin = 6;

MAX6675 thermocouple1(thermoCLK1, thermoCS1, thermoD1);
int vccPin1 = 11;
int gndPin1 = 12;

Do you count "Uh-huh, two, three..."? Or, do you count "one, two, three..."?

What does reading the thermocouples have to do with ModBus?

What does that code actually do? How does the differ from what you want?

the arduino is set up as a slave to my computer which is running a coffee roaster data logging program called Artisan which graphs temperature change during your roast. one temperature sensor reads bean temp while the other is the roasting drum temp. the Artisan program is designed to run a host of different devices, the easiest way to get it to communicate with an arduino is through Modbus RTU.

the program samples the temperatures every 5 seconds.

with the code as is, the program keeps reading the temperature samples of the first sensor, but is only reading the initial temperature reading of the second sensor and the reading stays constant from then on

Why not start with a simpler program that just reads the Thermocouples and shows the data on the Serial Monitor? That way you can make sure you know how to read two thermocouples.

Then make another simple program (without any thermocouples) that just sends two numbers on Modbus That way you can be sure you are sending the data correctly.

...R