OctoPrint on a Galaxy S6

Why?

I was quite happy with the performance and print quality I was able to get out of my 3D printer, a Monoprice Select Mini. With my print settings dialed in, I was ready to move on to getting my 3D printer to run a bit more independently. This led me to find OctoPrint, a convenient remote control and monitoring software that can run on various platforms.

Ideally, OctoPrint would be installed on a Linux-based single board computer like a Raspberry Pi. Unfortunately, I had no Pi, but I did have a possible alternative: a Samsung Galaxy S6.

"close enough" meme

☑ Can run compatible OS (Debian)
☑ USB input (via USB OTG)
☑ 2.4GHz & 5GHz WiFi
☑ Internal 32GB storage

After a weekend of reading countless wikis, blogs, XDA threads, and Reddit posts, I finally got it all working. My S6 was running OctoPrint and controlling my 3D printer as it printed various items, with barely any problems.

Getting this to work involved using information from numerous sources, and a lot of trial and error with different applications and settings.

s3 connection diagram

Originally, I did this project with a Galaxy S3 and it was functioning fine, but I ran into a power problem. I couldn’t find a USB OTG cable that would allow me to keep the S3 charged while connected to a 3D printer.

I had the same problem with a Galaxy S6, but since I already had a wireless charger for it, I decided to switch to the S6.

I wrote this guide to try and consolidate all the information it takes to turn a stock S6 into a functional 3D printer server.


How

Rooting your phone exposes system files and increase the chances of accidentally deleting them, bricking your device. Differences in firmware/program versions may cause unexpected errors during installation/use. You should have a general understanding of what you’re doing and proceed with caution.

1 – If you rooted your S6 before, it’s recommended to start fresh by flashing the stock firmware to minimize any conflicts with past root configurations.
⦿ How to restore S6 to stock (YouTube) or text version
⦿ S6 firmware (all variants)
⦿ Latest Odin software

2 – Root the phone by following the guide linked here.

3 – Make sure you’re connected to a WiFi network and open Google Play, install Linux Deploy, and then BusyBox. Open BusyBox and tap “INSTALL”, then “OK” on the pop up to confirm, and finally approve the “Superuser Request” for BusyBox.

4 – Open Linux Deploy. Notice there are multiple menu buttons for settings in the app. I’ve named each one below for the purpose of this guide.

Linux Deploy menus

-Upper left button = Main menu
-Upper right button = Tools menu
-Lower right button = Properties menu


5 – Go to Main menu > Settings, and check the boxes for Lock screen, Lock Wi-Fi, and Wake lock. Scroll down to “Environment” and tap “Remove ENV” and then “Update ENV”. Restart the device.

6 – Open Linux Deploy again and go to the Properties Menu. Use the settings below:
BOOTSTRAP:
⦿ Distribution: Debian
⦿ Architecture: arm64
⦿ Distribution suite: stretch
⦿ Install type: File
⦿ Install path: ${EXTERNAL_STORAGE}/debian.img
~${EXTERNAL_STORAGE} = /sdcard
⦿ Image size (MB): 4000
~Creating an img larger than 4095 MB will cause errors on creation, but you can always expand it later using a few shell commands.
⦿ File system: ext4
⦿ User name: Any_Username
⦿ User password: Strong_Password
⦿ Localisation: en_US.UTF-8
~This is for English (US). You can change the language by using this table of language codes to find the correct language code to select.
INIT:
⦿ Enable: Enabled
⦿ System: sysv
⦿ Settings Async: Enabled
MOUNTS:
⦿ Enable: Enabled
⦿ Mount points: Source /sdcard Target: /sdcard
SSH:
⦿ Enable: Enabled

7 – Go back to the Linux Deploy home screen, tap Tools menu > Install, and approve the “Superuser Request” for Linux Deploy. This will take about 10 minutes to install, and will end with “<<< deploy” as the last line in the output on the screen. Tap “▶ START” then “OK” to run the Debian system.

8 – Open Google Play and install the SSH client ConnectBot

9 – Tap the “+” button to add a host. Change the following settings:
⦿ Protocol: local
⦿ Nickname: Local host (or whatever you like)
Tap “+” in the upper right to save the new host.

10 – Tap on the host you just created. This opens a local shell in the Android environment. To open a root shell in the Debian system, run the following commands, approving the “Superuser Request” for ConnectBot when it pops up.

su root
/data/data/ru.meefik.linuxdeploy/files/bin/linuxdeploy shell

~Due to the way Android’s SELinux policy is set up on the S6, you can’t use sudo as a standard user or use root over SSH unless you flash a custom ROM to your device. This is documented in Linux Deploy’s GitHub

11 – Run the following commands to update the package lists and system. Tap the “y” key then “enter” key when asked about to approve the additional space the upgrade will use. It’s also possible that there are no updates.

apt update
apt upgrade

12 – Now to install some basic programs OctoPrint will require. Tap the “y” key then “enter” key to approve the additional space the installs will use.

apt install python2.7
apt install python-pip python-dev python-setuptools python-virtualenv git libyaml-dev build-essential

13 – When the install finishes, type exit and tap the enter key. Return to Linux Deploy and tap “◼ STOP” then “OK” to stop the Debian system. Restart the phone. Reopen Linux Deploy and tap “▶ START”.

14 – Now we can work from the standard user account instead of the root account. There are two ways to connect:
~Note: Use the same username and password set in Linux Deploy’s Properties menu in Step 6 to log in.

– ConnectBot on phone: Create a new host and use the following settings:
⦿ Protocol: ssh
⦿ username@hostname:port: YOUR_USER_HERE@localhost
⦿ Nickname: any nickname

– SSH from computer: Using an SSH client from a computer gives the advantage of working with a bigger screen/keyboard. To connect, just use the IP address at the top of Linux Deploy, and the port number that was set in the Properties menu (default is 22). Log in with the Debian username/password created earlier.


15 – Logging in using your SSH client of choice, you’ll be in your home directory. The commands below will make a virtual environment called venv in that directory, activate it, and then upgrade pip if necessary before installing the latest OctoPrint. The virtual environment is turned off with deactivate. (Source: Basic setup)

virtualenv venv
source venv/bin/activate
pip install pip --upgrade
pip install https://get.octoprint.org/latest
deactivate

16 – Now, we can finally start OctoPrint by running the command below.

~/venv/bin/octoprint daemon start

17 – To access OctoPrint, open a web browser and type in the device IP and default port 5000 like this: DeviceIP:5000
Go through the “Setup Wizard” and be sure to set a secure username and password under “Access Control”. Leave “Server Commands” blank as none of the standard commands work (for now).

18 – Now, just use a USB On-The-Go cable to connect your 3D printer to your S6. Take note of any extra options that show up under “Serial Port” after you click the refresh button. That is most likely your 3D printer, select it, but don’t click “Connect” just yet.


19 – For the OctoPrint system to be able to communicate with the 3D printer, we need to change the permissions for where it’s mounted. (This will have to be done each time you reconnect the 3D printer to the S6)
Open ConnectBot and open the local shell for the Android environment.
Run su root and then the command below that matches the “Serial Port” selected in OctoPrint.

chmod 666 /dev/ttyACM0

chmod 666 /dev/ttyUSB0

20 – Click “Connect” and you’re ready to start printing! You can view the active communication with your printer under the “Terminal” tab. To stop and restart the OctoPrint server, use one of the following commands through the command line:

~/venv/bin/octoprint daemon stop

~/venv/bin/octoprint daemon restart

~If your printer doesn’t connect, try changing the “Baudrate” (115200 usually works), or change the “Serial Port” and its corresponding permissions.
Some Malyan/Monoprice printers have a known issue connecting with OctoPrint, but there’s a plugin with a fix with more info as well.


Add Autostart

To further automate our new OctoPrint server, we’ll enable it to start automatically when Debian starts in Linux Deploy. In addition, Linux Deploy can also start on Android boot up.

1 – Make sure the OctoPrint server isn’t running.

~/venv/bin/octoprint daemon stop

2 – Open ConnectBot and pick the localhost, open a root shell into the Debian system.

su root
/data/data/ru.meefik.linuxdeploy/files/bin/linuxdeploy shell

3 – The following commands will download 2 scripts (octoprint.init and octoprint.default) into the current directory, then moves and renames them into their appropriate directories.
These 2 files tell the init system how to run OctoPrint at boot. (Helpful source)

wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init && sudo mv octoprint.init /etc/init.d/octoprint
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default && sudo mv octoprint.default /etc/default/octoprint

4 – To get these files to work on the system, a few lines will need to be edited. Using the built in text editor vi, open the first file from the last step.

vi /etc/init.d/octoprint

OctoPrint doesn’t have write access to the default location, so the line for PIDFILE needs to be edited so it looks like the one below:

PIDFILE=/home/YOURUSERNAMEHERE/.octoprint/$PKGNAME.pid

5 – Use vi to edit the second downloaded file:

vi /etc/default/octoprint

Change the following lines according to your paths and username:

OCTOPRINT_USER=your_username

CONFIGFILE=/home/your_username/.octoprint/config.yaml

DAEMON=/home/your_username/venv/bin/octoprint

Save and close the second file.

6 – Set the appropriate permissions for the last two files

chmod 755 /etc/init.d/octoprint
chmod 644 /etc/default/octoprint

7 – This activates the 2 added files so OctoPrint will now run on Debian start up:

update-rc.d octoprint defaults

8 – The final part: get Debian to start automatically when Android boots up. Open Linux Deploy -> Main menu -> Settings. Enable Autostart, and set Autostart delay to 5. Now restart the phone and watch OctoPrint become available in your browser as your phone boots up.
~You may need to increase your Autostart delay to 10 if SSH isn’t working right, or OctoPrint failed, or something else. This is experimental after all.

9 – OctoPrint can now restart itself through the web interface button. Open Settings, look under Server. Enter the command below for the Restart OctoPrint field:

/etc/init.d/octoprint restart

Enjoy your new OctoPrint server! 😀






Useful shell commands

Here are some useful shell commands that you may use repeatedly when working with the Android and Debian system.

⦿ Remount /system (or other directory) as {Read|Write} or {Read Only}

mount -o rw,remount /system

mount -o ro,remount /system

⦿ Access root shell for Linux system faster: Save yourself from typing out:
/data/data/ru/meefik/linuxdeploy/files/bin/linuxdeploy CMDS-HERE
and just type:
linuxdeploy CMDS-HERE

mount -o rw,remount /system
ln -s /data/data/ru.meefik.linuxdeploy/files/bin/linuxdeploy /system/xbin/linuxdeploy
mount -o ro,remount /system

⦿ Increase size of Linux .img by PICK_SIZE in megabytes (Source)

dd if=/dev/zero bs=1048576 count=PICK_SIZE >> /path/to/your/linux.img
e2fsck -f /path/to/your/linux.img
resize2fs /path/to/your/linux.img

⦿ Start/Stop Linux distro w/services from shell

/data/data/ru.meefik.linuxdeploy/files/bin/linuxdeploy start -m

/data/data/ru.meefik.linuxdeploy/files/bin/linuxdeploy stop -u

⦿ Open shell into Linux distro as root user

/data/data/ru.meefik.linuxdeploy/files/bin/linuxdeploy shell

⦿ Refresh info on latest available packages and versions, but doesn’t install anything

apt update

⦿ Install newer versions of installed packages

apt upgrade

Leave a Reply

Your email address will not be published. Required fields are marked *