Presentation

RaspZero

The Zero like the A and A+ has only one USB port, directly connected to the processor (OTG). Raspberry foundation make easy the use of this OTG port like an ethernet port, serial port, etc…​ We are going to see in this tutorial based on the excellent work of Andrew ‘gbaman’ how to configure the pi Zero.

Modules included:

  • Serial (g_serial)

  • Ethernet (g_ether)

  • Mass storage (g_mass_storage)

  • MIDI (g_midi)

  • Audio (g_audio)

  • Keyboard/Mouse (g_hid)

  • Mass storage and Serial (g_acm_ms)

  • Ethernet and Serial (g_cdc)

  • Multi (g_multi) - Allow to use two in Ethernet, Mass storage and Serial

Few others, less useful are included:

  • Webcam (g_webcam)

  • Printer (g_printer)

  • Gadget tester (g_zero)

Setup

  • Installation of classic Raspbian Jessie (full) disturb on the SD card

  • Start the Raspberry and resize the root partition (the digest one, usually in ext4 format) so it use all of the storage

Ouvrir un terminal et entrer:

$ sudo raspi-config

Select expand and reboot

  • Once booted open the terminal and download additional modules

$ sudo BRANCH=next rpi-update
Note
Two easy way to connect the Zero to internet. Use a USB-Ethernet hub, or use the internet sharing of a smartphone via usb. And if you don’t have any USB hub, you just can switch between keyboard and (smartphone or ethernet USB) by using the following command to give you enough time to switch and download sudo sleep 15 && BRANCH=next rpi-update.
  • Now we want the raspberry to enable the modules on the usb at the boot

$ echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt

or nano /boot/config.txt and write at the end dtoverlay=dwc2

  • And enable it for Raspbian

$ echo "dwc2" | sudo tee -a /etc/modules

or nano /etc/modules and write at the end dwc2

  • Last step, choose on of the modules of the list. For exemple ethernet:

$ echo "g_ether" | sudo tee -a /etc/modules

or $ nano /etc/modules and write at the end g_ether

And now ?

Now I’m going to show you how to configure the g_ether module to open a ssh connexion with the pi and how to share your internet connexion with the pi.

SSH

We need to configure the network, so the pi automatically get an IP address when connected to the laptop.

First we need to edit the network interfaces file:

$ sudo nano /etc/network/interfaces

complete the line with auto lo like this

auto lo usb0

and add this one at the end

allow-hotplug usb0
iface usb0 inet manual

the file should look like this:

networkinterfaces

Now just poweroff the pi and plug it to your laptop. You should see in your network application that the pi appear as a USB Gadget.

Just configure manually its IP address with a local address 192.168.2.1 and the mask 255.255.255.0 and apply, the result should be like this

osxnetwork

Now you should be able to ssh using:

$ ssh pi@raspberry.local
Note
If you didn’t change it in raspi-config, the default password of user pi is raspberry.

Internet sharing

Let’s share the wifi connexion of the laptop to the raspberry. The setup is easy on OS X.

Juste go in System Preferences > Sharing and tip internet sharing, select connexion from Wi-Fi and to the device Ethernet Gadget

sharing

That’s it, you should now be able to ping google from your ssh connexion

ping

X Forwarding

Let’s now use our laptop as the pi’s monitor.

You need a X11 application: XQuartz, for mac.

xquartz

Then ssh your pi with the option -X or -Y (only trusted X11 forwarding) to allow GUI via ssh

ssh -Y pi@raspberrypi.local

You need to disable the access control, so clients are allowed to connect from any host. Otherwise, the first time the operation may fail, with a warning:

(lxsession:xxxx): Gtk-WARNING **: cannot open display:
Note
more help on this error here

so just disable the access control

$ xhost +

and make sure X11 forwarding is enabled.

$ sudo nano /etc/ssh/sshd_config

make sure you see

X11Forwarding yes

Now everything is set you can start the GUI

$ startlxde
screen

ctrl+Alt+A to disable full screen mode

osx