Good Morning,
I have a problem that I'm trying to solve. I have 5 Thermocouples on max6675 boards attached to a mega with a ili9341 3.5" shield attached. I have it all working displaying the 5 thermocouple values on the screen in a very simple way.
My code is Inelegant. 15 lines of declarations for setting up the pins on the max's, 5 lines to initialize the max's, 5 more lines to access the values of the max's.
i have been trying fruitlessly to set the values of the pins into an array and initialize the max's with a for loop . then read and analyze the values in a loop that will set the tft background and font color based on the highest reading of the first four values.
I'm planning on putting this on my vintage 2 stroke outboard motor to monitor cylinder head temps and exhust temp.
as it sits it works but is super uggo.
Here is the code that works
// this example is public domain. enjoy!
// www.ladyada.net/learn/sensors/thermocouple
#include "max6675.h"
// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
// D0 connects to digital pin 8 (Notice these are
// D1 connects to digital pin 9 NOT in order!)
// D2 connects to digital pin 2
// D3 connects to digital pin 3
// D4 connects to digital pin 4
// D5 connects to digital pin 5
// D6 connects to digital pin 6
// D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
int thermoDO1 = 22;
int thermoCS1 = 24;
int thermoCLK1 = 26;
int thermoDO2 = 23;
int thermoCS2 = 25;
int thermoCLK2 = 27;
int thermoDO3 = 28;
int thermoCS3 = 30;
int thermoCLK3 = 32;
int thermoDO4 = 29;
int thermoCS4 = 31;
int thermoCLK4 = 33;
int thermoDO5 = 49;
int thermoCS5 = 51;
int thermoCLK5 = 53;
MAX6675 thermocouple1(thermoCLK1, thermoCS1, thermoDO1);
MAX6675 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);
MAX6675 thermocouple3(thermoCLK3, thermoCS3, thermoDO3);
MAX6675 thermocouple4(thermoCLK4, thermoCS4, thermoDO4);
MAX6675 thermocouple5(thermoCLK5, thermoCS5, thermoDO5);
int vccPin = 34;
int gndPin = 35;
void setup() {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
identifier = 0x9341;
if (identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if (identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if (identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if (identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if (identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
return;
}
tft.begin(identifier);
Serial.println(F("Benchmark Time (microseconds)"));
Serial.print(F("Text "));
Serial.println(testText());
delay(3000);
// use Arduino pins
pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
Serial.println("MAX6675 test");
// wait for MAX chip to stabilize
delay(2500);
}
void loop() {
// basic readout test, just print the current temp
//Serial.print("C = ");
//Serial.println(thermocouple1.readCelsius());
//Serial.println(thermocouple2.readCelsius());
//Serial.println(thermocouple3.readCelsius());
//Serial.println(thermocouple4.readCelsius());
//Serial.print("F = ");
//Serial.print(thermocouple1.readFahrenheit());
//Serial.print(", ");
//Serial.print(thermocouple2.readFahrenheit());
//Serial.print(", ");
//Serial.print(thermocouple3.readFahrenheit());
//Serial.print(", ");
//Serial.println(thermocouple4.readFahrenheit());
tft.setRotation(3);
tft.fillScreen(GREEN);
tft.setTextColor(WHITE);
testText();
delay(1500);
}
unsigned long testText() {
unsigned long start = micros();
tft.setCursor(0, 0);
tft.setTextSize(8);
tft.print("#1: ");
tft.println(thermocouple1.readFahrenheit());
tft.print("#2: ");
tft.println(thermocouple2.readFahrenheit());
tft.print("#3: ");
tft.println(thermocouple3.readFahrenheit());
tft.print("#4: ");
tft.println(thermocouple4.readFahrenheit());
tft.print("#5: ");
tft.println(thermocouple5.readFahrenheit());
return micros() - start;
}
follow up posts are required with the 9000char limit on posts.