Sunday, October 23, 2016

Qidi Avatar IV, OrangePi Lite and OctoPrint

Pre-condition: I have configured a user named 'user' with the home folder '/home/user', and I'm running on armbian 3.4.112 (see previous post for the setup).

Installation of OctoPrint
Here are a bunch of commands to install python and python-dev (it should work with apt-get, but at the time of writing some libs with the right version are missing in the repositoy, and I couldn't get it using exact this version)
---cut here begin---
cd /home/user/

wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/python2.7-dev_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/python2.7_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python-defaults/libpython-stdlib_2.7.9-1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/python2.7-minimal_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python-defaults/python-minimal_2.7.9-1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python-defaults/python_2.7.9-1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/libpython2.7-minimal_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/libpython2.7-stdlib_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/libpython2.7_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/e/expat/libexpat1-dev_2.1.0-6+deb8u3_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/g/glibc/multiarch-support_2.19-18+deb8u6_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python2.7/libpython2.7-dev_2.7.9-2+deb8u1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python-defaults/libpython-dev_2.7.9-1_armhf.deb
wget http://ftp.us.debian.org/debian/pool/main/p/python-defaults/python-dev_2.7.9-1_armhf.deb

dpkg -i libpython2.7-minimal_2.7.9-2+deb8u1_armhf.deb
dpkg -i libpython2.7-stdlib_2.7.9-2+deb8u1_armhf.deb
dpkg -i multiarch-support_2.19-18+deb8u6_armhf.deb
dpkg -i libpython2.7_2.7.9-2+deb8u1_armhf.deb
dpkg -i libexpat1-dev_2.1.0-6+deb8u3_armhf.deb
dpkg -i libpython2.7-dev_2.7.9-2+deb8u1_armhf.deb
dpkg -i libpython-dev_2.7.9-1_armhf.deb
dpkg -i python2.7-minimal_2.7.9-2+deb8u1_armhf.deb
dpkg -i python-minimal_2.7.9-1_armhf.deb
dpkg -i libpython-stdlib_2.7.9-1_armhf.deb
dpkg -i python2.7_2.7.9-2+deb8u1_armhf.deb
dpkg -i python_2.7.9-1_armhf.deb
dpkg -i python2.7-dev_2.7.9-2+deb8u1_armhf.deb
dpkg -i python-dev_2.7.9-1_armhf.deb
rm *.deb
---cut here end---

Installation of additional packages, set of user permissions and initial run of OctoPrint:
---cut here begin---
apt-get install python-pip python-setuptools python-virtualenv git libyaml-dev build-essential
apt-get autoremove
pip install virtualenv --upgrade
usermod -a -G tty user
usermod -a -G dialout user

su - user
git clone https://github.com/foosel/OctoPrint.git
cd OctoPrint
virtualenv venv
./venv/bin/python setup.py install
 /home/user/OctoPrint/venv/bin/octoprint
---cut here end---

Additional configuration
The OctoPrint server will start on port 5000, in my case it is 'http://192.168.0.5:5000'. Setup username and password, then login.
For the Qidi Avatar (or Makerbot or any Makerbot clone) follow these steps (as the serial port doesn't understand the standard G-code but only a binary language called x3g):
Go to 'Settings', 'Plugin Manager', get to 'Get more...' plugins and search for 'GPX' in order to install the GPX plugin.
Go to 'Setting', select the 'GPX' plugin and select your printer, for the Qidi Avatar IV it's the 'Replicator 1 - dual extruder', this will create the file '/home/user/.octoprint/data/GPX/gpx.ini'.

Go to 'Settings, 'Printer profile', click on edit and adjust the profile, for the Qidi Avatar IV:
Model: Qidi Avatar IV
Origin: Center
Volume X: 230mm
Volume Y: 145mm
Volume Z: 150mm
Number of Extruders: 2


Connect the OrangePi with an USB cable to your printer, and set the serial port name and speed. For the Qidi Avatar it is '/dev/ttyACM0' with a baudrate of '115200'. (You can check the name of the serial ports availabe over the ssh session, type 'dmesg | grep tty' to get the name of the serial port).

Autostart OctoPrint

Edit the file '/home/user/OctoPrint/scripts/octoprint.init', adjusting 'DEAMON':

DAEMON=/home/user/OctoPrint/venv/bin/octoprint

Edit the file '/home/user/OctoPrint/scripts/octoprint.default', adjusting 'OCTOPRINT_USER' and 'DEAMON':
OCTOPRINT_USER=user
DAEMON=/home/user/OctoPrint/venv/bin/octoprint

Copy these two files to the standard startup directories and automatic startup for OctoPrint:
---cut here begin---
cp /home/user/OctoPrint/scripts/octoprint.init /etc/init.d/octoprint
chmod +x /etc/init.d/octoprint
cp /home/user/OctoPrint/scripts/octoprint.default /etc/default/octoprint
update-rc.d octoprint defaults
---cut here end---

To manually start, restart, stop OctoPrint simply execute:
---cut here begin---
 service octoprint start
service octoprint restart
service octoprint stop
---cut here end---

Printing
Upload a G-code file to octoprint and then print it.

Note:
The Qidi Avatar (and other Makerbot clones) can't read or write to the SD card, due to firmware limitations. Therefore it is not possible to upload or download files on the SD card.
It should be possible to print x3g files directly from the SD card, but you won't be able to see any progress indicator and you won't be able to visualize the G-code as there's none. I didn't try this, I prefer handling G-code files over x3g, and I prefer a wireless web-interface over for printing over physical knobs.

Saturday, October 22, 2016

OrangePi Lite - armbian wifi/wlan setup

Orange Pi Lite:
While not listed on www.orangepi.org/ it is available on www.aliexpress.com/ for $14.44 incl. shipping.

I selected this model because it has build-in Wifi. I don't have an network cable at the printer and therefore I will use Wifi.

Armbian:
Availabe at www.armbian.com/ as desktop or server version, I selected the server version without X server.
Version used: Armbian_5.20_Orangepilite_Debian_jessie_3.4.112.7z

Initial setup:
Download the armbian image archive and write the unpacked image to a microSD card (I used Etcher www.etcher.io to write the image). Then put the card into the orangepi, connect a usb keyboard and a HDMI display, and power it up.
It will show a boot prompt shortly, do not log in! armbian is setting up disk size and a swap partition in the background, you'll have to wait a few minutes (depending on the microSD card speed) until it reboots. Then you can log in as root with the password 1234. It will promt you to change the root password and to set up an additional user. I selected the login name 'user'.

Wifi setup:
The first thing you might want to setup if Wifi, and then you can do all further configuration over ssh, and it has quite a few steps, in my case the SSID in named 'mySSIDhere', just replace it with yours:
Test if the wlan adapter is working at all:
root@orangepilite:~# iw dev
 phy#0
     Interface wlan0
         ifindex 3
         type managed
 root@orangepilite:~# 
Set your country specific WLAN profile (for the UK it's GB, as in this example). A list of all country codes is at the time of writing available at en.wikipedia.org/wiki/ISO_3166-1_alpha-2 - otherwise google for ' ISO / IEC 3166 alpha2 country code' (replace with your country code):
root@orangepilite:~# iw reg set GB

Bring the adapter up:
root@orangepilite:~# ip link set dev wlan0 up 
Scan for access points (without the grep it will display a lot more info):
root@orangepilite:~# iw dev wlan0 scan | grep SSID
     SSID: mySSIDhere
If your access point isn't using encryption you can connect already:
root@orangepilite:~# iw dev wlan0 connect mySSIDhere 
Check a few times until the connection is there, either it says 'Not connected' or it shows an info like this:
root@orangepilite:~# iw dev wlan0 link
 Connected to 00:00:00:00:00:00 (on wlan0)
     SSID: mySSIDhere
     freq: 2472
     signal: -72 dBm
     tx bitrate: 150.0 MBit/s
 root@orangepilite:~#
Get an IP addresss over DHCP (I'm assuming you're using DHCP on your Wifi network, as most users do):
root@orangepilite:~# dhclient -v wlan0 


If your access point is configured with WPA it's a little bit more complicated, replace myPasswordHere with the actual password:
root@orangepilite:~# wpa_passphrase mySSIDhere myPasswordHere >/root/wpa.conf
 
   root@orangepilite:~# cat /root/wpa.conf
   network={
       ssid="mySSIDhere"
       #psk="myPasswordHere"
       psk=04817c03bb5fd9d1c6d561a881f192da77501b47d0ac80598eb44191c603c516
   }
   root@orangepilite:~#  
 Check a few times until the connection is there, either it says 'Not connected' or it shows an info like this:
root@orangepilite:~# iw dev wlan0 link
   Connected to 00:00:00:00:00:00 (on wlan0)
       SSID: mySSIDhere
       freq: 2472
       signal: -72 dBm
       tx bitrate: 150.0 MBit/s
   root@orangepilite:~#
Get an IP addresss over DHCP (I'm assuming you're using DHCP on your Wifi network, as most users do):
root@orangepilite:~# dhclient -v wlan0 


Now it's time to test if ssh is working, figure out your ip address with ifconfig and test ssh. I got IP address 192.168.0.5 and connected with it:
ifconfig wlan0 
 wlan0 Link encap:Ethernet HWaddr 00:00:00:00:00:00 
 inet addr:192.168.0.5 Bcast:192.168.0.255 Mask:255.255.255.0 
 [...] 
  
 root@orangepilite:~# ssh 192.168.0.5 
 root@192.168.1.108's password: 

  ___                               ____  _   _     _ _
 / _ \ _ __ __ _ _ __   __ _  ___  |  _ \(_) | |   (_) |_ ___
| | | | '__/ _` | '_ \ / _` |/ _ \ | |_) | | | |   | | __/ _ \
| |_| | | | (_| | | | | (_| |  __/ |  __/| | | |___| | ||  __/
 \___/|_|  \__,_|_| |_|\__, |\___| |_|   |_| |_____|_|\__\___|
                       |___/
  
 Welcome to ARMBIAN Debian GNU/Linux 8 (jessie) 3.4.112-sun8i 
 System load: 0.02 Up time: 2 hours Local users: 3 
 Memory usage: 12 % of 494Mb IP: 192.168.1.108 
 CPU temp: 61°C 
 Usage of /: 9% of 15G 
  
 root@orangepilite:~#

Now you can switch to your PC and connect with ssh (on Windows you can use putty (free, www.putty.org), MobaXter (free for personal use, mobaxterm.mobatek.net), SecureCRT ($99, www.vandyke.com) or any other ssh client).

The most important thing is to write the Wifi settings into the configuration file '/etc/network/interfaces', so here it goes (without the use of editors like vi or nano). :
root@orangepilite:~# cat /root/wpa.conf
network={
        ssid="mySSIDhere"
        #psk="myPasswordHere"
        psk=04817c03bb5fd9d1c6d561a881f192da77501b47d0ac80598eb44191c603c516
}
Prepare a text document that you can easily copy and paste with the following contents (replacing the text behind wpa-ssid and wpa-psk with the values from your '/root/wpa.conf':
echo "# Local loopback
auto lo
iface lo inet loopback

# Wlan

auto wlan0
iface wlan0 inet dhcp
        wpa-ssid        mySSIDhere
        wpa-psk         04817c03bb5fd9d1c6d561a881f192da77501b47d0ac80598eb44191c603c516
" > /etc/network/interfaces
Then select it all, copy it and paste it over to your ssh session:
root@orangepilite:~# echo "# Local loopback
auto lo
iface lo inet loopback

# Wlan
auto wlan0

iface wlan0 inet dhcp
        wpa-ssid        mySSIDhere
        wpa-psk         04817c03bb5fd9d1c6d561a881f192da77501b47d0ac80598eb44191c603c516" > /etc/network/interfaces
root@orangepilite:~#

The county code is to be written to a config file '/etc/default/crda' as well, so here it goes (replace with your country code):
 root@orangepilite:~# echo "REGDOMAIN=GB" > /etc/default/crda

All config files are written, so it's time to reboot in order to test it:
root@orangepilite:~# sync
root@orangepilite:~# reboot
If you didn't make any errors you can connect with ssh to the orangepi after this reboot.