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.

1 Like

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

2 Likes

I found it necessary to change the keyboard style after booting up the BPI for the first time, as I couldn't use the "/" key among others. Easiest way was to use
: > sudo dpkg-reconfigure keyboard-configuration

So I was thinking about swapping out my ZeroW plugged into the back of my Prusa i3 MK3S+ and I was wondering if there are any extra steps that I need to do beyond just install OctoPrint, still debating between Raspbian install or DietPi install, to communicate over the GPIO pins properly since they are plugged directly into the Einsy board and not via USB.

As a side note, is there a reason you went with a Ubuntu install versus the Banana Pi provided images for Raspbian Stretch and then just upgrade and install OctoPrint via normal channels?

Also is the external antenna required on these boards because the seller insists that it has an integrated antenna, but every video/article I see with the m2 zero, they are using the external antenna.

I honestly would spend the money on a RPI 4. I used the BPI for quite a while but did have some issues where it locked up and wouldn’t respond in the middle of my print job. I went with Ubuntu because it was more stable than any of the ported RPI images. The RPI images would glitch out and during any module installation like python modules it would lock up. It could have just been the BPI zero I had but who knows. I also ran an external antenna on it. Even being 2 feet away from the router the internal antenna would drop signal.

1 Like

I just love the seamless mounting and communication method of plugging into the back of the Einsy board. I wish there was a more powerful and more reliable sbc in the form factor of the zeroW.

1 Like

Did you or anyone else happen to try converting a ported Raspbian image to Dietpi which ideally would fix any of the oddities with their Raspbian image? Do you think that would be worth doing?

I did not try that. If you can keep it stable it might be worth doing.

So I found this image of Armbian with OctoPrint so I likely will try that out first since the maintainer says that in his experience Armbian images will likely be the most up to date for this board. He also recommended against using Stretch images due to EOL fast approaching and according to the DietPi guys upgrading between major updates, e.g. Stretch to Buster, is generally a no no.

Does anyone know what antenna I need to get for the BPi M2 Zero? I think I got the right one:
https://www.amazon.com/dp/B07QDTXGGJ/ref=cm_sw_r_cp_apa_glc_fabc_W2YAKCJ3WJ9AAYM3ZEYF?_encoding=UTF8&psc=1
But when I tried to install it, it would just not stay in, it appears to be fully seated, but it easily falls out with a small tug. I noticed on the board the connector outer ring has a small gap in it? Is that supposed to be there or did it break when I inserted the antenna?

This is the one I have.

https://www.amazon.com/gp/aw/d/B00V6HY1T2?psc=1&ref=ppx_pop_mob_b_asin_title

Are you positive because the one I linked says it is for the m2 zero and it also states that it is similar to the u.fl cables, but smaller.

I trust you, I just want to double check as I rather get the right one a second time around.

I cannot find the spec from the BPi side as to what connector to use so if anyone has any documentation that specified the type I would appreciate it.

Yep. It’s connected to mine.

1 Like

Thank you so much for the reference, I got a 8dbi antenna with a u.fl connector and it worked perfectly. It is very confusing that the original antenna I posted specifically lists the m2 zero and even reviews mention it working when it is the wrong one.

Does anyone know what the safe operating temperature of the M2 Zero (Allwinner H2+) is? My setup is running about 30C over ambient with a heatsink on the Soc and memory but I am wondering if I need to figure out a exhaust fan for the back of the Einsy Rambo board.

I found the data sheet online, but the max junction temperature was never listed.

That is a quite vague information. If we don't know what your ambient temperature is, we can't say if yes or no.

In fact, absolute values count in this matter. 60°C is acceptable for most SoC. But as it for all semiconductors applies: the lower, the better. Put a small and silent fan above the chips to keep the air moving.

I get that, I was more just giving that as a testament to my current cooling solution more than anything else, the reported SoC temperature ranges from low 40's to mid 70's Celsius.

I just don't get how finding the max junction temperature of a given chip is so difficult. For some reason, the datasheet provided the Storage Temperature and the Ambient Operating Temperature but neither of those are particularly useful as I am guessing Storage Temperature is just non-operational temperature, and the Ambient Operating Temperature does not specify the cooling setup or if there is one at all and having a max of 70C ambient without cooling and while under full load, well that seems super suspect to me.

You can control the gpio pins directly under /sys/class/gpio/

I have a little problem. When i enter the command for flashing, its starting normal on /sdb1 but when it is compressing it wants a sdb12 instead of a sdb1 (witch does not exist) where is the problem?

mint@mint:~/Desktop/bananapi-zero-ubuntu-base-minimal$ sudo ./flash_sdcard_m2z_v2.sh /dev/sdb1
INFO: Umounting /dev/sdb1, please wait...
INFO: Reading partition...
WARN: Flashing /dev/sdb1....
347+1 records in
347+1 records out
355699 bytes (356 kB, 347 KiB) copied, 0.0129055 s, 27.6 MB/s
INFO: Decompressing rootfs to /dev/sdb12, please wait... (takes some time)
mount: /home/mint/Desktop/bananapi-zero-ubuntu-base-minimal/erootfs: special device /dev/sdb12 does not exist.