Most Recent


Octoprint on Android (Galaxy S3) - Ender 3 (Pro)

I have read "installing octoprint on a smartphone" on reddit and decided to do it. Here is my documentation about how to install Octoprint on an Android-Phone (Galaxy S3) 

Lineageos Based ROM with Root
First of all you need a phone that is rooted, twrp installed and preferably with lineageos based rom (i will explain how to edit  kernel). I will be telling it for samsung galaxy s3 but it should be generally applicable to any android phone:

Kernel Driver Support to Connect to Ender
For any rom, if you want to connect it to Ender 3, you need "ch341" driver added/activated in the kernel. You could understand it by connecting the phone with a USB OTG cable to your printer and execute command "ls /dev | grep tty". If "ttyusb" is seen kernel has the driver, otherwise you need to compile a kernel with driver support. Also keep in mind that kernel needs to support "loopback" functionality to host a virtual linux system and accept/direct connections to that virtual linux over its loopback.

Compiling Kernel
So i searched for Lineage os based 7.x kernels on github and found a one with "ch341" driver already included in its folders. 
Good part is that this kernel supports many phones, loopback and usb audio/dock station mode. You need a linux environment to compile kernel (might be possible on windows too). First you need to download the kernel and a toolchain (Google) to compile it. 

We need programs/files listed below: 
  • AIK KITCHEN folder (to split and merge new kernel into boot.img file) 
  • arm-eabi folder (google toolchain to compile kernel) 
  • Kernel folder (new kernel source code)
  • boot.img file (we will replace the kernel in this original image file taken from firm zip file) 
1. Installing prerequisites 
sudo apt-get install libncurses5 libncurses5-dev
sudo apt-get install make
sudo apt-get install git

2. Install google toolchain

cd /home/ercin
git clone 

3. Download Android image kitchen  and extract it to a folder. (/home/ercin/Downloads/AIK-Linux)

4. Download CrDroid rom and extract boot.img file

At the end you will have a Download folder  with folders and images like below: 

5. Edit kernel configuration file to include ch341 driver

6. Compile New Kernel
export ARCH=arm
export SUBARCH=arm
export CROSS_COMPILE=/home/ercin/Downloads/arm-eabi-4.8/arm-eabi-
cd /home/ercin/Downloads/elite-boeffla-kernel-lineage14.1-i9300-master/
make clean
make mrproper
make lineageos_i9300_defconfig
make -j$(nproc --all)
7.Now you have the kernel with name Zimage under arch/arm/boot folder: 
8. Unpack boot.img (taken from crdroid zip file) and change old kernel with newly compiled one. 

cd /home/ercin/Downloads/AIK-Linux/
./ /home/ercin/Downloads/boot.img 
cd /home/ercin/Downloads/AIK-Linux/split_img/
rm boot.img-zImage
cp  /home/ercin/downloads/elite-boeffla-kernel-lineage14.1-i9300-master/arch/arm/boot/Zimage boot.img-zImage
cd /home/ercin/Downloads/AIK-Linux/

Now you have image-new.img file under folder /home/ercin/Downloads/AIK-Linux

8. Install image-new.img file to phone boot section using TWRP

OTG Cable With Charging 
Even though it is possible to add wireless-charging to galaxy s3 (solder charger pins directly), it also stops charging if you connect a usb device through standart otg cable. 

You need a cable that charges phone and allows for usb functionality at the same time. Some phones support it through dock/audio stations. So it is easy to make a usb otg cable with charging by tricking the phone like it is connected to a station. I used 60k resistor using the diagram below. The only important part when connecting is that power needs to be connected first. I'm not so sure if this cable method works for all phone types. I know that there are kernels that support charging + otg for Nexus 7.

Also cut only the 5V + (red)  cable between the phone and Ender3 for not to power the mainboard of the printer from phone. This way you would be sure that 3dprinter mainboard will be up only if its power supply is up.

If you have not experince in soldering, soldering a microusb is not that easy, so like myself i suggest you to do a otg+charing cable using either a microusb dip or female dupont cables like the one below: 

7/24 Plugged Phone & Battery Health
Since your phone is going to be connected to plug all the time, you need to find a way to stop and start charging at certain levels. Fortunately there is a program for that (on rooted phones if supported) which could stop and restart charging a when it reaches or falls configured levels.

I configured it to %65 and %20 to prolong the battery life to maximum.

Installing Ubuntu  - "Linux Deploy"

Before installing Ubuntu, be sure to have the serial drivers installed (kernel) on the phone, otherwise you will waste too much time.

1. Install Busybox 
Leave folders as default. 

2. Install LinuxDeploy

Newest Ubuntu that i succeded to install is Debian Jessie, since it depends on the Android kernel version of the phone itself. 

3. Open LinuxDeploy and go to settings and check 
  • Lock-wifi
  • Wake lock 
  • Auto-start
  • Track network changes
  • Track power changes
  • Auto-start delay : 60 seconds is enough 
  • Debug : Useful to understand if something goes wrong (like kernel version is old etc.) 

Go to properties menu and and configure below: 
  • Distribution: debian jessie
  • Architecture: armhf
  • Username: pi    (octoprint scripts are for raspberry-pi installation, pi user will make our job easier)
  • Password: your-password 
  • Installation type: file  (default) 
  • Installation path: $(EXTERNAL_STORAGE)/linux.img  (default) 
  • Image Size: 4000 MB
  • enable ssh
  • Init: enabled 
  • Mounts: enabled
  • Mount points: source: /sdcard  target: /sdcard 

Start installation

To eliminate local network problems, first try to connect to linux over the phone itself. ssh to "localhost"

Change root password with command "sudo passwd root" 

Installing Python & Octoprint

Octoprint needs Python 2.7.9 or newer (Debian Jessie 2.7.9 could be installad). If you have a phone with a newer kernel you could install a later version of Ubuntu/debian and you won't need to upgrade system or venv python.) It is better to install latest python version in a virtual-environment and install octoprint in the same venv.(future octoprint version or klipper might need newer python version)  

1.Change user shell from sh to bash, and close and restart your ssh session. 
sudo usermod --shell /bin/bash pi

2. Upgrade ubuntu and install prerequisites 
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential checkinstall -y
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev -y
sudo apt-get install python-pip python-dev python-setuptools python-virtualenv -y
3. Install python 2.7.17 in virtual-environment
Above packages are needed not to face problems later on (python could be make-install without libz2 etc. but then you might face problems like missing modules....) 
sudo apt-get install wget -y
tar xfz Python-2.7.17.tgz
cd Python-2.7.17
sudo ./configure --prefix /usr/local/lib/python2.7.17 --enable-ipv6
sudo make
sudo make install
*if you add  --enable-optimizations to line ./configure   it will add around 30-40 minutes to compiliation but will result in faster python processing. (for galaxy s3 test result was failure)

4. Check python installation 
cd /usr/local/lib/python2.7.17/bin/
./python --version

5. Upgrade PIP (also for virtualenv)
sudo pip install wheel
sudo pip install --upgrade pip virtualenv virtualenvwrapper --ignore-inst

6.Create and enter into virtual env 
cd /home/pi
mkdir venvs
cd venvs/
virtualenv --python=/usr/local/lib/python2.7.17/bin/python octoprint
source /home/pi/venvs/octoprint/bin/activate

7.Check python and pip version inside virtualenv (python 2.7.17, pip 20.x)
python --version
pip install --upgrade pip 
pip install --upgrade setuptools
pip --version
8. Install octoprint (inside venv)
pip install wheel
pip install octoprint
8. Start octoprint
/root/venvs/python2717/bin/octoprint serve

Start Octoprint On Debian Boot Automatically
Download necessary script files: 
wget && sudo mv octoprint.init /etc/init.d/octoprint
wget && sudo mv octoprint.default /etc/default/octoprint
sudo chmod +x /etc/init.d/octoprint
Change the daemon path in "/etc/default/octoprint" file with vi/nano (whatever text editor is your favorite) to: 
sudo nano 

Screen Off - Sleep Problems
For an always on Linux installation on Android, some battery and cpu optimization settings need to be changed otherwise Linux becomes unreachable when screen is of after a while: 

1. Change wifi settings to "keep wifi always on" 

2. Install Wake-Lock: Select "Screen_DIM_wake_lock" option for phone not to (deep)sleep when the screen is off. 

3. Change Battery Settings: Disable optimization for LinuxDeploy and WakeLock application. 

4. Change minimum cpu frequency: 100Mhz minimum frequency is too low, i changed it to 400Mhz. You could use  SmartPack-Kernel Manager or KernelAuditor. 

Astroprint plugin 
First install missing packages: 
sudo apt-get install libjpeg-dev
Then you could install it Astroprint plugin from octoprint web page.

Restarting Phone Over Octoprint Webpage
Somekev explained it really well in his website, Here it is: 
Octoprint on Android (Galaxy S3) - Ender 3 (Pro) Octoprint on Android (Galaxy S3) - Ender 3 (Pro) Reviewed by Erçin TORUN on 23:25 Rating: 5

No comments:

Powered by Blogger.