Trouble with arrays and max6675->Mega2560

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.

As you can see there are a bunch of extraneous lines of code which I'm trying to simplify with arrays but I'm having trouble getting the arrays to work.

// 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;
[color=red]/* setting up the thermocouple pins */
int thermoDO[5] =  (22, 23, 28, 29, 49);
int thermoCS[5] = (24, 25, 30, 31, 51);
int thermoCLK[5] = (26, 27, 32, 33, 53);
/*setting vars for thermocouple values*/
int thermocouple[5];
int thermovals[5];[/color]
/*
  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;
*/

[color=red]for (int i = 0, i <= 4, int++) {
  MAX6675 thermocouple[i](thermoCLK[i], thermoCS[i], thermoDO[i]);
}[/color]


/*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);

[color=red]  for (int t = 0, t <= 4, t++) {
    tft.print("#" + t + ": ");
    tft.println(thermocouple[t].readFahrenheit());

  }
[/color]  return micros() - start;
}

My changes are supposed to be highlighted in red but putting color tags in code tags doesn't appear to work. Followed by the errors returned . I'm not a very strong c++ coder. I spent several years as a lamp coder and wrote some very elaborate cms => hardware interfaces but c, c++, c# have always been a challenge for me and add about 7 years of abstinence from any type of coding and I'm sure nuances have emerged that I'm unaware of. I've spent 8 hours trying to figure out where I'm going wrong on this and just can't get it.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

testfthermoarrays:74: error: expected unqualified-id before 'for'

 for (int i = 0, i <= 4, int++;) {

 ^

testfthermoarrays:74: error: expected unqualified-id before ')' token

 for (int i = 0, i <= 4, int++;) {

                               ^

C:\Users\ThatGuy\Documents\Arduino\thermosimple\testfthermoarrays\testfthermoarrays.ino: In function 'long unsigned int testText()':

testfthermoarrays:169: error: expected initializer before '<=' token

   for (int t = 0, t <= 4, t++) {

                     ^

testfthermoarrays:169: error: expected ';' before '<=' token

testfthermoarrays:169: error: expected primary-expression before '<=' token

testfthermoarrays:169: error: expected ';' before ')' token

   for (int t = 0, t <= 4, t++) {

                              ^

testfthermoarrays:170: error: invalid operands of types 'const char*' and 'const char [3]' to binary 'operator+'

     tft.print("#"+'t'+": ");

                       ^

testfthermoarrays:171: error: request for member 'readFahrenheit' in 'thermocouple[t]', which is of non-class type 'int'

     tft.println(thermocouple[t].readFahrenheit());

                                 ^

exit status 1
expected unqualified-id before 'for'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any help is appreciated. I notice that hairs are piling up on my keyboard.
best guess it that the value of readFahrenheit() is returned as char from that function.
up higher it talks about expecting a ; before t<=4 but when I change , to ; it says unexpected initializer ;.

I'm just very lost at the moment

ok so here is the following that I have been able to get almost working.

#include "max6675.h" //Thermocouple library
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#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

#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;
/* setting up the thermocouple pins */
int thermoDO[5] =  {22, 23, 28, 29, 49};
int thermoCS[5] = {24, 25, 30, 31, 51};
int thermoCLK[5] = {26, 27, 32, 33, 53};
/*setting vars for thermocouple values*/
unsigned long thermocouple[5];
int8_t thermovals[5];
int i;
int t;

void decThermocouples() {
  for (i=0; i<=4; i++)
  MAX6675 thermocouple[i](thermoCLK[i], thermoCS[i], thermoDO[i]);
}


int vccPin = 34;
int gndPin = 35;
void setup() {
  Serial.begin(9600);
  Serial.println(F("TFT LCD"));

  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
  tft.reset();
  uint16_t identifier = 0x9341;
    return;
  tft.begin(identifier);
  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() {
  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);
  int t;
  for (t=0; t<=4; t++){
    tft.print("#f ");
    tft.println(thermocouple[t].readFahrenheit());
  }
  return micros() - start;
}

I trimmed all of the really extraneous stuff. commented out things etc... slimmed it down. fixed? the for loop stuff and am still getting an error that I don't understand.

Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\thatguy\Documents\Arduino\dunno\dunno.ino: In function 'void decThermocouples()':

dunno:32: error: bad array initializer

   MAX6675 thermocouple[i](thermoCLK[i], thermoCS[i], thermoDO[i]);

                                                                 ^

C:\Users\thatguy\Documents\Arduino\dunno\dunno.ino: In function 'long unsigned int testText()':

dunno:73: error: request for member 'readFahrenheit' in 'thermocouple[t]', which is of non-class type 'long unsigned int'

     tft.println(thermocouple[t].readFahrenheit());

                                 ^

exit status 1
bad array initializer

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

edited because I copied the wrong windows error messages.