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

[BUG] Support for bed MAX31865 on esp32 #27610

Open
anvoice opened this issue Dec 27, 2024 · 10 comments
Open

[BUG] Support for bed MAX31865 on esp32 #27610

anvoice opened this issue Dec 27, 2024 · 10 comments

Comments

@anvoice
Copy link

anvoice commented Dec 27, 2024

Is your feature request related to a problem? Please describe.

The Marlin documentation claims support for a bed max31865 module. Such support does not exist however, and I was hoping to see it happen.

Are you looking for hardware support?

Fully custom cartesian printer, MKS Tinybee motherboard, max31865 module for bed support.

Describe the feature you want

Support for max31865 for the bed.

Additional context

Although the comments in Marlin code claim support exists, it does not seem to. Setting #define TEMP_SENSOR_BED -5 leads to errors, upon fixing which I get more errors. Hoping to see actual support added.

@anvoice anvoice added the T: Feature Request Features requested by users. label Dec 27, 2024
@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

This is just config options that are not in standard config files. and I added a sanity check

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 6d5ae49de8..f7ae53b1fd 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -599,6 +599,10 @@
   #define MAX31865_SENSOR_OHMS_2      100
   #define MAX31865_CALIBRATION_OHMS_2 430
 #endif
+#if TEMP_SENSOR_IS_MAX_TC(BED)
+  #define MAX31865_SENSOR_OHMS_BED      100
+  #define MAX31865_CALIBRATION_OHMS_BED 430
+#endif

 #if HAS_E_TEMP_SENSOR
   #define TEMP_RESIDENCY_TIME         10  // (seconds) Time to wait for hotend to "settle" in M109
diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h
index 806bafa2d0..99437183d2 100644
--- a/Marlin/Configuration_adv.h
+++ b/Marlin/Configuration_adv.h
@@ -174,9 +174,10 @@
  * Thermocouple Options — for MAX6675 (-2), MAX31855 (-3), and MAX31865 (-5).
  */
 //#define TEMP_SENSOR_FORCE_HW_SPI                // Ignore SCK/MOSI/MISO pins; use CS and the default SPI bus.
-//#define MAX31865_SENSOR_WIRES_0 2               // (2-4) Number of wires for the probe connected to a MAX31865 board.
-//#define MAX31865_SENSOR_WIRES_1 2
-//#define MAX31865_SENSOR_WIRES_2 2
+//#define MAX31865_SENSOR_WIRES_0   2             // (2-4) Number of wires for the probe connected to a MAX31865 board.
+//#define MAX31865_SENSOR_WIRES_1   2
+//#define MAX31865_SENSOR_WIRES_2   2
+//#define MAX31865_SENSOR_WIRES_BED 2

 //#define MAX31865_50HZ_FILTER                    // Use a 50Hz filter instead of the default 60Hz.
 //#define MAX31865_USE_READ_ERROR_DETECTION       // Treat value spikes (20°C delta in under 1s) as read errors.
@@ -188,6 +189,7 @@
 //#define MAX31865_WIRE_OHMS_0              0.95f // For 2-wire, set the wire resistances for more accurate readings.
 //#define MAX31865_WIRE_OHMS_1              0.0f
 //#define MAX31865_WIRE_OHMS_2              0.0f
+//#define MAX31865_WIRE_OHMS_BED            0.0f

 /**
  * Hephestos 2 24V heated bed upgrade kit.
diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h
index 9c21c4fd29..b7edc34ade 100644
--- a/Marlin/src/inc/SanityCheck.h
+++ b/Marlin/src/inc/SanityCheck.h
@@ -2121,6 +2121,13 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
     #error "MAX31865_SENSOR_OHMS_2 and MAX31865_CALIBRATION_OHMS_2 must be set if TEMP_SENSOR_2/TEMP_SENSOR_REDUNDANT is MAX31865."
   #endif
 #endif
+#if TEMP_SENSOR_BED_IS_MAX31865
+  #if !defined(MAX31865_SENSOR_WIRES_BED) || !WITHIN(MAX31865_SENSOR_WIRES_BED, 2, 4)
+    #error "MAX31865_SENSOR_WIRES_BED must be defined as an integer between 2 and 4."
+  #elif !defined(MAX31865_SENSOR_OHMS_BED) || !defined(MAX31865_CALIBRATION_OHMS_BED)
+    #error "MAX31865_SENSOR_OHMS_BED and MAX31865_CALIBRATION_OHMS_BED must be set if TEMP_SENSOR_BED is MAX31865."
+  #endif
+#endif

 /**
  * Redundant temperature sensor config

@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

related PR #27511

@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

PR created to add this to marlin.

@ellensp ellensp closed this as completed Dec 28, 2024
@anvoice
Copy link
Author

anvoice commented Dec 28, 2024

Thank you, but for my motherboard (MKS tinybee, an esp32-based board), even after adding everything according to your instructions, I get the following error: Marlin/src/libs/../HAL/shared/Delay.h:220:58: error: 'DELAY_CYCLES_VAR' was not declared in this scope. Apparently DELAY_CYCLES_VAR is not defined for my platform. I attempted to add it manually in Delay.h:

#elif defined(ESP32) || defined(__PLAT_LINUX__) || defined(__PLAT_NATIVE_SIM__)

  // DELAY_CYCLES specified inside platform

  // Delay in microseconds
  #define DELAY_US(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL))
  #define DELAY_CYCLES_VAR DELAY_CYCLES                         // attempt to get rid of error
#else

  #error "Unsupported MCU architecture"

#endif

but while that compiles, the printer does not respond to commands if the bed temp sensor is defined as the max31865.

@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

Is a esp32 specific issue

diff --git a/Marlin/src/HAL/shared/Delay.h b/Marlin/src/HAL/shared/Delay.h
index a6795a78ea..4751d7a5e2 100644
--- a/Marlin/src/HAL/shared/Delay.h
+++ b/Marlin/src/HAL/shared/Delay.h
@@ -174,6 +174,9 @@ void calibrate_delay_loop();
 
   // Delay in microseconds
   #define DELAY_US(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL))
+
+  #define DELAY_CYCLES_VAR DELAY_CYCLES
+
 #else
 
   #error "Unsupported MCU architecture"

The PR has been updated

as for not working... that is beyond me. (I don't have access to MAX31865 module)

@ellensp ellensp reopened this Dec 28, 2024
@ellensp ellensp changed the title [FR] Support for bed MAX31865 [BUG] Support for bed MAX31865 on esp32 Dec 28, 2024
@ellensp ellensp added Bug: Confirmed ! and removed T: Feature Request Features requested by users. labels Dec 28, 2024
@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

please attach your config files. and any other edited files
Want to know what pins your trying to use as a start

@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

add #define DEBUG_MAX31865 to Configuration.h
It may tell you more over serial

@ellensp
Copy link
Contributor

ellensp commented Dec 28, 2024

Please test the bugfix-2.1.x branch to see where it stands.

@anvoice
Copy link
Author

anvoice commented Dec 29, 2024

Apologies for late response, ran into some issues. The bugfix-2.1.x branch results in same behaviour: printer connects but does not communicate. Here are my configuration files and changed source from the 2.1.2.5 branch. I'm not sure I got everything but hope I did: the code with AlexB in the comments was code that I changed. The changes not related to the bed max31865 include an additional of serial3 to allow the TFT screen to communicate with the printer, and I also inverted the behaviour of a fan pin to accommodate the CPAP fan. Please let me know if any other details are needed. One (possible) issue I see with the code is that BED is defined as 0 somewhere else in the source, perhaps that is causing a problem. I could be totally wrong though.

I'm currently using the pins on the exp2 connection of the mainboard. The max31865 version I have is a stepstick variant on a breadboard. I tried using it directly in the slot for the unused E1 stepstick but got the same results. The MKS tinybee does not seem to support SPI mode for the steppers due to I think low pin count, so I thought maybe using the unused exp2 connection could be an alternative.
Configuration_AlexB.zip
changes_AlexB.zip

@anvoice
Copy link
Author

anvoice commented Jan 4, 2025

Please let me know if anything else is needed.

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

No branches or pull requests

2 participants