OctoPrint guide for Banana Pi M2 Zero install

Hello. I wanted to share the working steps to get a BPI M2 Zero setup with OctoPrint. There is a decent guide but there were some missing parts that I thought would confuse beginners.
(https://zen3d.hu/banana-pi-m2-zero-octoprint/)

I had a BPI M2 Zero laying around from a project that never took off, so I figured a quad core in a small size would work great for my print server. I will be making a case for it with fan and heat sink since it does get warmer than the RPI zeros. It is pretty decent in performance and is comparable to my RPI 3b I had previously. I also used an 8gb SD card for this project.
You should be able to copy and paste all the commands from here.
Here are the steps as of this posting date:

Use Linux computer for this first part. 
Download or clone the bananapi-zero-ubuntu-base-minimal file from github.
RUN TERMINAL COMMAND: git clone https://github.com/avafinger/bananapi-zero-ubuntu-base-minimal.git

Extract the file to a folder and open terminal to that folder. Mine was cd ~/bananapi-zero-ubuntu-base-minimal

Insert SD card into computer.
Use Disks or other util to find what disk the SD card is. Mine was /dev/sbd.

RUN TERMINAL COMMAND: sudo ./format_sd_mainline. sh /dev/sdb
RUN TERMINAL COMMAND: cat rootfs_kernel_4.17.y.tar.gz. *> rootfs_kernel_4.17.y.tar.gz
RUN TERMINAL COMMAND: sudo ./flash_sdcard_m2z_v2.sh /dev/sdb
Eject the SD card and insert it in again.
Navagate to this folder in file explorer of the rootfs partition  /etc/network/interfaces. You will need to know the exact path to edit that file. Mine was /roofs/etc/network/interfaces.

RUN TERMINAL COMMAND: sudo nano /roofs/etc/network/interfaces
Change the ssid and psk to match your home network, change wireless power to on, CTRL X and save file.

Eject the SD card once again and put in BPI. You will need to hook up a monitor and keyboard to the BPI. Power it up. It will take a bit this first time. Once at the login, use ubuntu, ubuntu.

RUN TERMINAL COMMAND: ifconfig
You should see an ip address in the wlan0 section. Write it down and go on to the next step. If you dont, do sudo shutdown now, take the card out and put it back in your computer and try doing the network/interfaces file again.

On your PC (on the same network as BPI) open terminal.
It is easier to SSH into the BPI and copy and paste these commands.
RUN TERMINAL COMMAND: ssh ubuntu@ipaddress
Use the password ubuntu if prompted, also you may be asked about a passkey, just press Y.

RUN TERMINAL COMMAND: sudo apt update
RUN TERMINAL COMMAND: sudo apt install --reinstall coreutils
RUN TERMINAL COMMAND: sudo apt install --reinstall systemd
RUN TERMINAL COMMAND: sudo reboot
Once back up, SSH into the BPI again.
RUN TERMINAL COMMAND: sudo apt update && sudo apt upgrade

RUN TERMINAL COMMAND: sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget nano

Installing python 3.7:
RUN TERMINAL COMMAND: cd / tmp 
RUN TERMINAL COMMAND: wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tar.xz
RUN TERMINAL COMMAND: tar -xf Python-3.7.7.tar.xz 
RUN TERMINAL COMMAND: cd Python-3.7.7

(This part takes hours to complete)
RUN TERMINAL COMMAND: ./configure --enable-optimizations
RUN TERMINAL COMMAND: make -j 1
RUN TERMINAL COMMAND: sudo make altinstall
RUN TERMINAL COMMAND: check by typing python3. 7 --version

RUN TERMINAL COMMAND: cd / boot
RUN TERMINAL COMMAND: sudo apt install device-tree-compiler
RUN TERMINAL COMMAND: ll bpi-m2-zero. dtb 

RUN TERMINAL COMMAND: sudo dtc -I dtb -O dts -o m2z.dts bpi-m2-zero-v1.dtb_4.17.4-m2z
RUN TERMINAL COMMAND: sudo nano m2z.dts 
RUN TERMINAL COMMAND: sudo dtc -I dts -O dtb -o bpi-m2-zero-v1.dtb_4.17.4-m2z m2z.dts

In nano editor, arrow down and look for settings under serial @ 1c28c00 . Here we need to see a “ status = disabled ” line. This should be rewritten to “ status = okay ”. When done, save the file with CTL X.

RUN TERMINAL COMMAND: sync
RUN TERMINAL COMMAND: sudo shutdown -p now

Power back on and SSH back in again.

RUN TERMINAL COMMAND: sudo apt install python3-virtualenv libyaml-dev
RUN TERMINAL COMMAND: mkdir OctoPrint && cd OctoPrint
RUN TERMINAL COMMAND: python3.7 -m venv venv
RUN TERMINAL COMMAND: source venv/bin/activate
RUN TERMINAL COMMAND: pip3.7 install pip --upgrade
RUN TERMINAL COMMAND: pip3.7 install --default-timeout=100 octoprint
RUN TERMINAL COMMAND: sudo usermod -a -G tty ubuntu
RUN TERMINAL COMMAND: sudo usermod -a -G dialout ubuntu

THIS NEXT COMMAND WILL START THE PROGRAM, let it set it up first, view on web browser at ipaddress:5000, CTL-C to quit in terminal.

RUN TERMINAL COMMAND: /home/ubuntu/OctoPrint/venv/bin/octoprint serve           

RUN TERMINAL COMMAND: cd ~/
RUN TERMINAL COMMAND: sudo wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init
RUN TERMINAL COMMAND: sudo mv octoprint.init /etc/init.d/octoprint

RUN TERMINAL COMMAND: sudo nano /etc/default/octoprint
This should be what you need to paste into that window:

# Configuration for /etc/init.d/octoprint

# The init.d script will only run if this variable non-empty.
OCTOPRINT_USER=ubuntu

# base directory to use
BASEDIR=/home/ubuntu/.octoprint

# configuration file to use
CONFIGFILE=/home/ubuntu/.octoprint/config.yaml

# On what port to run daemon, default is 5000
PORT=5000

# Path to the OctoPrint executable, you need to set this to match your installation!
DAEMON=/home/ubuntu/OctoPrint/venv/bin/octoprint

# What arguments to pass to octoprint, usually no need to touch this
DAEMON_ARGS="--port=$PORT"

# Umask of files octoprint generates, Change this to 000 if running octoprint as its own, separate user
UMASK=022

# Process priority, 0 here will result in a priority 20 process.
# -2 ensures Octoprint has a slight priority over user processes.
NICELEVEL=-2

# Should we run at startup?
START=yes


CTRL x and save.

RUN TERMINAL COMMAND: cd ~/
RUN TERMINAL COMMAND: sudo nano octoprint.service
Paste this in the window:

[Unit]
Description=The snappy web interface for your 3D printer
After=network-online.target
Wants=network-online.target

[Service]
Environment="LC_ALL=C.UTF-8"
Environment="LANG=C.UTF-8"
Type=simple
User=ubuntu
ExecStart=/home/ubuntu/OctoPrint/venv/bin/octoprint serve
Reboot=always
Nice=-2
[Install]
WantedBy=multi-user.target


RUN TERMINAL COMMAND: sudo chmod +x octoprint.service
RUN TERMINAL COMMAND: sudo mv octoprint.service /etc/systemd/system/
RUN TERMINAL COMMAND: sudo update-rc.d octoprint defaults
RUN TERMINAL COMMAND: sudo visudo
Add this below the %sudo line:
ubuntu ALL=NOPASSWD: ALL

CTRL x and save.

RUN TERMINAL COMMAND: cd /~
RUN TERMINAL COMMAND: sudo nano autostart.py
Paste this in the window:

#!/usr/bin/env python
import os
os.system( "sudo service octoprint start")
exit()

CTRL x and save.

RUN TERMINAL COMMAND: sudo chmod+x autostart.py
RUN TERMINAL COMMAND: sudo crontab -e

Add this below the last line:
@reboot sudo python3.7 /home/ubuntu/autostart.py &  

CTRL x and save.

This part is to setup auto login for BPI.
RUN TERMINAL COMMAND: sudo nano /lib/systemmd/system/getty@.service

Scroll down to service section, first part should look like this paste in this info:

[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin ubuntu %I $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes

CTRL x and save

RUN TERMINAL COMMAND: sudo systemctl daemon-reload
RUN TERMINAL COMMAND: sudo reboot

This should reboot and run this command autmatically in the background. sudo service octoprint start. It will take a min for the server to come up on ipaddress:5000.

Add these in octoprint settings web UI under preferences/ server:
Restart OctoPrint: sudo service octoprint restart
Restart system: sudo shutdown -r now
Shutdown system: sudo shutdown -h now

Hope this guide helps someone out!

2 Likes

Good stuff, this should help people. I've moved it over to the guides section so it can be found a bit easier.

Another part I am adding is how to control GPIO with this BPI-M2-ZERO.

I am used to writing code with python for my RPIs but for whatever reason the Allwinner chips do not have great support using WiringPi or RPi-GPIO. I had struggled with this trying to get the correct libraries to create a power on/off script using GPIOs on the BPI to turn on and off my printer through OctoPrint macros.

I tried following the getting started guide http://wiki.banana-pi.org/Getting_Started_with_M2_Zero and installing https://github.com/BPI-SINOVOIP/RPi.GPIO, https://github.com/BPI-SINOVOIP/BPI-WiringPi2.git but once installed python scripts still didn't control GPIO and the gpio readall command didn't look right.

I ended up going an alternate route. I found a library for a sister board, the OrangePi, and gave it a try. https://github.com/zhaolei/WiringOP.git

Now the gpio readall command looked correct (except for now it says OrangePi at the bottom of the gpio readout screen). I still however could not use python to control the GPIO. Next I tried writing the same program in bash. That ended up working!

Here are the steps to get GPIO control working on the BPI-M2-Zero:

Install git if you have not already.
TERMINAL COMMAND: sudo apt install git-all
TERMINAL COMMAND: cd ~/
TERMINAL COMMAND: git clone https://github.com/zhaolei/WiringOP.git -b h3 ^C
TERMINAL COMMAND: cd WiringOP
TERMINAL COMMAND: chmod +x ./build
TERMINAL COMMAND: sudo ./build

This should build the WiringOP library. You can test it with the next command.
TERMINAL COMMAND: gpio readall
It should show a somewhat graphical readout of your GPIO status.
Next lets create the bash scripts to turn off and on GPIO 24.

TERMINAL COMMAND: cd ~/
TERMINAL COMMAND: sudo nano printeron.sh

Paste this into the window:

#!/bin/sh
#This will turn the printer on.
PIN=24
gpio mode $PIN out
gpio write $PIN 1
exit 0


CTRL x and save.

TERMINAL COMMAND: sudo chmod +x printeron.sh

Next we will do the printer off script. 

TERMINAL COMMAND: sudo nano printeron.sh

Paste this into the window:

#!/bin/sh
#This will turn the printer off.
PIN=24
gpio mode $PIN out
gpio write $PIN 0
exit 0

CTRL x and save.


TERMINAL COMMAND: sudo chmod +x printeroff.sh

Now you can control that GPIO by using these commands (in the directory which it was saved):
TERMINAL COMMAND: ./printeron.sh
or 
TERMINAL COMMAND: ./printeroff.sh

Now you can wire up a relay for GPIO control like this one.
GPIO relay

1 Like