Thursday, August 25, 2016

Turning the M3D The Micro into a Wi-Fi 3D Printer with Raspberry Pi

Combining everything from previous posts to build a compact Wi-Fi-enabled 3D printer.



The goal here is to be able to monitor print progress and control the 3D printer through a browser over Wi-Fi.

Operating it via the touchscreen monitor would also be possible with more effort, but that's for another day.

Wi-Fi 3D printer setup overview



※ If the brown PLA filament looks like something it shouldn't, gently close your eyes and scroll past it.



Materials


Everything needed has been covered in previous posts:



Check on Amazon

3D Printer

M3D The Micro

The ultra-compact 3D printer that had a historic Kickstarter run. Now also available on Amazon.

Aside from being small and good-looking, it has no other practical advantages — normally requires a direct PC connection.







Check on Amazon

Controller

Raspberry Pi 3 + LCD display

Raspberry Pi 2 or earlier won't work well. Pi 3 is recommended.

Reason: the Pi 2 doesn't have Wi-Fi. Also, connecting multiple USB devices draws more power than earlier models can comfortably handle.

Note: the LCD display is optional for this setup, but using OctoPiPanel allows touchscreen control of the printer.





Check on Amazon

USB Camera

USB digital microscope with LED

Deliberately using the microscope from last time — a regular webcam would be more practical.

For a webcam, a UVC-compatible model with a built-in LED is recommended.





Setting up OctoPrint on Raspberry Pi



We'll be using OctoPrint.

There's a more feature-rich 3D printer server for Raspberry Pi called Repetier-Server, but it doesn't have a profile for the M3D The Micro, so that was out.



If you're setting up a Raspberry Pi 3 dedicated to OctoPrint, use OctoPi instead of Raspbian — it comes pre-configured.



In this case, I wanted to keep the LCD monitor working, so I'm adding OctoPrint to an already-running Raspberry Pi.

Setting up Raspbian on a Raspberry Pi 3 with Wi-Fi is covered in a previous post.



With that preamble out of the way, follow a guide like this to set up OctoPrint:

"Installing OctoPrint on Raspberry Pi for standalone 3D printer ATOM operation" (Japanese)



Clone from git and install OctoPrint.

You can clone anywhere; I prefer a subdirectory to keep my home directory clean:

pi@raspberrypi: ~ $ mkdir git
pi@raspberrypi: ~ $ cd git
pi@raspberrypi: ~/git $ sudo apt-get install python-pip python-dev git
pi@raspberrypi: ~/git $ git clone https://github.com/foosel/OctoPrint.git
pi@raspberrypi: ~/git  $ cd OctoPrint
pi@raspberrypi: ~/git/OctoPrint $ sudo pip install -r requirements.txt



Add the pi user to the required groups and log out.
OctoPrint runs with user-level permissions, so this is required. Group changes take effect on the next login, so you must log out before starting OctoPrint:
pi@raspberrypi: ~/git/OctoPrint $ sudo usermod -a -G tty pi
pi@raspberrypi: ~/git/OctoPrint $ sudo usermod -a -G dialout pi
pi@raspberrypi: ~/git/OctoPrint $ sudo usermod -a -G staff pi
pi@raspberrypi: ~/git/OctoPrint $ exit



Connect the M3D The Micro's USB cable to the Raspberry Pi, then start OctoPrint:

pi@raspberrypi: ~/git/OctoPrint $ ./run



From a PC on the same Wi-Fi network, open a browser and navigate to:

http://{Raspberry Pi IP address}:5000/

If the OctoPrint interface loads, you're in business:

OctoPrint web interface



Connecting OctoPrint to the M3D The Micro



Go to Settings from the top menu.

Find "Plugin Manager" in the left sidebar.

Search for "M3" in the plugin search box — you'll find a plugin called "M33-Fio."

(Older blog posts refer to it as "M3D-Fio" — apparently the name changed due to a trademark issue.)

OctoPrint Plugin Manager showing M33-Fio


If nothing shows up in the Plugin Manager, it's a permissions issue.

Add the pi user to the tty, dialout, and staff groups, log out, log back in, then restart OctoPrint. That should fix it.



pi@raspberrypi: ~/ $sudo chmod g+w /usr/local/lib/python2.7/dist-packages/octoprint_setuptools/



Slicing with CuraEngine



Without a slicer, you can't print unless you send GCode directly.

Install the CuraEngine plugin to enable STL slicing.



Installation instructions vary widely online, and not all of them work. This was quietly frustrating.



First, download the deb package from Ultimaker's site to get the profiles and other assets.

Make sure to download version 15.04.x — newer versions are not supported by OctoPrint.

https://ultimaker.com/en/products/cura-software/list



Extract the downloaded package:

pi@raspberrypi: ~/ $ sudo dpkg-deb --extract cura_15.04.5-debian_amd64.deb /



The CuraEngine binary that lands in /usr/share/cura/ is an amd64 binary, not ARM — it won't run on Raspberry Pi as-is.



Follow the OctoPrint GitHub instructions to rebuild CuraEngine for ARM and replace the binary:



pi@raspberrypi: ~/git/ $ sudo apt-get -y install gcc g++
pi@raspberrypi: ~/git/ $ git clone -b legacy https://github.com/Ultimaker/CuraEngine.git
pi@raspberrypi: ~/git/ $ make -C CuraEngine
pi@raspberrypi: ~/git/ $ sudo mkdir -p /usr/share/cura/
pi@raspberrypi: ~/git/ $ sudo cp CuraEngine/CuraEngine /usr/share/cura/



After building the binary, install the "Cura Engine" plugin through OctoPrint's Plugin Manager, then open the "Cura Engine" menu that appears in the left sidebar.



If OctoPrint has auto-detected CuraEngine successfully, it should look like this without any manual configuration.

The M3D profile was apparently added by the M33-Fio plugin (probably):

OctoPrint Cura Engine settings with M3D profile



Printing



At this point you can print remotely.

Click "Connect" on the top of the main screen and confirm that "Machine State" shows "Operational."

OctoPrint main screen showing Operational state



If it doesn't reach Operational, the likely causes are: a bad connection, the printer not being powered on, or a plugin issue.



Once Operational, upload an STL file from the bottom-left menu.

Uploaded files are saved, so you can come back later from an iPad or other device to start printing.



The STL file needs to be sliced into a .gco file first.

Click the small button in the bottom-right of the filename (marked with a red circle) to open slicing settings — it's easy to miss:

OctoPrint slice button location



I'd almost forgotten this was an M3D until this screen appeared:

OctoPrint slicing dialog

OctoPrint M3D printer profile selection



After clicking slice, if it gets stuck at "slicing (0%)" forever, the CuraEngine build failed.

Try running the CuraEngine binary directly in a shell — it will likely throw an error.

Rebuild CuraEngine, confirm there are no build errors, and replace the binary.





Connecting the camera



Conveniently, the mjpg-streamer setup from the earlier streaming post works here as-is.

The configuration described in "Streaming a USB Microscope with Raspberry Pi 3" can be used directly — startup script and all.



In OctoPrint Settings, select "Webcam" and enter the stream URLs:

OctoPrint webcam settings



Enter the following URLs:

Stream URL: http://{Raspberry Pi IP address}:8080/?action=stream

Snapshot URL: http://{Raspberry Pi IP address}:8080/?action=snapshot



If configured correctly, the print progress streams live in the "Control" tab on the main page:

OctoPrint Control tab with live camera feed



You can also configure FFmpeg to generate a timelapse video of the print — but installing FFmpeg on Raspberry Pi is a bit of a hassle, so that's for another day.





Auto-start on boot



To start OctoPrint automatically when Raspberry Pi boots, create the following init script at /etc/init.d/octoprint:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          octoprint
# Required-Start:    $local_fs $remote_fs $network $syslog $named mjpg
# Required-Stop:     $local_fs $remote_fs $network $syslog $named mjpg
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

OCTOPRINT_HOME=/home/pi/git/OctoPrint

case "$1" in
start)
/usr/bin/sudo -u pi $OCTOPRINT_HOME/run --daemon start
;;
stop)
/usr/bin/sudo -u pi $OCTOPRINT_HOME/run --daemon stop
;;
restart)
/usr/bin/sudo -u pi $OCTOPRINT_HOME/run --daemon stop
/usr/bin/sudo -u pi $OCTOPRINT_HOME/run --daemon start
;;
esac

exit 0

The "mjpg" at the end of lines 4 and 5 refers to the Provides name of the mjpg-streamer startup script.

See the earlier post for the mjpg-streamer startup script.



Register the scripts to run at boot:

$ sudo -s
# apt-get install chkconfig
# chkconfig -add mjpg
# update-rc.d mjpg defaults
# chkconfig -add octoprint
# update-rc.d octoprint defaults
# ls /etc/rc5.d/*octoprint
/etc/rc5.d/S04octoprint
# ls /etc/rc5.d/*mjpg
/etc/rc5.d/S03mjpg
# reboot

mjpg starts before octoprint as intended.

These could be combined into a single startup script, but keeping them separate feels more Linux-like — each service can be started and stopped independently.





Done



By the time I finished writing this, the print had finished.

The light on the left is the microscope; the Raspberry Pi in the bottom right is the controller:

Completed Wi-Fi 3D printer setup with microscope and Raspberry Pi



The finished object — a lens cap holder for the camera. Perfect fit:

3D printed lens cap holder, perfect fit

No comments:

Post a Comment