/!\ Preliminary work in progress

Know How for the Raspberry Pi Zero W

The Raspberry Pi Zero W presentation was presented in February 2017, but the sale is still today (September 2017) limited to just one piece per customer.

There is a good FAQ.

Because it is so small (30 x 65 mm), and cheap (about 11 EUR), it is very attractive to use it in all kinds of embedded computer projects. Also the power consumption is low power, average about 150 mA, but the power supply should have 5 V @ 1.2 A.

The operating software (Debian Linux) Raspbian Stretch with Desktop can be downloaded here and written on a micro SD-card. Debian version Stretch 9 is after 2 years the successor of version Jessie 8.

The main page for Raspberry Pi informations is here.

attachment:RPiZeroW_DSC07436.jpg

I will explain here some Know How on one place.

RPi Zero W

/!\ Handling to do with the micro SD-card - before - you put it in the Raspberry Pi Zero W micro SD-card socket.

/!\ Headless operation means access via SSH over network (Terminal), without connected monitor, keyboard and mouse. In addition a Remote Desktop with VNC (Virtual Network Computing).

/!\ SSH access via USB port: In a German computer magazin c't 20-2017 there is a good explanation how to connect with SSH via USB port. That makes the bootstrapping easier, in case the WLAN access does not work immediately.

Two things must be done, to get wireless access.

For headless setup, the SSH-server must be enabled by placing a file named ssh, without any extension, onto the boot partition (Format FAT32, size = 42 MB) of the SD card. The rest of the micro SD-card is formatted in EXT4. The When the Pi boots, it looks for the ssh file in the boot partition, if it is found, SSH is enabled and then the file is deleted. The content of the file doesn't matter: it could contain either text or nothing at all.

You have to connect the Raspberry Pi Zero W via WLAN to the network. In order to have headless connection, you have to prepare the Raspbian micro SD-card with some configuration. Copy in partition/folder /boot/ the empty file ssh and supply a WLAN configuration file in the same folder. wlan-name (SSID) and secret-password (WLAN password) will be found in your WLAN router.

# Put micro SD-card into computer (PC)
# Enter in Termianal:

# Show what is in folder /media
$ ls /media
# change directory to micro SD-card
$ cd /media/<user>/boot # <user> = your user name

# create empty file
$ touch ssh

# create empty file
$ touch wpa_supplicant.conf
# edit wpa_supplicant.conf (Editor nano)

# File wpa_supplicant.conf in the Boot-Partition
# of the Raspbian micro SD-card
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
       ssid="wlan-name"
       psk="secret-passwort"
}

# put micro SD-card into socket on the Raspberry Pi Zero W
# Power up
# Wait a few minutes, and that the green LED no longer flickers
# Check for boot finished
$ ping raspberrypi
PING raspberrypi.fritz.box (192.168.17.210): 56 data bytes
64 bytes from 192.168.17.210: icmp_seq=0 ttl=64 time=1.321 ms
...
# Stop command ping with Ctrl/Strg C

# Try to login via SSH client or terminal
# in Mac OS terminal (example of 3 year old Raspberry Pi 2):
$ ssh pi@raspberrypi
pi@raspberrypi's password:
Linux raspberrypi 3.10.25+ #622 PREEMPT Fri Jan 3 18:41:00 GMT 2014 armv6l
....

Change host name

The operating software Raspbian has the preset hostname "raspberrypi". If you have just one Raspberry Pi computer in your network, it is OK. But when you fire up the next one, you are in trouble because of a name conflict. As a temporary fix you can unplug the network cable of the other Raspberry Pi.

So, it is wise to rename every Raspberry Pi's hostname after you setup the operating system. Once you have a SSH connection to the Raspberry Pi Zero W you have the choise, type in the Terminal:

# easy method:
$ sudo raspi-config
  2 Hostname

# more difficult:
$ cd /etc

# Edit file "hostname", e.g. raspberrypi -> rpizerow1
$ sudo nano hostname

# Edit file "hosts", e.g. raspberrypi -> rpizerow1
$ sudo nano hosts

# reboot with new hostname
$ sudo shutdown -r now

raspi-config

The shell program raspi-config allows to make the most important system configurations easy. The selected importance here is for Desktop use with VNC. With the key TAB you can jump from field to field.

  1. Change User Password: you should do that, but remember the password at a safe place.

  2. Hostname: You should do that as soon as possible. The WLAN router will show the hostname.

  3. Boot Options: You should select B1 - Desktop-

  4. Localisation Options: If you language is not English you should do that.

  5. Interfacing Options: At a minimum select P3 VNC.

  6. Overclocking: This Pi can not be overclocked.

  7. Advanced Options:

    1. Select A1 Expand Filesystem once on a fresh micro SD-card.

    2. Select A5 Resolution with DMT Mode 16 1024x768 60 Hz 4:3.

  8. Update: Should not be necessary on a fresh install.

  9. About raspi-config: Some information for the use.

VNC server

Virtual Network Computing (VNC) allows you, to show the monitor screen of a remote computer (VNC Server) on a local computer (VNC Client), also to use your local monitor, keyboard and mouse for control of the remote computer. That allows to control a remote computer which does not have its own monitor, keyboard and mouse.

First you have to install on the Raspberry Pi a VNC Server, with raspi-config it is RealVNC.

Now you can establish a connection with a VNC client viewer.

/!\ It may be needed, to append the port number 5901 to the IP address (Real VNC: Connection refused (61))

VNC and Clipboard

Actually in a VNC connection the clipboard does work from Raspberry to Client only.

The other direction can be enabled with the programm autocutsel on the Raspberry Pi:

# Install program to synchronise the clipboard
$ sudo apt-get install autocutsel

# enable auto start
# edit /home/pi/.vnc/xstartup  (Editor nano)
# append at the third line:
autocutsel -fork
xrdb $HOME/.Xresources  # already there
...

# start  "autocutsel"
$ autocutsel -fork
# Now the clipboard copying from VNC client to the Raspberry should work.

VNC and sudo

In the VNC viewer, if you start a program with sudo, you can get an error _tkinter.TclError: couldn't connect to display ":1.0".

The solution is to setup XAUTHORITY, see more about at the links:

$ cd /etc/sudoers.d
# create a new parameter file
$ sudo touch xauthority
# edit file
$ sudo visudo xauthority
# enter the following 5 lines and save to file:
# setup for VNC with sudo
Defaults    env_reset
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults    env_keep += "DISPLAY"
Defaults    env_keep += "XAUTHORITY"

# Add these few lines to ~/.bashrc:

if [ -z "$XAUTHORITY" ]; then
    if [ -e $HOME/.Xauthority ]; then
        export XAUTHORITY=$HOME/.Xauthority;
    fi;
fi

# logout and login again
# Please be care that for entering the password an ENGLISH keyboard is used!
# for password "raspberry" you must type "raspberrz"!

Now it should be possible to start a X-Windows program with sudo.

VNC and Screen Shot

If you like to do a screen shot from your graphic window, type on the command line:

$ scrot -s -d 4

# option "-s" select a window, or a rectangle, with the mouse
# option "-d 4" have a 4 s delay before the screen shot, in order to restore the window
# and read "man scrot"

# result:
$ ls -ls | grep 2014-05-05
   36 -rw-r--r-- 1 pi   pi      33458 Mai  5 14:00 2014-05-05-140020_655x643_scrot.png

Samba Server

In order to exchange easier Files it is advisable to install a Samba Server. We’re going to update our repository index, make sure our operating system is fully updated. The following has to be done in the terminal:

# Update software software repository index
$ sudo apt-get update

# Update the software
$ sudo apt-get upgrade

# Install the software
$ sudo apt-get install samba samba-common-bin

# create share folder in upper file system level
$ sudo mkdir -m 1777 /share
# This command sets the sticky bit (1) to help prevent the directory from being 
# accidentally deleted and gives everyone read/write/execute (777) permissions on it.

$ sudo nano /etc/samba/smb.conf
# append following text:
Comment = Pi shared folder
Path = /share
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes

This means that anyone will be able to read, write, and execute files in the share, either by logging in as a Samba user (which we’ll set up below) or as a guest. If you don’t want to allow guest users, omit the guest ok = yes line.

You could also use Samba to share a user’s home directory so they can access it from elsewhere on the network, or to share a larger external hard disk that lives at a fixed mount point. Just create a smb.conf entry for any path you want to share, and it’ll be made available across your network when you restart Samba.

Before we start the server, you’ll want to set a Samba password for user pi – this must not be the same as your standard default password (raspberry), but there’s no harm in reusing this if you want to, as this is a low-security, local network project.

$ sudo smbpasswd -a pi

Finally let's restart Samba:

$ sudo /etc/init.d/samba restart

From now on, Samba will start automatically whenever you power on your Pi. Once you’ve made sure that you can locate your shared folder on the network, you can safely disconnect the mouse, monitor, and keyboard from your Pi and just leave it running as a headless file server.

You’ll now be able to find your Raspberry Pi file server (named rpizerow1) from any device on your local network. If you’ve left smb.conf’s default settings as they are, it will appear in a Windows network workgroup called WORKGROUP.

GPIO

In order to access the General Purpose Input Output ports (GPIO) there is the library gpio, it is also documented. The benefit is, you do not need root access (sudo) for that. Most I/O pins can have multiple functions. It you want to know what is actually dis-/enabled you can ask for with a utility:

# check version:
$ gpio -v
gpio version: 2.44
Copyright (c) 2012-2017 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
  Type: Pi Zero-W, Revision: 01, Memory: 512MB, Maker: Sony 
  * Device tree is enabled.
  *--> Raspberry Pi Zero W Rev 1.1
  * This Raspberry Pi supports user-level GPIO access.

# show port numbers
$ gpio readall
 +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 1 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |  OUT | 0 | 15 || 16 | 0 | OUT  | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | OUT  | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | OUT  | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Pi ZeroW-+---+------+---------+-----+-----+
BCM = Broadcom SOC channel
wPi = Wiring Raspberry Pi
Mode = I/O mode
Physical = Pin number of 40 pin GPIO connector

Serial Port

Can be enabled via raspi-config on the GPIO pins 8 (TxD) and 10 (RxD), the device name /dev/ttyS0 is used.

The group attribute of ttyS0 is dialout. In order to use that serial port without sudo (root rights) your user (normally pi) must be member of group dialout. This is normally preset. Check with:

$ ls -ls /dev/ttyS0
0 crw-rw---- 1 root dialout 4, 64 Sep 22 20:01 /dev/ttyS0

$ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

If you want to use the serial port from the GPIO plug for Input/Output communication, you have to configure that with raspi-config, in the Terminal.

$ sudo raspi-config

# Select: 5 Interfacing Options
# Select: P6 Serial
# Would you like a login shell to be accessible over serial?
# Select: No
# Would you like the serial port hardware to be enabled?
# Answer: Yes (drawback: you loose GPIO I/O signals 14 and 15)

# Info: The serial login shell is disabled
# Info: The serial interface is enabled 
# Acknowledge with: OK

# Leave raspi-config with select of <Finish>

# Now you can use /dev/serial0 (mapped to /dev/ttyS0) for serial IO

Tipps

  1. Midnight Commander (mc) cheat sheet

  2. Midnight Commander Turorial

  3. VNC with sudo

  4. Install Samba file server

  5. Raspberry Pi, low level peripherals

  6. raspberry-pi-rev2-gpio-pinout, JPG

  7. Raspberry Pi pinout guide, with shields

  8. Raspberry Pi Model B+ 3.5mm Audio/Video Jack

  9. Modell B+ getestet und im Detail erklärt – was ist neu, was ist besser?

  10. USB cable size matters

  11. Micro USB test jig

  12. [RPi3] SSH not working via wifi

Contact Email

/!\ Please insert your Email address, if you like to have an answer.

/!\ Your Email address will NOT be published or shared.

Comment this page
Name:
Comment:
Are you human?

List of pages in this category:

-- RudolfReuter 2017-09-21 09:47:17


Go back to CategoryRaspberryPi or FrontPage

RaspberryPiZeroW (last edited 2017-09-23 20:54:12 by RudolfReuter)