Improving and adding some comments to the code, updating a few details on the readme
This commit is contained in:
David Ramiro 2019-03-10 22:40:35 +01:00
parent 1a5804f260
commit ee6094f39d
No known key found for this signature in database
GPG Key ID: 5B042737EBEEB736
2 changed files with 130 additions and 85 deletions

View File

@ -137,23 +137,23 @@ void AnycubicTFTClass::KillTFT()
void AnycubicTFTClass::StartPrint(){
if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) { // resuming from SD pause
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was that a regular pause?
{
// are we resuming from a pause?
if (TFTstate==ANYCUBIC_TFT_STATE_SDPAUSE) {
// was that a regular pause?
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
enqueue_and_echo_commands_P(PSTR("G91")); // relative mode
enqueue_and_echo_commands_P(PSTR("G1 Z-10 F240")); // lower nozzle again
enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode
}
}
starttime=millis();
#ifdef SDSUPPORT
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was that a regular pause?
{
// was that a regular pause?
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
card.startFileprint(); // start or resume regularly
}
else if((PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) // resuming from a pause that was caused by filament runout
{
// resuming from a pause that was caused by filament runout
else if((PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
enqueue_and_echo_commands_P(PSTR("M24")); // unpark nozzle and resume
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M24 Resume from Filament Runout");
@ -163,43 +163,46 @@ void AnycubicTFTClass::StartPrint(){
SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag cleared");
#endif
}
else if((!PausedByRunout) && (PausedByFilamentChange) && (!PausedByNozzleTimeout)) // was M600 called and the nozzle is not timed out?
{
// was M600 called and the nozzle is not timed out?
else if((!PausedByRunout) && (PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Start M108 routine");
#endif
FilamentChangeResume(); // enter M108 routine
FilamentChangeResume(); // enter display M108 routine
PausedByFilamentChange=false; // clear flag
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Change Flag cleared");
#endif
}
#endif
if (!PausedByNozzleTimeout) {
TFTstate=ANYCUBIC_TFT_STATE_SDPRINT;
} else {
if (PausedByNozzleTimeout) {
// nozzle was timed out before, do not enter printing state yet
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Set Pause again because of timeout");
#endif
// clear the timeout flag to ensure the print continues on the
// next push of CONTINUE
PausedByNozzleTimeout=false;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Nozzle timeout flag cleared");
#endif
} else {
// regular resume/start or all specific resume routines are done,
// set printing state again
TFTstate=ANYCUBIC_TFT_STATE_SDPRINT;
}
}
void AnycubicTFTClass::PausePrint(){
#ifdef SDSUPPORT
if((!PausedByRunout)) // is this a regular pause?
{
if((!PausedByRunout)) { // is this a regular pause?
card.pauseSDPrint(); // pause print regularly
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Regular Pause");
#endif
}
else // pause caused by filament runout
{
} else { // pause caused by filament runout
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Runout Pause");
#endif
@ -207,7 +210,8 @@ void AnycubicTFTClass::PausePrint(){
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M25 sent, parking nozzle");
#endif
ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 Show Filament Lack prompt on screen
// show filament runout prompt on screen
ANYCUBIC_SERIAL_PROTOCOLPGM("J23");
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: J23 Show filament prompt");
@ -216,15 +220,17 @@ void AnycubicTFTClass::PausePrint(){
#endif
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
#ifdef ANYCUBIC_FILAMENT_RUNOUT_SENSOR
// regular pause
if(FilamentTestStatus) {
ANYCUBIC_SERIAL_PROTOCOLPGM("J05");// J05 pausing
ANYCUBIC_SERIAL_PROTOCOLPGM("J05");
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: SD print paused... J05");
#endif
// pause because of filament sensor
} else {
// Pause because of "out of filament"
ANYCUBIC_SERIAL_PROTOCOLPGM("J23"); //J23 FILAMENT LACK with the prompt box don't disappear
// show filament runout prompt on screen
ANYCUBIC_SERIAL_PROTOCOLPGM("J23");
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout while printing... J23");
@ -266,22 +272,31 @@ void AnycubicTFTClass::StopPrint(){
}
void AnycubicTFTClass::FilamentChangeResume(){
enqueue_and_echo_commands_P(PSTR("M108")); // call M108 to break out of M600 pause
// call M108 to break out of M600 pause
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M108 called");
SERIAL_ECHOLNPGM("DEBUG: M108 Resume called");
#endif
// remove waiting flags
wait_for_heatup = false;
wait_for_user = false; // remove waiting flags
card.startFileprint(); // resume with proper progress state
wait_for_user = false;
// resume with proper progress state
card.startFileprint();
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M108 Resume done");
#endif
}
void AnycubicTFTClass::FilamentChangePause(){
// set filament change flag to ensure the M108 routine
// gets used when the user hits CONTINUE
PausedByFilamentChange=true;
// call M600 and set display state to paused
enqueue_and_echo_commands_P(PSTR("M600"));
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ; // set TFT state to paused
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: M600 Pause called");
#endif
@ -295,13 +310,19 @@ void AnycubicTFTClass::ReheatNozzle(){
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Resume heating");
#endif
HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e); // resume heating if timed out
// enable heaters again
HOTEND_LOOP() thermalManager.reset_heater_idle_timer(e);
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Clear flags");
#endif
nozzle_timed_out = false;
// clear waiting flags
wait_for_user = false;
wait_for_heatup = false;
// set pause state to show CONTINUE button again
TFTstate=ANYCUBIC_TFT_STATE_SDPAUSE_REQ;
}
@ -570,8 +591,8 @@ void AnycubicTFTClass::StateHandler()
#ifdef SDSUPPORT
if((!card.sdprinting) && (!planner.movesplanned())) {
// We have to wait until the sd card printing has been settled
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout))
{
if((!PausedByRunout) && (!PausedByFilamentChange) && (!PausedByNozzleTimeout)) {
// no flags, this is a regular pause.
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Regular Pause requested");
#endif
@ -579,13 +600,12 @@ void AnycubicTFTClass::StateHandler()
enqueue_and_echo_commands_P(PSTR("G1 E-2 F1800")); // retract 2mm
enqueue_and_echo_commands_P(PSTR("G1 Z10 F240")); // lift nozzle by 10mm
enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode
} else if((PausedByRunout))
{
} else if((PausedByRunout)) {
// filament runout, retract and beep
enqueue_and_echo_commands_P(PSTR("G91")); // relative mode
enqueue_and_echo_commands_P(PSTR("G1 E-3 F1800")); // retract 3mm
enqueue_and_echo_commands_P(PSTR("G90")); // absolute mode
enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000")); // alert user with beeps
enqueue_and_echo_commands_P(PSTR("M300 S2093 P3000"));
enqueue_and_echo_commands_P(PSTR("M300 S1567 P1000\nM300 S2093 P3000"));
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament runout - Retract, beep and park.");
#endif
@ -629,9 +649,8 @@ void AnycubicTFTClass::FilamentRunout()
#if ENABLED(ANYCUBIC_FILAMENT_RUNOUT_SENSOR)
FilamentTestStatus=READ(FIL_RUNOUT_PIN)&0xff;
if(FilamentTestStatus>FilamentTestLastStatus)
{
// something changed! save current timestamp.
if(FilamentTestStatus>FilamentTestLastStatus) {
// filament sensor pin changed, save current timestamp.
const millis_t fil_ms = millis();
static millis_t fil_delay;
@ -646,22 +665,19 @@ void AnycubicTFTClass::FilamentRunout()
FilamentSetMillis=false;
}
// have three seconds passed?
if ((FilamentTestStatus>FilamentTestLastStatus) && (fil_ms>fil_delay)) {
// if three seconds passed and the sensor is still triggered,
// we trigger the filament runout status
if ((FilamentTestStatus>FilamentTestLastStatus) && (ELAPSED(fil_ms, fil_delay))) {
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: 3000ms delay done");
#endif
#ifdef SDSUPPORT
if((card.sdprinting==true))
{
if((card.sdprinting==true)) {
PausedByRunout=true; // set runout pause flag
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("DEBUG: Filament Pause Flag set");
#endif
PausePrint();
}
else if((card.sdprinting==false))
{
} else if((card.sdprinting==false)) {
ANYCUBIC_SERIAL_PROTOCOLPGM("J15"); //J15 FILAMENT LACK
ANYCUBIC_SERIAL_ENTER();
#ifdef ANYCUBIC_TFT_DEBUG
@ -669,13 +685,10 @@ void AnycubicTFTClass::FilamentRunout()
#endif
FilamentTestLastStatus=FilamentTestStatus;
}
#endif
}
}
else if(FilamentTestStatus!=FilamentTestLastStatus)
{
// set the timestamps on the next loop again
FilamentSetMillis=true;
else if(FilamentTestStatus!=FilamentTestLastStatus) {
FilamentSetMillis=true; // set the timestamps on the next loop again
FilamentTestLastStatus=FilamentTestStatus;
#ifdef ANYCUBIC_TFT_DEBUG
SERIAL_ECHOLNPGM("TFT Serial Debug: Filament runout recovered");
@ -864,8 +877,7 @@ void AnycubicTFTClass::GetCommandFromTFT()
break;
case 13: // A13 SELECTION FILE
#ifdef SDSUPPORT
//if((!planner.movesplanned()) && (TFTstate!=ANYCUBIC_TFT_STATE_SDPAUSE) && (TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE))
if((TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE)) // allow special menu to be used while printing from USB
if((TFTstate!=ANYCUBIC_TFT_STATE_SDOUTAGE))
{
starpos = (strchr(TFTstrchr_pointer + 4,'*'));
if (TFTstrchr_pointer[4] == '/') {

View File

@ -6,8 +6,7 @@ This is my slightly customized version of the [Marlin Firmware](https://github.c
Feel free to discuss issues and work with me further optimizing this firmware!
I am running this version on an i3 Mega Ultrabase V3 (for distinction of the different versions, check [this Thingiverse thread](https://www.thingiverse.com/groups/anycubic-i3-mega/forums/general/topic:27064)).
Basically, this should work on every Ultrabase version that has two Z-axis endstops.
This firmware works on every i3 Mega that has two Z-axis endstops. If you have an older model with only one Z endstop, a small [adjustment](https://github.com/davidramiro/Marlin-AI3M/wiki/Customization-&-Compiling#single-z-endstop) is required.
The new **Mega-S** should work too, but you will need to enter two additional commands after flashing the firmware, mentioned in the instructions below.
@ -19,13 +18,6 @@ Note: This is just a firmware, not magic. A big part of print quality still depe
A German translation of the instructions can be found [here](https://kore.cc/i3mega/download/marlin-ai3m_german.pdf).
## Known issues:
- Power outage support is not included
- Estimated print times from your slicer might be slightly off.
- Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem.
**Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.**
- Cancelling prints after pausing may show an error. Simply resume the print before canceling. Protip: Switch to OctoPrint.
## Why use this?
@ -40,7 +32,16 @@ While the i3 Mega is a great printer for its price and produces fantastic result
- Very loud stock stepper motor drivers, easily replaced by Watterott or FYSETC TMC2208. To do that, you'd usually have to flip the connectors on the board, this is not necessary using this firmware.
- No need to slice and upload custom bed leveling tests, test it with a single GCode command
- Easily start an auto PID tune or mesh bed leveling via the special menu (insert SD card, select special menu and press the round arrow)
- Filament change feature enabled: Switch colors/material mid print with `M600` (instructions below)
- Filament change feature enabled: Switch colors/material mid print (instructions below) and control it via display.
- The filament runout sensor functionality has been overhauled and improved: The hotend now parks and retracts automatically and purges after loading a new spool.
## Known issues:
- Power outage support is not included
- Estimated print times from your slicer might be slightly off.
- Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem.
**Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.**
- Cancelling prints after pausing may show an error. Simply resume the print before canceling. Protip: Switch to OctoPrint.
## How to flash this?
@ -57,8 +58,9 @@ I provided three different precompiled hex files: One for no modifications on th
### Or compile it yourself:
- Download Arduino IDE
- Download and install [Arduino IDE](https://www.arduino.cc/en/main/software)
- Clone or download this repo
- Browse into the Marlin folder and run `Marlin.ino`
- In the IDE, under `Tools -> Board` select `Genuino Mega 2560` and `ATmega2560`
- Open Marlin.ino in the Marlin directory of this repo
- [Customize if needed](https://github.com/davidramiro/Marlin-AI3M/wiki/Customization-&-Compiling) (e.g. motor directions and type at line `559` to `566` and line `857` to `865` in `Configuration.h`)
@ -69,7 +71,7 @@ I provided three different precompiled hex files: One for no modifications on th
- Flash the hex with Cura, OctoPrint or similar
- Use a tool with a terminal (OctoPrint, Pronterface, Repetier Host, ...) to send commands to your printer.
- Connect to the printer and send the following commands:
- **Important** Connect to the printer and send the following commands:
- `M502` - load hard coded default values
- `M500` - save them to EEPROM
@ -80,7 +82,6 @@ I provided three different precompiled hex files: One for no modifications on th
#### Calibration and other instructions have been moved to the [Wiki](https://github.com/davidramiro/Marlin-AI3M/wiki/Calibration).
## Manual Mesh Bed Leveling
If you have issues with an uneven bed, this is a great feature.
@ -103,7 +104,7 @@ If you have issues with an uneven bed, this is a great feature.
- Your nozzle will now move to the first calibration position.
- Don't adjust the bed itself with screws, only use software from here on!
- Use a paper - I recommend using thermopaper like a receipt or baking paper
- Use the onscreen controls to lower or raise your nozzle until you feel a light resistance: (If you want to send the same command multiple times, select the item again, even though it is still marked red.)
- Use the onscreen controls to lower or raise your nozzle until you feel a light resistance: (**If you want to send the same command multiple times, select the item again, even though it is still marked red.**)
![Z axis controls][control]
@ -112,7 +113,7 @@ If you have issues with an uneven bed, this is a great feature.
![Next mesh point][next]
- Repeat the last two steps until all 25 points are done.
- Your printer will beep, wait 20 seconds and then save:
- Your printer will beep, wait 20 seconds and then save (the printer will beep once more to confirm):
![Save to EEPROM][save]
@ -129,15 +130,14 @@ If you have issues with an uneven bed, this is a great feature.
### After leveling:
- Reboot the printer.
- To ensure your mesh gets used on every print from now on, go into your slicer settings and look for the start GCode
- Look for the Z-homing (either just `G28` or `G28 Z0`) command and insert these two right underneath it:
```
M501
M420 S1
```
- Enjoy never having to worry about an uneven bed again!
- Your printer should now correctly print first layers even on a warped bed.
- When working on the printer, installing a new hotend or nozzle or the bed warping over time, a new Mesh Leveling procedure is recommended.
#### Manual commands for use with OctoPrint etc.:
@ -156,6 +156,7 @@ G28
G26 C H200 P25 R25
```
- To adjust your filament's needed temperature, change the number of the `H` parameter
- Default bed temperature is 60°C, if you need another temperature, add e.g. `B80`
- If your leveling is good, you will have a complete pattern of your mesh on your bed that you can peel off in one piece
- Don't worry if the test looks a bit messy, the important thing is just that the line width is the same all over the mesh
- Optional: Hang it up on a wall to display it as a trophy of how great your leveling skills are.
@ -167,9 +168,9 @@ G26 C H200 P25 R25
[m600 demo]: https://kore.cc/i3mega/img/m600demo.jpg "M600 demo"
**Printing via USB is highly recommended for this.**
**BETA: This now also works without USB printing, via SD & display.**
#### Configuration:
#### Configuration (only needed once):
- Send `M603 L0 U0` to use manual loading & unloading.
- Send `M603 L538 U555` to use automatic loading & unloading
- The `L` and `U` paramters define the load and unload length in mm. The values above work well on a stock setup, if you modded your extruder, bowden tube or hotend, you might need to adjust those.
@ -235,6 +236,11 @@ M304
After flashing the new version, issue a `M502` and `M500`. After that, enter every line you saved before and finish by saving with `M500`.
## Something went wrong?
No worries. You can easily go back to the default firmware and restore the default settings.
- Flash the hex file from the [manufacturer's website](http://www.anycubic3d.com/support/show/594016.html) (in case it's offline, I have uploaded the stock firmwares [here](https://kore.cc/i3mega/download/stockFW/) as well).
- After flashing, send `M502` and `M500`. Now your machine is exactly as it came out of the box.
## Detailed changes:
@ -248,10 +254,14 @@ After flashing the new version, issue a `M502` and `M500`. After that, enter eve
- G26 Mesh Validation enabled
- Some redundant code removed to save memory
- Minor tweaks on default jerk and acceleration
- Printcounter enabled (`M78`)
- Print statistics enabled (send `M78` to read them)
- `M600` filament change feature enabled
- Screen resume for `M600` implemented
- Filament runout, stop and pause behaviour tweaked
- Implemented easy resume via display
- Filament runout behaviour tweaked
- Added purge and retract
- Move nozzle to park position on runout
- Prevent false positives by adding a small delay to the sensor
- Pause and stop behaviour tweaked
## Changes by [derhopp](https://github.com/derhopp/):
@ -337,3 +347,26 @@ Notable contributors include:
## License
Marlin is published under the [GPLv3 license](https://github.com/MarlinFirmware/Marlin/blob/1.0.x/COPYING.md) because we believe in open development. The GPL comes with both rights and obligations. Whether you use Marlin firmware as the driver for your open or closed-source product, you must keep Marlin open, and you must provide your compatible Marlin source code to end users upon request. The most straightforward way to comply with the Marlin license is to make a fork of Marlin on Github, perform your modifications, and direct users to your modified fork.
## Disclaimer
```
/*
* Flashing a custom firmware happens at your own risk.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
* AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
```