i am logging temperature data to a coffee roasting program on my computer. i want to add a second temperature sensor to the arduino, how can i add a second slave to my sketch? i was going to use the same Max6675 thermocouple amplifier in the same configuration using pins 8-12.
#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;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
int vccPin = 5;
int gndPin = 6;
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(led, OUTPUT);
delay(500);
}
void loop() {
// basic readout test, just print the current temp
//Serial.print("C = ");
au16data[2] = (uint16_t) (thermocouple.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);
}
}