Skip to content

Instantly share code, notes, and snippets.

@pawl

pawl/sketch.ino

Created Sep 12, 2020
Embed
What would you like to do?
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment