Uncategorized

3D print from PC stop for no reason? I think I figured out why.

Problem

  • Start your PC and connect to your 3D printer through a USB cable.
  • Begin a print from your PC.
  • Part way through the print, printing stops. No reason given. New commands sent to printer get queued.

Checksums

Picture this: I’m at the Bay Area Maker Fair, talking to a news crew about the Makelangelo and why it’s great for learning 3D printing. Suddenly, the pen start going WAY off course and I have to leap into action before the machine breaks itself. While the cameras are rolling! So embarrassing. What could have caused it?

Turns out USB Serial (the way your PC talks to your printer) doesn’t have any checksums like TCP/IP. This means once in a random while – maybe every 5000 commands? – a single character would not arrive. The PC might send “AOK” and the printer would receive “AK” or “AO”. Most of the time if it happened the error was small – sending 10.004 instead of 10.0034 didn’t make a big difference. Sending 100034 was a show-stopper!

If I think someone’s solved a problem before, I look at how they did it. Marlin – the code most 3D printers have in their brains – noticed this problem and added checksums. When the PC sends a command it sends “AOK*█”. The * means “there’s a checksum after this” and █ is ( A + O + K ) % 0xFF. if the part before * doesn’t add up to the checksum, Marlin asks the PC to send again.

What I found

When Marlin sends to the PC there is no checksum and the PC has no way to say “what? can you repeat that?”

What happens is:

  • PC sends an instruction
  • Marlin says “OK” and starts waiting for a new instruction.
  • PC receives “O”
  • PC can’t ask for it again, so it keeps waiting for “K”.
  • Both machines are waiting for each other forever.
  • New commands to the PC are put in a queue. “I’ll send it as soon as I get the OK from Marlin”.

The fix

I added a short timer to Marlin. After it sends “OK” the timer starts. If the timer runs out then Marlin hasn’t heard from the PC, so it resets the timer and says “OK” again. I made my very first Git pull request – asking the head Marlin coders to add my changes for everyone.  With a little luck it will be in the code in a couple of days and everyone will enjoy.

What’s next

The biggest challenge now is testing. How do you prove that something that almost never happens has finally stopped happening?

If this has improved your printing from PC, please make a pull request for the Makelangelo software or any of the many open source projects you love.