Temperature sensor only showing on LCD when connected to laptop.

Hi All,

I have a project that is using a thermocouple and RTD temperature sensor and is displaying them on an LCD screen.

The screen displays "T Type: " then the thermocouple vale on the first line, and "RTD: " then the value on the second. Everything is currently working fine when the Arduino is plugged into my laptop, however, when the Arduino is plugged into a USB power supply, the thermocouple value always shows 0.00.

The program still runs as expected and is displaying the text correctly so I do not understand where I could go wrong? Has anyone else experienced this?

I am using an Arduino Mega 2560,

The thermocouple is a T type and uses the Adafruit max31856 shield and uses software SPI pins 10, 11, 12, 13.

The RTD uses the Adafruit max31865 shield and uses hardware SPI pins 50, 51, 52 and I have set pin 25 as an output for chip select.

The lcd screen is also from Adafruit and uses I2C for communication.

Thanks in advance,

Blake

blaketaylor:
...and uses software SPI pins 10, 11, 12, 13.

Why not two devices on the same hardware SPI bus?
The modules do have a CS (chip select) pin.
Leo..

Hi Leo,

I have other modules that use SPI such as an SD card reader and a number of other components hardwired onto a protoboard that sits ontop of the arduino so it was really just a spacial convenience thing at the time.

The other components shouldn't be interfering with this issue.

-Blake

blaketaylor:
Everything is currently working fine when the Arduino is plugged into my laptop, however, when the Arduino is plugged into a USB power supply, the thermocouple value always shows 0.00.

So the Mega works if you power it from laptop USB,
and doesn't work when you power it with a 5volt USB charger connected to the USB socket?

Need more info to help you.
Did you read the "how to post" sticky.
Leo..

Yes, all other parts of my program work fine when powered through a USB wall charger, it only doesnt pull the correct value for the thermocouple.

The program currently starts, waits for the user to push the # key on the keypad, then opens two solenoid valves and then starts displaying temperatures on the LCD screen as shown. The picture that shows a temperature of 0.00 for the t type is when it is plugged into the wall, the other is when it is plugged into the laptop.

Note the sensors are obviously not calibrated yet.

There is more code in my program, but here is the parts I think are relevant.

// Thermocouple Sensor
#include <Adafruit_MAX31856.h>
// Use software SPI: CS, DI, DO, CLK
Adafruit_MAX31856 max0 = Adafruit_MAX31856(10, 11, 12, 13);

// RTD Sensor
#include <Adafruit_MAX31865.h>
// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31865 max1 = Adafruit_MAX31865(25, 51, 50, 52);
// Use hardware SPI, just pass in the CS pin
Adafruit_MAX31865 max1 = Adafruit_MAX31865(25);
// The value of the Rref resistor. Use 430.0!
#define RREF 430.0
const int RTDchipSelect = 25;

// LCD Display
#include <Wire.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
// The shield uses the I2C SCL and SDA pins. SCL 21, SDA 20.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// Set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
// ***************************************************************************************
// Setup Code 
// ***************************************************************************************
void setup() {
  // Set SPI CS pin for RTD
  pinMode(RTDchipSelect, OUTPUT);
  
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // Wait for serial port only when programming and debuging code.
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Begin hardware setup.");

  // Setup Thermocouple Sensor
  max1.begin();
  max0.setThermocoupleType(MAX31856_TCTYPE_T);
  Serial.print("Thermocouple type: ");
  switch ( max0.getThermocoupleType() ) {
    case MAX31856_TCTYPE_B: Serial.println("B Type"); break;
    case MAX31856_TCTYPE_E: Serial.println("E Type"); break;
    case MAX31856_TCTYPE_J: Serial.println("J Type"); break;
    case MAX31856_TCTYPE_K: Serial.println("K Type"); break;
    case MAX31856_TCTYPE_N: Serial.println("N Type"); break;
    case MAX31856_TCTYPE_R: Serial.println("R Type"); break;
    case MAX31856_TCTYPE_S: Serial.println("S Type"); break;
    case MAX31856_TCTYPE_T: Serial.println("T Type"); break;
    case MAX31856_VMODE_G8: Serial.println("Voltage x8 Gain mode"); break;
    case MAX31856_VMODE_G32: Serial.println("Voltage x8 Gain mode"); break;
    default: Serial.println("Unknown"); break;
  }

  // Setup RTD Sensor
  max1.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
  Serial.println("RTD sensor.");
  
  // Setup LCD Display
  lcd.begin(16, 2);
  Serial.println("LCD screen.");
}

There is other setup code for an SD card reader, keypad, digital pins for solnoids, etc.

void loop() {
  //
  // Wait For Start 
  // 

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Press # to");
  lcd.setCursor(0, 1);
  lcd.print("begin test.");
  char startKey = 0;
  while (startKey != 35){
    startKey = keypad.getKey();
  }
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Starting...3");
  Serial.println("Starting...");
  delay(1000);
  lcd.print("Starting...2");
  delay(1000);
  lcd.print("Starting...1");
  delay(1000);
  lcd.clear();

  // 
  // Open Valves and Display Temps 
  // 

  digitalWrite(solenoidHot, LOW);
  digitalWrite(solenoidCold, LOW);

  double thermoTemp = 0;
  double rtdTemp = 0;

  lcd.setCursor(0, 0);
  lcd.print("T Type: ");
  lcd.setCursor(0, 1);
  lcd.print("RTD: ");

  startKey = 0;
  while (startKey != 35){
    startKey = keypad.getKey();
    thermoTemp = max0.readThermocoupleTemperature();
    rtdTemp = max1.temperature(100,RREF);
    lcd.setCursor(8, 0);
    lcd.print(thermoTemp);
    lcd.setCursor(8, 1);
    lcd.print(rtdTemp);
  }

  startKey = 0;
  while (startKey != 42){
    startKey = keypad.getKey();
  }

  Serial.println("Finished");
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Finished");
  delay(5000);
  resetFunc();  //call reset
}

The only issue I have had so far with the adafruit thermocouple shield is to do with the max calling protocol (not sure how to phrase it) that was addressed in Adafruit Max31856 thermocouple amp and Max31865 RTD amp codes will not compile - Programming Questions - Arduino Forum which is why there is max0 and max1.