Understanding the adafruit max31855 example sketch

Hi all,
I am putting together a kiln controller and just got the adafruit max31855 breakout board to interface my thermocouple and my arduino uno. In looking through the example sketch that they provide with the adafruit max31855 library, there are several things that i don't understand and am wondering if anyone can tell me why they are included and/or what they do.

In the header: I understand the inclusion of the adafruit_MAX31855.h and liquidcrystal.h libraries, but why are the SPI.h and Wire.h libraries included? I can't see where they are used in the sketch

then under setup, what does this do, I have no clue at all:

#ifndef ESP8266
    while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  #endif

Thanks so much for any insight you can offer!

Jesse

#include <SPI.h>
#include <Wire.h>
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>

// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define MAXDO   3
#define MAXCS   4
#define MAXCLK  5

// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  #ifndef ESP8266
    while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  #endif
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  lcd.clear();
  lcd.print("MAX31855 test");
  // wait for MAX chip to stabilize
  delay(500);
  if (!thermocouple.begin()) {
    lcd.print("ERROR.");
    while (1) delay(10);
  }
  lcd.print("DONE.");
}

void loop() {
  // basic readout test, just print the current temp
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Int. Temp = ");
   lcd.println(thermocouple.readInternal());
   Serial.print("Int. Temp = ");
   Serial.println(thermocouple.readInternal());

   double c = thermocouple.readCelsius();
   lcd.setCursor(0, 1);
   if (isnan(c))
   {
     lcd.print("T/C Problem");
   }
   else
   {
     lcd.print("C = ");
     lcd.print(c);
     lcd.print("  ");
     Serial.print("Thermocouple Temp = *");
     Serial.println(c);
   }

   delay(1000);
} [

It tests whether the code is being compiled for an ESP8266 and if not adds

while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens

to the code to do what the comment says

I expect that those libraries are used in the Adafruit one. Try compiling without them if you want to be sure.

what is an ESP8266? what is meant by Zero and Leonardo? and why is it desirable to pause until serial console opens

Thanks - I will try it.

ESP8266 is not officially an Arduino board, but is compatible with the IDE and is often used because of its WiFi interface.

The pause is needed on boards that have a native USB port on the processor (as opposed to a USB to serial converter), because it takes a significant amount of time to establish the USB connection, during which time any output sent to Serial will be lost.

There are many, many different types of boards that are supported by the arduino platform. Those are but 3 examples. Some boards use different MCUs and/or auxiliary chips for the Serial communication

Thanks all for the info - since i'm using an actual arduino I will delete this block of code. Glad to know what it does :slight_smile: !

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.