Skip to content

Instantly share code, notes, and snippets.

@pawl
Created September 12, 2020 04:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawl/490c51cb3357c96ef8124941cb8b2363 to your computer and use it in GitHub Desktop.
Save pawl/490c51cb3357c96ef8124941cb8b2363 to your computer and use it in GitHub Desktop.
modbus arduino max6675 artisan roasterscope
/*
* This sketch programs Ardunio to communicate with Artisan using MODBUS protocol and
* an inexpensive thermocouple amplifier.
*
* Hardware:
* Arduino UNO
* Thermocouple amplifier (MAX6675 or MAX31855)
* K-type thermocouple
*
* Libraries needed:
* https://github.com/adafruit/Adafruit-MAX31855-library or;
* https://github.com/adafruit/MAX6675-library and;
* https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino
*/
#include <max6675.h>
// #include <Adafruit_MAX31855.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 slave;
// declare variables for Arduino pins connected to the MAX data pins:
int thermoDO = 6;
int thermoCS = 5;
int thermoCLK = 4;
// declare variables for Arduino pins to power MAX:
int vccPin = 3;
int gndPin = 2;
// use the line below that applies
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
// Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
// declare variable for Arduino pin connected to solid state relay (SSR)
// int ssr = 5;
void setup() {
// configure the pins to power MAX and SSR
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
// pinMode(ssr, OUTPUT);
slave = Modbus(1,0,0); // MODBUS object declaration: (1 = slave #1, 0 = RS232, 0 = RS232)
slave.begin( 19200 ); // 19200 baud, 8-bits, none, 1-bit stop
delay(500);
}
void loop() {
//au16data[2] = ((uint16_t) (thermocouple.readFahrenheit()*10));
// au16data[2] = ((uint16_t) (thermocouple.readCelsius()*10));
au16data[2] = ((uint16_t) thermocouple.readCelsius()*100);
slave.poll( au16data, 16 );
// heater control loop:
// for(int i=1; i<=99; i++) {
// if(i<=au16data[4])
// digitalWrite(ssr, HIGH);
// else
// digitalWrite(ssr, LOW);
// delay(5);
// }
// add delay if commenting out heater control loop
delay(200);
}
@Larrythelong
Copy link

Very grateful for this code.

I'm trying to find out what settings we have to put into Artisan to pick up the data from this sketch.

Artisan is currently connected successfully to MODBUS on Slave channel 1, but I'm getting no data through for temps.

FYI My main inputs are from a TC4 and the MODBUS is being used as a secondary input, the settings for that might be de different... it seems to be connected.. but I think I have the wrong register set.

what register would the data from this sketch come in on? I read some documentation that the 30000-40000 was correct for this type of data.

I'm too new to this to know what is correct for this use case.

Any help would be amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment