MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.17k stars 19.21k forks source link

[FR] Prusa MMU 2.0 support #11859

Closed revilor closed 5 years ago

revilor commented 5 years ago

I will try to add support for the Prusa MMU 2.0 to Marlin as soon as I have a unit at hand. So just to avoid reinventing the wheel: is anybody already working on MMU 2.0 integration?

brandstaetter commented 5 years ago

I guess Prusa will publish their sources, so we probably we should wait for that?

rmoravcik commented 5 years ago

Prusa already released source code of their firmware with MMU support. https://github.com/prusa3d/Prusa-Firmware/blob/MK3/Firmware/mmu.cpp

revilor commented 5 years ago

I walked through the Prusa sources already. Nothing too complex, but we'll have to generalize, implement the serial communication based on the HAL, etc. to make the MMU usable with as many printers as possible.

FNeo31 commented 5 years ago

So I didn't buy an MMU from Prusa I made one myself. My trouble right now os just the communication. Like I try to explain below.

The system is simple and just need messages system by Serial to work independently. Just an add-in system.

Objective:

Connect One Multi-Material unit to a printer with communication by Serial on pins Rx2Tx2 (MEGA + RAMPS 1.4 configuration)

What's needed:

Make a Clone of all movements of extruder E0 to other motor (E1) same way that we can make with the Axis like Z and Z2.

Instead of Make some tool change, pick the T number and send it by Serial on format "T1." or "T2." or "T3." , Etc. To change the tool on multi material unit.

just continue the print after receive "OK." for example.

I know, this isn't a trouble is an improve to new generations of printers with a lot of material with just one extruder noozle and with direct drive extruding with just one motor on head.

Can you help me?

If you are available to help me I'll post here all the hardware and the code of Multi Material Unit after test and check that os works well.

This was what I posted on #11879

thinkyhead commented 5 years ago

It shouldn't be too tricky to implement, except that right now we don't support a second serial connection in the AVR version of Marlin. So that would need to be added in.

Does it really need multiple extruders to be defined in Marlin and multiple sets of stepper signal pins? It was my understanding that a single E0 extruder is all that's needed from the Marlin side, and the steppers on the MMU are controlled by its onboard MCU.

revilor commented 5 years ago

@FNeo31 is your MMU based on the PCB and firmware published by Prusa? I'm building one myself, waiting for the PCB at the moment.

From my understanding there is no replication of extruder movements to the MMU. The MMU loads the filament into the extruder and then moves out of the way. The extruder will then pull the filament just through the MMU box. Otherwise you would have to take care for some slack in the filament path should extruder and MMU get out of sync (like the Mosaic Palette+ does).

thinkyhead commented 5 years ago

Just peeked at the MALYAN_LCD which uses Serial1, and evidently we can do that on AVR very easily. So strike my previous comment about serial.

revilor commented 5 years ago

It shouldn't be too tricky to implement, except that right now we don't support a second serial connection in the AVR version of Marlin. So that would need to be added in.

Does it really need multiple extruders to be defined in Marlin and multiple sets of stepper signal pins? It was my understanding that a single E0 extruder is all that's needed from the Marlin side, and the steppers on the MMU are controlled by its onboard MCU.

That's also my understanding, yes.

revilor commented 5 years ago

Just peeked at the MALYAN_LCD which uses Serial1, and evidently we can do that on AVR very easily. So strike my previous comment about serial.

I already created PR #11880 to enable additional uarts. But I'll have a look at the MALYAN_LCD.

revilor commented 5 years ago

Just peeked at the MALYAN_LCD which uses Serial1, and evidently we can do that on AVR very easily. So strike my previous comment about serial.

I already created PR #11880 to enable additional uarts. But I'll have a look at the MALYAN_LCD.

Ok, MALYAN_LCD uses Arduino Serial1 directly. But to provide MMU support also for boards other than AVR some abstraction in the HAL will be required, I guess.

thinkyhead commented 5 years ago

The HALs all provide some kind of emulation of the Arduino Serial# ports, so things like MALYAN_LCD ought to work with any MCU.

radsonpatrick commented 5 years ago

Hello, how are you ?, I'm trying to develop the adaptation for marlin I believe that the most complex part will be interpreting the gcode sent by the serial to select the filament and its respective size

revilor commented 5 years ago

@radsonpatrick My MMU build is still missing the control board, so for the moment I'm using one Arduino Mega2560 + RAMPS for Marlin and another Mega2560 emulating the MMU 2 unit. This way I can implement the serial communication without an actual MMU. I have the initial setup routine (requesting version, buildnr and FINDA status from the MMU) working with my emulator. Next step will be to implement the filament load/unload commands. If you are interested I can push the current state to my github repository.

There is no gcode send to or from the MMU by the way. The printer firmware sends simple commands like "Unload filament", "Switch to filament x", "Load filament" to the MMU which answers "ok" when the command has been executed.

Lyr3x commented 5 years ago

Do you already have som documentation how you build everything? Or is it just a RAMPS + spare Mega2560 for now? It would be nice if you can push everything to a repository that we can have a look. I am more then willing to support 👍

radsonpatrick commented 5 years ago

I want to understand, so he does not cut filaments in size? than a cutting blade would be serious for that, but that's more sense, would not it just interpret the M600 code?

revilor commented 5 years ago

The spare Mega2560 is emulating the MMU until I have a working MMU2 unit. Connecting the real MMU2 to the printer board is quite straightforward.

But first a short disclaimer: the following info is without guarantee, it's based on the assembly guide and the schematics for the control board published on Prusa's github repository. So if you kill your MMU2 by connecting it to any printer other than the Prusa Mk3, don't blame me for that.

Ok, so to hook up the MMU to a RAMPS board you can follow https://manual.prusa3d.com/Guide/3.+Electronics+and+MMU2+unit+assembly/757?lang=en down to Step 40.

The power cable (green) will go to your power supply. Prusa uses 24V on the Mk3, but 12V should be fine for the MMU steppers, too.

The signal cable (pink) has the following connections

So on the RAMPS board you will connect

If you have an LCD connected to AUX-4, pins 16 and 17 could be an issue, depending on the display at use. But UART0 is USB, and the pins of UART1 and UART3 are used for endstops, so UART2 is the only remaining serial to communicate with the MMU2.

SoftwareSerial might be an option in case pins 16 and 17 are used for the display, or for printer boards which have no serial connection at all.

radsonpatrick commented 5 years ago

I'm not using the prusa, I'm using marlin 1.1.9, so it will not be useful to me, I watched some videos and I understood the operation, so your already in what stage? charging the filament? communication with the main arduino?,I want to be a DIY

FNeo31 commented 5 years ago

I'm working in a MMU system made by me to the tool seletor on MMU and positioning I'm using a 28YBJ-48 stepper with a ULN 2003 drivers to be more compact. For the MMU board I'm using one Arduino nano with ATmega 328.

I'll Change the pin -Y to the position of X+ top put the end stop of Y and conect the serial2 of mega+ramps1.4 to the nano.

The extruder motor I will clone to feed motor on MMU. Direct controlled by main board. Instead of blade I Will put a gate stop.

PS I don't have a PRUSA too

radsonpatrick commented 5 years ago

If you need help with something I am at your disposal. Do you have photos of the project? will you use the same desing as mmu2.0?

revilor commented 5 years ago

@FNeo31 @radsonpatrick I'm building a Prusa MMU2 myself based on the sources published on Prusa's github repository. If everything works out - missing part is the controller board - I'll have an exact clone of the original Prusa MMU2.

Therefore what I'm implementing in Marlin is based on the firmware and communication protocol for Prusa's MMU2. If your self-designed MMU units behave in exactly the same manner they should work, too.

radsonpatrick commented 5 years ago

Is your documentation of the development of your project in github?

radsonpatrick commented 5 years ago

@revilor If you need help I'm giving my whatsaap to exchange ideas about this upgrade.

GMagician commented 5 years ago

OT @revilor don't know if you need it or not but on aliexpress there is a mmu2 board clone available. A question about your project, there are some parts in mmu2 that are not easily on the market (brass tubes on carriage and brass nut for ptfe come in my mind) where did you found them?

revilor commented 5 years ago

OT @GMagician Brass tubes were no problem here in Germany, 6mm outer and 5mm inner diameter like this https://ebay.us/xATVqt Cutting to 25mm length is no problem as Brass is easy to work with. The selector is not moving too fast, so I guess reducing the openings in the printed part to 5.1mm or so and go without the brass tubes should work fine, too.

For the PTFE mount I modified the printed part using the published OpenSCAD file. I reduced the center hole to a diameter of 5mm, tapped an M6x1 thread and directly screwed in the pneumatic connector. On Twitter I have a photo https://twitter.com/revilor3d/status/1043900826257960961.

The most challenging part for me was the stepper with a 130mm shaft for the pulleys. I could not find one on the market so I modified a stepper I had laying around and replaced the shaft with a 150mm long 5mm smooth rod, photo also on twitter.

Thanks for the tip regarding the controller board. I have all the soldering equipment so doing it myself should be fine. But good to know there is a fallback should I screw up.

revilor commented 5 years ago

My latest sources are now in my repository: https://github.com/revilor/Marlin/tree/MMU2

Check Configuration_adv.h and feature/Prusa_MMU2.

makerbitter commented 5 years ago

Hello, is fully compatible MMU2 with Marlin? I'm finishing my MMU2 clone (Arduino+ramps+drv8825) , it will work with Marlin?

thinkyhead commented 5 years ago

Good question. Please try it and let us know!

Lyr3x commented 5 years ago

SoftwareSerial might be an option in case pins 16 and 17 are used for the display, or for printer boards which have no serial connection at all.

Is it really possible to use two pins in software serial mode and the TMC2130 with SPI? Connected five TMC2130 and an Full Graphics disply to my MKS Gen 1.4 so SoftwareSerial is the only option right?

revilor commented 5 years ago

@Lyr3x There should be ways to avoid SoftwareSerial. I assume you are not using pins 16 or 17 as CS for your TMC2130s. So the question is: what is the exact display you are using? Because most of the displays I checked do not use pins 16 and 17. In that case it would just be a question of how to get to the pins of the EXP1 connector. You could cut the wires to the display or create some kind of adapter for that purpose.

If D16 and D17 are used by the display or you can't find a way to use them, moving the Y or Z endstops to other pins could be an alternative. This would free the uart1 or uart3 pins to communicate with the MMU.

If you can't get a hardware serial to use, SoftwareSerial might be an option. But with all the timing-critical stuff that's going on inside Marlin I'm not sure it really is. The main board is asking the MMU for the FINDA status every 300ms, so there is a lot of communication. You would have to test and see if SoftwareSerial works, I guess.

revilor commented 5 years ago

@makerbitter We are not there yet, but the plan is to make Marlin fully compatible with MMU2. So if your clone uses Prusa's MMU2 firmware or at least implements the MMU's serial communication protocol, it should work.

Lyr3x commented 5 years ago

@revilor I'm using this type of Display right now: https://reprap.org/wiki/MKS_MINI_12864 Correct me if i'm wrong but it seems this type of display does not use 16/17:

#elif ENABLED(MKS_MINI_12864)   // Added in Marlin 1.1.6

      #define DOGLCD_A0         27
      #define DOGLCD_CS         25

      // GLCD features
      //#define LCD_CONTRAST   190
      // Uncomment screen orientation
      //#define LCD_SCREEN_ROT_90
      //#define LCD_SCREEN_ROT_180
      //#define LCD_SCREEN_ROT_270

      #define BEEPER_PIN        37
      // not connected to a pin
      #define LCD_BACKLIGHT_PIN 65   // backlight LED on A11/D65

      #define BTN_EN1           31
      #define BTN_EN2           33
      #define BTN_ENC           35

      #define SD_DETECT_PIN     49
      #define KILL_PIN          64
revilor commented 5 years ago

@Lyr3x From all the information I found regarding your display I would say you are good to go using pins 16 and 17 for serial. They are not used by the display.

revilor commented 5 years ago

Important notice: I missread the schematics regarding the serial connection, you have to swap the green and white wire on your printer board. White is RX on the MMU side, green is TX.

So on the RAMPS board you will connect

I corrected my comment above accordingly.

Lyr3x commented 5 years ago

Alright, everything I need is ordered. I bought the control board from AliExpress. We'll see if this is working out.

Lyr3x commented 5 years ago

@revilor Do you can give an status update?

alexxy commented 5 years ago

I plan to build my own version of MMU2 with stm32f1 board (actualy based on blue pill).

revilor commented 5 years ago

Status update: handling filament change for the T0..4 gcode is implemented in my repository. The MMU unit seems to do what it is supposed to do for a material change. But still a lot of testing is required. My next step is to print and mount the Mk3 extruder upgrade parts and then try a real multi-material print.

alexxy commented 5 years ago

Btw is it possible to have 2 mmu2 units?

revilor commented 5 years ago

@alexxy To control 2 MMU units you require two free serial ports on your printer board. And support for two MMUs in Marlin, of course.

blackus3r commented 5 years ago

@revilor Which board do you use currently? Did you build your own MMU2?

bula87 commented 5 years ago

Hi there, If you are interested I ported MMU2 firmware for Ramps... It could help in Marlin part. It is still the first implementation, I have to tweak motor movement to do not grind too much during homing (no feedback from tmc's drivers). In the following days, I should fix those issues. My fork: https://github.com/bula87/MM-control-01

cskozlowski commented 5 years ago

I did an mmu2 implementation using Ramps board + Arduino mega 2560. It has been fully operational since October 20th, 2018. I print every day with it and added a 2nd sensor at the top of the mk3 extruder to make it extremely reliable. Code was developed from scratch. https://github.com/cskozlowski/mmu2

makerbitter commented 5 years ago

Is there any progress in Marlin implementation? Is only compatible with Mk2.5/MK3 firmware?

Lyr3x commented 5 years ago

Check the repository from revilor. He's implementing it in a way that we can use the official Hardware. I can test it soon

OleUrgast commented 5 years ago

I do not understand, why it should be so complicated. As I understand by now, the MMU2 controller get only comandos like "retract filament into mmu2" "select tool" and "load filament into extruder". Also the MMU2 sends Back an OK. By the way - which are the exact commands transfered between both controllers? So "communication" should be very simple without changing anything in Marlin (or any other controller firmware). Simply use an small extra arduino (3-4$ for a Clone). Connect dir/step signals from printer stepper driver for the extruder. The Arduino simply count steps if dir is in retract direction, resetting counter if a forward step is done. If the counter exeeds a certain number, obviously the printer has not only done a retract but fully unloaded filament. So an "unload" can be detected by the extra Arduino. If you didn't have access to dir/step, you may simply add an optical rotary encoder to your extruder motor. So in gcode its a simple long backward movement of the extruder (Not m600 !). I think slic3r does that anyway on colour change (with an special accelleration profile to reduce blops in filament).

As the extra Arduino detects the unload, it can send the propper comand to mmu2 controller by serial connection. So filament will be retract into mmu2.

Next step: choose material number. In gcode move extruder 1...5 mm forward. As the extruder is empty (mmu2), nothing happens - but by dir/step or optical rotary encoder the Arduino now knows that you want material 1...5 next. Arduino waits muu2 completed filament been retracted (getting "O.K.") and sends command to choose material 1...5. Next gcode command is m600. You need to add the lenght for loading new filament, as normaly the filament would be squezed out of the nozzle to clear it, but we only have to put it to the nozzle, squezing and clearing will be done in wipe tower (or infill or extra object). M600 will mostly wait to "O.K.-button" to be pressed. So connect an relais in parallel to the O.K.-Button. So Arduino now can "Push" O.K. when it gets the o.k. for new filament loaded from mmu2 by serial. This May not needed, if printer has filament-sensor and filament-autoload.

The difference between changing marlin and / or mmu2 firmware and using an "Interface-Arduino" is, that an Interface-Arduino would work with nearly any firmware - not only Marlin.

revilor commented 5 years ago

@blackus3r I used the printed parts and PCB from Prusa's github repository to build a MMU2 clone.

Lyr3x commented 5 years ago

The electronics of my MMU 2.0 clone is working nearly fine, but i have some issues with filament loading (filament is slipping) and homing of the mmu. The stallguard threshold is not working fine for me.

makerbitter commented 5 years ago

@revilor your Marlin is fully functional with the MMU 2 clone board? Did you make prints successful?

0lympu5 commented 5 years ago

Has anyone got a functioning marlin fw for a genuine MMU 2.0 with ramps 1.4

I've enabled all the options, 5 extruders, the multiplexer, nozzle park and advanced pause feature but still need to find the pins so I can change them as I have a full graphics display and anything else I'm missing for the proper communication between the two

yellobello commented 5 years ago

I am also a little confused. As I see there is cskozlowski´s code to implement the MMU2 with an MEGA2560/RAMPS but this only works with the einsy board and the prusa firmware. But is there a current way to interface it to marlin fw?