Serial Connection with the Orange Pi Zero
November 27, 2017
Updated: December 15, 2017
<-Domoticz on the Orange Pi Zero, a First Look --

Something went horribly wrong when I did an update and upgrade of the system on the Orange Pi Zero earlier today. I could no longer connect with the OPiZ. Indeed, it would not even show up as a connected device on the local network. And that was with an Ethernet connection in place.

This seemed like a good occasion to test the debug UART port which is next to the RJ45 connector. At the same time, I could test another CH340G based USB-TTL converter I purchased for next to nothing some time ago. I forget where the device came from but it looks like it is easily obtained from the usual Chinese outlets. The device shows up as

      QinHeng Electronics HL-340 USB-Serial adapter
in the lsusb command.

It was all very simple to connect and the converter performed without problem. codelectron has posted a blog on the subject back in May 2017 with numerous photographs. There is not much to add if you like PuTTY on a Linux box. I don't.

Instead I first tried which I had used with nodeMCU on ESP8266 devices. That was not a good idea, especially when using configuration utilities or other programs that make use of ANSI escape codes to draw on the screen in text mode. Next I tried GNU Screen. If its not already present, it can be installed with the Ubuntu Software Center or with the APT package manager. I suggest installing a configuration file in the home directory that will enable a scroll buffer.

michel@hp:~$ sudo apt-get install screen if necessary ... michel@hp:~$ echo "defscrollback 5000" > .screenrc is 5,000 lines enough?

Plug the converter to a USB port on the desktop computer. Connect the converter to the header pins on the OPiZ which should be disconnected from its power source. We need to know which TTY port is assigned to the USB-TTL converter. Try listing all tty devices. It should show up as ttyUSB0 or something similar. If there are too many similar names in the directory, use dmseg which should show to which port the last ch341-uart converter (or whatever chip your USB-TTL converter is based on) was attached.

michel@hp:~$ ls /dev/tty* ... /dev/tty18 /dev/tty33 /dev/tty49 /dev/tty7 /dev/ttyS20 /dev/ttyS8 /dev/tty19 /dev/tty34 /dev/tty5 /dev/tty8 /dev/ttyS21 /dev/ttyS9 /dev/tty2 /dev/tty35 /dev/tty50 /dev/tty9 /dev/ttyS22 /dev/ttyUSB0 /dev/tty20 /dev/tty36 /dev/tty51 /dev/ttyprintk /dev/ttyS23 ... michel@hp:~$ dmesg | grep tty [ 0.000000] console [tty0] enabled [25490.513501] usb 3-14: ch341-uart converter now attached to ttyUSB0

Now that we know the port, launch screen in the terminal and THEN power up the OPiZ. Be prepared for a lot of text scrolling in the terminal window. You will see the typical Linux boot sequence just as if a physical screen had been connected to the OPiZ.

michel@hp:~$ screen /dev/ttyUSB0 115200 [ 8469.538162] Restarting Linux version 3.4.113-sun8i (root@armbian) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #4 SMP PREEMPT Wed Nov 22 13:45:28 CET 2017 [ 8469.538174] U-Boot SPL 2017.09-armbian (Nov 22 2017 - 16:54:06) DRAM: 512 MiB Trying to boot from MMC1 ... ... lots of mostly incomprehensible messages, as far as I am concerned ... [Ok] Scheduler SCHED_OTHER 0 OpenSSH Server (480) [Ok] Nice 0 [Ok] Affinity 0-3 [Ok] Scheduler SCHED_OTHER 0 [Ok] DietPi-Process Tool | Completed ─────────────────────────────────────── DietPi | 17:39 | Mon 27/11/17 ─────────────────────────────────────── V158 | OrangePi Zero (armv7l) ─────────────────────────────────────── IP Address | ─────────────────────────────────────── Default Login: Username = root Password = dietpi [Ok] NTPD: time sync | Completed Enter Nothing happens until you hit that key Debian GNU/Linux 8 domopiz ttyS0 domopiz login:

If screen complains about permissions, you can change the /dev/ttyUSB0 permissions, but the much better solution is to add yourself (well, you as a user) to the dialout group.

michel@hp:~$ sudo chmod 666 /dev/ttyUSB0 or michel@hp:~$ sudo usermod -a -G dialout michel

To enter scrolling mode in screen press the key combination CtrlA and then the ESC key. The up/down and PageUp/PageDown keys will scroll through the buffer. It is possible to select a region of text with the mouse left button which can then be copied to the system clipboard by clicking on the right mouse button. Press ESC button to exit scrolling mode.

To get out of screen press the key combination CtrlA and then the \ key (with the French AZERTY keyboard on my computer, I produce a "\" with the Alt Gr8 combination).

I tried an old friend Kermit I first encountered in the 1980s. Here is how I installed and then started the program.

michel@hp:~$ sudo apt-get install -y ckermit ... michel@hp:~$ kermit -l /dev/ttyUSB0 -b 115200 -C "set carrier-watch off, connect" Connecting to /dev/ttyUSB0, speed 115200 Escape character: Ctrl-\ (ASCII 28, FS): enabled Type the escape character followed by C to get back, or followed by ? to see other options. ---------------------------------------------------- Enter Nothing happens until you hit that key Debian GNU/Linux 8 domopiz ttyS0 domopiz login:

It is possible to start kermit in interactive mode in which to specify the paramters and then connect

michel@hp:~$ kermit C-Kermit 9.0.302 OPEN SOURCE:, 20 Aug 2011, for Linux+SSL+KRB5 (64-bit) Copyright (C) 1985, 2011, Trustees of Columbia University in the City of New York. Type ? or HELP for help. (/home/michel/) C-Kermit>set line /dev/ttyUSB0 (/home/michel/) C-Kermit>set flow-control none (/home/michel/) C-Kermit>set carrier-watch off (/home/michel/) C-Kermit>set speed 115200 /dev/ttyUSB0, 115200 bps (/home/michel/) C-Kermit>connect

Instead of entering that long convoluted command line, or going through the little interactive session, create a .kermrc initialization file containing the following lines and save it in the home directory.

set line /dev/ttyUSB0 set speed 115200 set flow-control none set carrier-watch off connect

Then launching kermit will automatically connect to the OPiZ.

michel@hp:~$ kermit Connecting to /dev/ttyUSB0, speed 115200 Escape character: Ctrl-\ (ASCII 28, FS): enabled Type the escape character followed by C to get back, or followed by ? to see other options. ---------------------------------------------------- Enter Nothing happens until you hit that key Debian GNU/Linux 8 domopiz ttyS0 domopiz login:

It is a huge program but simpler to use. In particular, the scroll keys work as expected, no need to escape to a command mode. To quit the program, first return to command mode by typing a Ctrl\ combination and then C. Again with an AZERTY keyboard the initial combination is a three key affair CtrlAlt Gr8 to be followed with the single C. In command mode enter the quit command.

If GNU screen and Kermit do not appeal to you then you could try minicom which is what Orange pi recommends. Ultimately, use what you is most comfortable.

No matter which terminal program you use, you may find it much more convenient than opening an ssh session. And best of all you do not need to find the IP address assigned to the Ethernet interface to log in. Indeed, this may be a quicker way of finding the IP address as it is displayed on the logon screen. If you missed it,

dietpi@domopiz:~$ ip addr 1: lo: mtu 16436 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 0b:42:09:fc:73:9c brd ff:ff:ff:ff:ff:ff inet brd scope global eth0 inet6 fd00:fc:8d4f:71b2:8b4:91ff:feff:739c/64 scope global dynamic valid_lft 535418sec preferred_lft 401561sec inet6 2607:fea8:f180:c5a:8b4:91ff:feff:739c/64 scope global dynamic valid_lft 604790sec preferred_lft 172790sec inet6 fe80::8b4:91ff:feff:739c/64 scope link valid_lft forever preferred_lft forever

if ifconfig is not there as is the case in the dietPi version of Armbian.

As for getting ssh to work on my newly upgraded OPiZ... I never did figure it out. I just reloaded a recent backup of my SD card. With Etcher that takes less than 15 minutes, so I was not willing to spend much time investigating the problem. The second time around, upgrading the Armbian image went without a hitch.

NOTE: It might prove impossible to establish a connection with screen or Kermit as shown below.

michel@hp:~$ screen /dev/ttyUSB0 115200 cannot open /dev/ttyUSB0: Device or resource busy or with kermit connecting from the command line michel@hp:~$ kermit -l /dev/ttyUSB0 -b 115200 -C "connect" /dev/ttyUSB0: Device or resource busy or with kermit in interactive mode (/home/michel/) C-Kermit>set line ttyUSB0 Sorry, write access to UUCP lockfile directory denied.

If there is no doubt that /dev/ttyUSB0 is the correct serial port, this may very well be because a process is using it. In my case, a session of screen that I had left hanging when I closed the terminal in which it was running without quitting the program was still connected to the port. To get back control of the port, first the process id (pid) must be obtained and then the process can be killed.

michel@hp:~$ sudo lsof /dev/ttyUSB0 ... lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs Output information may be incomplete. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME screen 15906 michel 7u CHR 188,0 0t0 525 /dev/ttyUSB0 michel@hp:~$ kill 15906

Thank you AppBeing Studio for the information.

WARNING: I am not responsible if you loose all your work because you killed the wrong process because of fat fingers, dyslexia or bad luck. Be careful.

<-Domoticz on the Orange Pi Zero, a First Look --