[Solved] MAX31865 conflicts with ETHERNET

So my project is to send temperature value from MAX31865 to my computer via ETHERNET. I won't get into the details of the program of my computer's side. Instead, I've extracted the important bits of my code for ease of reproducibility. Here's my full code below.

#include <Adafruit_MAX31865.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
bool ethstats = false;
uint8_t packetPos = 0;

bool udp_init(){
  
  // Enter a MAC address and IP address for your controller below.
  // The IP address will be dependent on your local network:
  byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  };
  IPAddress ip(192, 168, 2, 90);
  uint16_t localPort = 5000;      // local port to listen on
  
  // start the Ethernet
  Ethernet.begin(mac, ip);

  bool result = Ethernet.hardwareStatus() == EthernetNoHardware || Ethernet.linkStatus() == LinkOFF;
  result = !result;

  // start UDP
  if(result) Udp.begin(localPort);
  return result;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  udp_init();
}

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

Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);

thermo.begin(MAX31865_2WIRE);  // set to 2WIRE or 4WIRE as necessary
float temperature = thermo.temperature(1000, 4300);
  Serial.print("Temperature = "); Serial.println(temperature);
  delay(100);
}

Now let's take a look at this specific bit:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  udp_init();
}

With this function being called, MAX31865 outputs -242 every time.

Whereas when I disable it, with the following code:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(19200);
  // udp_init();
}

MAX31865 worked well and outputted somewhere around 23 (the room temperature). Any solutions on how to overcome this? Thanks in advance.

Just guessing, but probably its some conflict with both ETHERNET and MAX31865 using hardware SPI. Perhaps a quick and easy solution would be to use software SPI mode for the MAX31865.

1 Like

I found the solution. What you said helps. So there are two solutions I've found out.

It lies in the code below:

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

Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);

thermo.begin(MAX31865_2WIRE);  // set to 2WIRE or 4WIRE as necessary
float temperature = thermo.temperature(1000, 4300);
  Serial.print("Temperature = "); Serial.println(temperature);
  delay(100);
}

Solution 1

Change the following code:

Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);

To this:

Adafruit_MAX31865 thermo = Adafruit_MAX31865(6, 7, 8, 9);

You can see that the second code is just changing the values. Turns out this is the software option of MAX31865. So it means that you must change the pins for all. This option takes a lot of pins where you need to save up some pins. So the better solution is the second solution below.


Solution 2

Change the following code:

Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);

To this:

Adafruit_MAX31865 thermo = Adafruit_MAX31865(9);

The better way (which I haven't noticed up until now), is to use the hardware SPI option. Adafruit_MAX31865 automatically sets up SCK, SDO and SDI (PIN 13, 12, 11 respectively), which we only need to worry of the SS (slave select). By default it's PIN 10, which should be used by the ETHERNET. As such, we must use other pin (in this case, PIN 9).

Supposed you need to use more than one MAX31865, the code below should suffice:

Adafruit_MAX31865 thermo0 = Adafruit_MAX31865(9);
Adafruit_MAX31865 thermo1 = Adafruit_MAX31865(8);
Adafruit_MAX31865 thermo2 = Adafruit_MAX31865(7);

Thank you @dlloyd for the insight and the reply. It is much appreciated.

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