Author Topic: Need Help with Marlin 3D printer firmware  (Read 7814 times)

0 Members and 1 Guest are viewing this topic.

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Need Help with Marlin 3D printer firmware
« on: July 05, 2023, 08:36:44 pm »
Hello Forum!

I am working on adding heated chamber functionality to my 3D printer, which involves a heater and an exhaust fan, i.e. heating and cooling.

My printer mainboard is a Bigtreetech skr 1.4 turbo (now discontinued I think?) running marlin bugfix 2.0.x . So far I have the heater running, I use VScode to edit the files and generate the binary for the mainboard.

The main thing I am stuck on is how to get the cooling fan set up. There are blocks of code for controlling the heater and fan, but there are no entries for the fan in the files that define the actual pins for the processor. I was able to find set the heater pin to what I wanted, but I searched high and low for an enclosure fan pin and didn't find anything.

If anybody has any experience in this area of marlin some help would be greatly appreciated! I think I will have to manually add code to define a pin for the fan, but I don't know how to do that.

Here is some of the code:

//
// Heated Chamber options
//
#if TEMP_SENSOR_CHAMBER
  #define CHAMBER_MINTEMP             5
  #define CHAMBER_MAXTEMP            60
  #define TEMP_CHAMBER_HYSTERESIS     3   // (°C) Temperature proximity considered "close enough" to the target
  //#define CHAMBER_LIMIT_SWITCHING
  #define HEATER_CHAMBER_PIN       P1_00   // Chamber heater on/off pin
  //#define HEATER_CHAMBER_INVERTING false

  #define CHAMBER_FAN               // Enable a fan on the chamber
  #if ENABLED(CHAMBER_FAN)
    #define CHAMBER_FAN_MODE 1        // Fan control mode: 0=Static; 1=Linear increase when temp is higher than target; 2=V-shaped curve.
    #if CHAMBER_FAN_MODE == 0
      #define CHAMBER_FAN_BASE  255   // Chamber fan PWM (0-255)
    #elif CHAMBER_FAN_MODE == 1
      #define CHAMBER_FAN_BASE  255   // Base chamber fan PWM (0-255); turns on when chamber temperature is above the target
      #define CHAMBER_FAN_FACTOR 0   // PWM increase per °C above target
    #elif CHAMBER_FAN_MODE == 2
      #define CHAMBER_FAN_BASE  128   // Minimum chamber fan PWM (0-255)
      #define CHAMBER_FAN_FACTOR 25   // PWM increase per °C difference from target
    #endif
  #endif

  //#define CHAMBER_VENT              // Enable a servo-controlled vent on the chamber
  #if ENABLED(CHAMBER_VENT)
    #define CHAMBER_VENT_SERVO_NR  1  // Index of the vent servo
    #define HIGH_EXCESS_HEAT_LIMIT 5  // How much above target temp to consider there is excess heat in the chamber
    #define LOW_EXCESS_HEAT_LIMIT 3
    #define MIN_COOLING_SLOPE_TIME_CHAMBER_VENT 20
    #define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5
  #endif
#endif
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #1 on: July 06, 2023, 10:32:33 pm »
I asked to move the thread since you posted in the wrong location: https://www.eevblog.com/forum/3d-printing/

The pins are defined in another file, \Marlin\src\pins\lpc1768\pins_BTT_SKR_V1_4.h and pins_BTT_SKR_common.h

In the common.h you can find this section:
Quote
//
// Heaters / Fans
//
#ifndef HEATER_0_PIN
  #define HEATER_0_PIN                     P2_07
#endif
#if HOTENDS == 1 && DISABLED(HEATERS_PARALLEL)
  #ifndef FAN1_PIN
    #define FAN1_PIN                       P2_04
  #endif
#else
  #ifndef HEATER_1_PIN
    #define HEATER_1_PIN                   P2_04
  #endif
#endif
#ifndef FAN_PIN
  #define FAN_PIN                          P2_03
#endif
#ifndef HEATER_BED_PIN
  #define HEATER_BED_PIN                   P2_05
#endif

If it doesn't exist you'll have to add a definition and ensure the pin isn't used elsewhere in the code. Eg. you can probably steal the second extruder FET if you are not using that.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #2 on: July 07, 2023, 12:45:52 am »
Thanks for the reply! Sorry I posted this in the wrong place I guess I wasn't paying enough attention, I had no idea there was a 3D printing section.

I figured I would have to add a pin definition. would the syntax be something like this?

#ifndif CHAMBER_FAN_PIN
   #define CHAMBER_FAN_PIN        P2_04
#endif

I don't know what the particular variable should be, it is called CHAMBER_FAN in configuration.h, but I don't know if that is necessarily the actual variable.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #3 on: July 07, 2023, 10:22:15 pm »
I think you need to add "#define HOTENDS  1" to your configuration.h if there isn't an existing define.

So now TEMP_CHAMBER_PIN will auto define to TEMP_1_PIN:
Code: [Select]
#if HOTENDS == 1 && !REDUNDANT_TEMP_MATCH(SOURCE, E1)
  #if TEMP_SENSOR_PROBE
    #define TEMP_PROBE_PIN            TEMP_1_PIN
  #elif TEMP_SENSOR_CHAMBER
    #define TEMP_CHAMBER_PIN          TEMP_1_PIN
  #endif
#endif

Setup the temperature probe type if you have one, to whatever type of thermistor:
"#define TEMP_SENSOR_CHAMBER 0"

Then in configuration_adv:
"#define CHAMBER_AUTO_FAN_PIN -1"

define that pin, presumably as "FAN1_PIN" (which is P2_04)


This means you shouldn't have to do any editing in the pin config file at all.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #4 on: July 08, 2023, 03:07:23 am »
That is a fan for the chamber but I don't think it is the right one. looking at the lines below #define CHAMBER_AUTO_FAN_PIN -1 it looks like this refers to a fan that turns on when the chamber is above a certain temp. I suppose I could use this fan as the chamber cooling fan but if I wanted to change the chamber temp I would have to change it in the firmware.
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #5 on: July 09, 2023, 08:30:24 pm »
I tried the simple thing first, adding #define CHAMBER_FAN_PIN    1_25  as shown below.

#define CHAMBER_FAN               // Enable a fan on the chamber
  #if ENABLED(CHAMBER_FAN)
    #define CHAMBER_FAN_MODE 1        // Fan control mode: 0=Static; 1=Linear increase when temp is higher than target; 2=V-shaped curve.
    #if CHAMBER_FAN_MODE == 0
      #define CHAMBER_FAN_BASE  255   // Chamber fan PWM (0-255)
    #elif CHAMBER_FAN_MODE == 1
      #define CHAMBER_FAN_BASE  255   // Base chamber fan PWM (0-255); turns on when chamber temperature is above the target
      #define CHAMBER_FAN_FACTOR 0   // PWM increase per °C above target
    #elif CHAMBER_FAN_MODE == 2
      #define CHAMBER_FAN_BASE  128   // Minimum chamber fan PWM (0-255)
      #define CHAMBER_FAN_FACTOR 25   // PWM increase per °C difference from target
    #endif

  #define CHAMBER_FAN_PIN       P1_25

  #endif

This did not work, the pin was just stuck high regardless of chamber setting or heater state. Compiling the firmware did not throw any errors, for what that is worth.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #6 on: July 11, 2023, 11:23:06 pm »
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #7 on: July 16, 2023, 07:14:52 pm »
I had a look through that post, very useful actually.

I could not find the exact file that the op mentioned called temperature.cpp to see if mine had the same issues, I have temperature.cpp.o, which I cannot open.  :-//  So I am not sure if the same bugs still exist.
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #8 on: July 16, 2023, 08:02:49 pm »
I tried a few of the things that the op did from that reddit post, to no avail unfortunately. I wish I could look at temperature.cpp to see if the chamber fan is referenced anywhere.

I did learn that fan 1 is set to use the extra extruder mosfet if you only have one extruder enabled, this fan can be controlled by the firmware. There must be a way to dig up this fan pin, I would really like to get this thing working because I want to print somethings with ABS soon.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #9 on: July 18, 2023, 09:09:58 pm »
Temperature is in \Marlin\src\module\Temperature.cpp

if you have the compiled .o (object file) then you have the source somewhere.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #10 on: July 19, 2023, 03:07:54 pm »
I found the file, though I am clueless when it comes to cpp so I will need some help deciphering this.

I found this line, the one mentioned by that reddit post. (line 1246)

 thermalManager.set_fan_speed(2, fan_chamber_pwm); // TODO: instead of fan 2, set to chamber fan                   
 
my guess is that this line is telling fan 2 to run at a certain pwm value? The pins file for my board has fan 0 and fan 1, but no fan 2. I am not using fan 1 so perhaps I could put 1 in that line and change the pin to the one that I want in the pins file?
« Last Edit: July 19, 2023, 03:12:42 pm by Alex_Baker »
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #11 on: July 19, 2023, 09:03:26 pm »
I think you can try setting the FAN2 pin to HE1 (P2.4?). Then you don't need to modify the code. Maybe try FAN1 if that doesn't work.
#define FAN2_PIN xxx

There is a FAN1 header on SKRv1.4 but it has no software control, you can see in the schematic its directly connected to Vbb (main supply, usually 12 or 24V).

https://github.com/bigtreetech/BIGTREETECH-SKR-V1.3/blob/master/BTT%20SKR%20V1.4/Hardware/BTT%20SKR%20V1.4-SCH.pdf

You could also get a generic 12V PID controller.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #12 on: July 19, 2023, 09:15:44 pm »
I saw that marlin uses the second extruder mosfet (HE1) as fan 1 when you only have one hotend. I have tried doing #define FAN2_PIN but I did not get any good results.

I will see if I can disable fan 1 and put 1 instead of 2 in line 1246, hopefully that will give control of fan 1 to the heated chamber code.
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #13 on: July 20, 2023, 12:08:32 am »
Well now I am not even sure if new firmware is being written to my board, is there a way to verify if it has? All I have done in the past is dump the firmware.bin onto the sd card and start the board. The file is 220kb, could that be to large?
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #14 on: July 20, 2023, 12:29:34 am »
Once the file is written it will be renamed to firmware.cur
If its not being renamed, it means it was never written.

220kB should be OK, the LPC1769 has 512kB flash, minus a bit for the bootloader probably.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #15 on: July 20, 2023, 12:31:26 am »
The file is never being renamed, so clearly the new firmware is not being written. Is there any way I could have borked the bootloader? I updated the firmware several weeks back when I initially started building my heated chamber, but I don't recall if the filename was changed after it updated.
« Last Edit: July 20, 2023, 12:36:22 am by Alex_Baker »
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #16 on: July 20, 2023, 09:19:10 pm »
You can try to communicate with the board over USB, plug in the USB to the PC and then user pronterface/whatever to check the version info on the board.
While you are doing that, plug in the micro SD card into the slot on the board, it should show up on the PC as a removable drive, indicating its accessible by the board.
If it doesn't show up there may be an issue with the microsd port.

https://www.reddit.com/r/BIGTREETECH/comments/imfkln/skr_v14_turbo_wont_load_firmwarebin/
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #17 on: July 21, 2023, 12:47:37 am »
The mico sd shows up as a drive on my pc while connected over usb. It also has no issue connecting to a raspberry pi running octoprint, I don't know how to check version info from there so I will look into it.
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #18 on: July 21, 2023, 09:02:43 pm »
Right so I checked with m115 the version info of marlin, and sure enough the firmware has not been updating this whole time  :palm: . So I did some digging and it seemed like a common problem with these boards was the SD card slot getting damaged, that is not the case with mine, I could access and write to the sd fine.

Here is where it gets interesting though, I decided to change the formatting of the card, I was using NTFS, no particular reason except that is what the card was formatted as already. I changed the SD card to fat32 and suddenly it decided to take the firmware file, the only problem is that the SD did not show up as a removable device in windows. The card is 8GB, I doubt that is too big, but apparently my board will not update firmware off of a ntfs SD card. So to summarize, an ntfs sd card would show up in windows but would not update FW, and a fat32 SD card would update FW but not show up in windows.

This behavior is consistent over multiple SD cards. I do not have an explanation for this phenomenon, if anybody does I would like to hear it. Although I have updated firmware now this still does not seem right, regardless of formatting shouldn't the SD still appear in windows?

I will get back on to troubleshooting the heated chamber fan thing, perhaps I will have more luck since the FW actually has changes on it now.  :scared:
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #19 on: July 21, 2023, 10:19:26 pm »
just another update, I put everything back together and so far it seems like I have solved my original issue with the fans. To get the chamber cooling fan working I left everything alone in temperature.cpp and added #define FAN2_PIN 1_25 in the pin_BTT_SKR_common.h below the other heater/fan definitions. I am guessing that this will need some tuning but for now it works, I just need to finish wiring things up.

As for the SD card thing, I would still like to figure out what is going on with that. I now know that marlin only works with fat32, but it should still show up in windows right?
 
The following users thanked this post: thm_w

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6123
  • Country: ca
  • Non-expert
Re: Need Help with Marlin 3D printer firmware
« Reply #20 on: July 21, 2023, 11:34:45 pm »
Yeah these STM32 MCU are only going to be working with FAT or FAT32 as its a simpler file system to implement.

It should still show in windows if it is FAT32 or NTFS. In windows 10 you can right click on the start menu and go to Disk Management. Sometimes if there is an odd formatting the drive will not show the partition but should still be detected at the bottom. Could try reformatting/repartitioning it.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline Alex_BakerTopic starter

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: us
Re: Need Help with Marlin 3D printer firmware
« Reply #21 on: July 22, 2023, 06:58:01 pm »
I am familiar with disk management. The device shows up there when plugged in but it just says "no media", the same my empty cd drive says "no media" as you would expect.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf