Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max31856 Loom not working, raw example code does #32

Open
udellc opened this issue Sep 12, 2022 · 4 comments
Open

Max31856 Loom not working, raw example code does #32

udellc opened this issue Sep 12, 2022 · 4 comments

Comments

@udellc
Copy link
Member

udellc commented Sep 12, 2022

Describe the bug
Max 31856 raw example (oneShot.ino) gives good data on serial monitor.
Loom version prints errors and bad reading.

This is the example code that works:

// Basic example using one-shot measurement.
// The call to readThermocoupleTemperature() is blocking for O(100ms)

#include <Adafruit_MAX31856.h>

// Use software SPI: CS, DI, DO, CLK
//Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10, 11, 12, 13);
// use hardware SPI, just pass in the CS pin
Adafruit_MAX31856 maxthermo = Adafruit_MAX31856(10);

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);
  Serial.println("MAX31856 thermocouple test");

  maxthermo.begin();

  maxthermo.setThermocoupleType(MAX31856_TCTYPE_K);

  Serial.print("Thermocouple type: ");
  switch (maxthermo.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;
  }

}

void loop() {
  Serial.print("Cold Junction Temp: ");
  Serial.println(maxthermo.readCJTemperature());

  Serial.print("Thermocouple Temp: ");
  Serial.println(maxthermo.readThermocoupleTemperature());
  // Check and print any faults
  uint8_t fault = maxthermo.readFault();
  if (fault) {
    if (fault & MAX31856_FAULT_CJRANGE) Serial.println("Cold Junction Range Fault");
    if (fault & MAX31856_FAULT_TCRANGE) Serial.println("Thermocouple Range Fault");
    if (fault & MAX31856_FAULT_CJHIGH)  Serial.println("Cold Junction High Fault");
    if (fault & MAX31856_FAULT_CJLOW)   Serial.println("Cold Junction Low Fault");
    if (fault & MAX31856_FAULT_TCHIGH)  Serial.println("Thermocouple High Fault");
    if (fault & MAX31856_FAULT_TCLOW)   Serial.println("Thermocouple Low Fault");
    if (fault & MAX31856_FAULT_OVUV)    Serial.println("Over/Under Voltage Fault");
    if (fault & MAX31856_FAULT_OPEN)    Serial.println("Thermocouple Open Fault");
  }
  delay(1000);
}

This example in loom does not work:

/**
 * Temperature Readings using teh MAX31865 sensor
 * Pass in a variable number of arguments to the construct to designate the number of samples and which pin you're using
 * 
 * MANAGER MUST BE INCLUDED FIRST IN ALL CODE
 */


#include <Loom_Manager.h>

#include <Sensors/SPI/Loom_MAX318XX/Loom_MAX31856.h>


Manager manager("Device", 1);

// Reads the temperature
Loom_MAX31856 maxDude(manager);

void setup() {

  // Start the serial interface
  manager.beginSerial();

  // Initialize the manager
  manager.initialize();

  // Measure the data from the sensors
  manager.measure();

  // Package the data into JSON
  manager.package();

  // Print the JSON document to the Serial monitor
  manager.display_data();

}

void loop() {
  // put your main code here, to run repeatedly:

}

This prints the following:
[Manager] Initializing Modules...
[Manager] ** Setup Complete **
[MAX31856] Cold Junction Range Fault
[MAX31856] Thermocouple Range Fault
[MAX31856] Cold Junction High Fault
[MAX31856] Cold Junction Low Fault
[MAX31856] Thermocouple High Fault
[MAX31856] Thermocouple Low Fault
[MAX31856] Over/Under Voltage Fault
[MAX31856] Thermocouple Open Fault

[Manager] Data Json:
{
"type": "data",
"id": {
"name": "Device",
"instance": 1
},
"contents": [
{
"module": "Packet",
"data": {
"Number": 1
}
},
{
"module": "MAX31856",
"data": {
"Temperature": null
}
}
]
}

@udellc
Copy link
Member Author

udellc commented Sep 13, 2022

Document fix please!

@WL-Richards
Copy link
Member

changed name of variable from max to maxthermo?

@udellc
Copy link
Member Author

udellc commented Sep 14, 2022

That might do it as max looks to be reserved in the IDE

@udellc udellc reopened this Dec 3, 2024
@udellc
Copy link
Member Author

udellc commented Dec 3, 2024

Elliot found a way to use hardware spi with this chip. This uses less GPIO. can we implement it? But let's first check to ensure there are no strange things with the SD card. SPI functionality. There does seem to be an issue when reading the time period for sampling from the SD card using hardware spy, but it doesn't seem to be an issue. Any use software spy for the max chip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants