Category Archives: Raspberry Pi

Raspberry Pi Zero – Programming over USB! (Part 2)

This is a follow on post from the older, more detailed documentation in an earlier post.

Summary

An extremely simple new way to setup Raspberry Pi Zero as a USB virtual network gadget, allowing SSH, SFTP, VNC etc over a single USB cable. All without need of a keyboard, mouse, screen etc to setup!
To make it clear though, this can only work with the Raspberry Pi Zero.

Quick history lesson

So back over Christmas 2015, I had worked on getting the Raspberry Pi Zero OTG/Slave USB mode working and documented. My work was based off the excelent work done by awesome volunteers from the Raspberry Pi community here and here.
Back then, it required you have a screen, keyboard, mouse and internet connection to set everything up from a stock Raspbian image. This was a bit of a pain if all you had was your normal Windows/Mac/Linux computer with downloaded Raspbian, an SD card, Pi Zero and a USB cable.

Then, with the  2016-05-10 release of Raspbian, the required modules and kernel version were included on the stock Raspbian images, but they still required configuring. At least all this could be done with a screen and keyboard plugged into the Pi Zero (no internet required).

Now, after a heck of a lot of Linux Kernel documentation digging/hunting around, I have stumbled across what seems to be a very little known kernel cmdline parameter. This parameter allows us to do all the configuration on the /boot partition, which is formatted FAT32 and readable on Windows/Mac/Linux (vs normal root partition only being readable with Linux).

What does this mean?

You can now set up a virtual network connection between your Raspberry Pi Zero and normal PC using a single USB cable in a matter of seconds, without the need for any extra hardware!
No need for an HDMI screen, keyboard, mouse etc, all with stock Raspbian Jessie lite or full.
You can then SSH into the Raspberry Pi Zero, copy files with SFTP or use VNC (extra installation required).

How do I set it up?

Setup is super simple! Once you have flashed your Raspbian image, should take only a few minutes to set it up! See guide below.

Big Bang Fair 2016

This year, for the first time I got the opportunity to head over the UK Big Bang Fair in Birmingham. I had been meaning to try and get over for few years, but an opportunity arose this year to help out the Raspberry Pi Foundation so thought, why not.

Breathe on this...
Breathe on this…

What is the UK Big Bang Fair?

Big Bang Fairs are science/tech fairs for school ages kids. They are dotted up and down the UK (sometimes under different names). They are excellent as include exhibitors from industry and also usually include regional heats for the National Science + Engineering Competition. Winners of those heats get invited over the finals at the UK Big Bang Fair in Birmingham in mid March each year.

Over the 4 days the fair was running at the NEC, over 70,000 people came through the doors, most being schoolkids and families.

Space!

I was there from the Thursday-Saturday volunteering with the Raspberry Pi Foundation with Astro Pi on the UK Space Agency stand.

We had set up 4 Raspberry Pis with Sense HATs, 3 of which were set up with the excellent Pixel Art activity, while one was set up with a humidity reading program.

Over the 3 days I was there, we were constantly inundated with kids! Was great to hear 95% of them were well aware who Tim Peake was and they thought it was pretty cool they could be creating code that could end up in space!

Some students testing the humidity in their breath
Some students testing the humidity in their breath
"Look what I made!"
“Look what I made!”
Trying to beat the humidity record.
Trying to beat the humidity record.
Creating pixel art using the Sense HAT!
Creating pixel art using the Sense HAT!

Plus, of course I ended up in one of the spacesuits on the Saturday!

Raspberry Pi Zero – Programming over USB! (Part 1)

Part 2 to this post can be found here.

Update 19/05/2016 – The modules are now included in the most recent version of Raspbian and thanks to some digging around in kernel documentation, it is now possible to set the full thing up without a keyboard/mouse/screen! Just need a Windows/Mac/Linux computer!

Update 15/01/2016 – The modules have now been merged into the Raspberry Pi Foundation maintained kernels! So no more need for custom kernels, just need to grab the most recent alpha kernels. Doing this is now far simpler.

Full credit for the initial documentation for this goes to a number of Pi experts from the Raspberry Pi community, see here and here.

An acknowledgement also to Lady Ada of Adafruit who was working on documenting in parallel to myself on Christmas eve. She has taken a different approach which requires a UART serial cable. Her guide can be found here.

What is this?

The Raspberry Pi Zero is a very cool little computer. At £4, is pretty amazing for the price. But one thing many Pi users have wanted to be able to do for a long time is program their Raspberry Pi from another computer, using only a single USB cable!

The Raspberry Pi Zero is able to do this, hardware wise anyway, although a lack of software support was holding up it ever happening. Until now!

So what can it do?

Using the Linux USB Gadget modules, we can get the Pi Zero to emulate a whole host of USB devices including

  • Virtual Serial – So can get a serial connection into the Pi, similar to using the UART pins. You can use Putty (on Windows) or Screen (on Mac and Linux).
  • Virtual Ethernet – You can get your Pi Zero to appear as a USB Ethernet modem. With a little configuration, you can then get full SSH, VNC, FTP etc.
  • Mass storage device – You can get the Pi Zero to appear as a flash drive, allowing you to for example, copy files over and have the Pi run these files (useful for robotics for example)
  • Virtual MIDI – The Pi Zero could appear as a virtual MIDI instrument.
  • Virtual Audio – The Pi Zero could appear as a virtual headphone output or microphone input.
  • Virtual Human Interface Device (HID) – The Pi Zero could appear as a virtual HID, for example a keyboard or mouse. So when you plug it into your computer, it could start typing!

You can also combine a few of the above (up to 3 at a time) using the g_multi module, although Windows and Mac have difficulty handling it then.

Examples

Where is this useful? Lets take an example of some Raspberry Pi robots in a classroom. Although you could be using Wifi for each robot, remembering addresses, unreliability with wifi etc all make wifi a bit of a rubbish answer.
With this, the student simply plugs in the robot and perhaps drops their script onto the flash drive that appears. When they unplug it, the robot runs the script, dumping the results of the script back onto the mass storage device, ready to be read when it is plugged in next.

Another example, lets say you don’t have access to a screen to use with your Raspberry Pi Zero, in for example, a school. You could still let your students play with GPIO or Linux by simply using the serial module (with Putty or Screen), or the virtual ethernet module to allow them SSH access.

How to I set it up on my Raspberry Pi?

I have thrown together a guide over on Github Gists, including links to the downloadable precompiled kernels.

Destination space at W5

On Tuesday 15th December 2015, Tim Peake, the first British ESA astronaut, launched on a Soyuz rocket from Baikonur Cosmodrome.

To celebrate this, a number of Destination Space public events were being held across the UK with one at W5 in Belfast.
Myself and some of the Northern Ireland Raspberry Jam team went along and with us, brought 10 Raspberry Pis, some Sense HATs and a stack of Raspberry Pi DOTS Boards.

Rocket dots

Our most popular activity we were running on the day was as usual, the DOTS boards. For the launch, I hastily added a new Easter Egg to the RPi-dots-minecraft program, a rocket simulation!

To enable the secret mode, you simply don’t draw the wings on the plane, causing your drawing to look like a rocket!

Lots and lots of rockets filled in by schoolkids!
Lots and lots of rockets filled in by schoolkids!
Lots of schoolkids busy drawing their customised rockets!
Lots of schoolkids busy drawing their customised rockets!

The activity was extremely popular with over 200+ students giving it a go.

We even had a real ESA astronaut, Jean-Francois Clervoy try out the activity!
We even had a real ESA astronaut, Jean-Francois Clervoy try out the activity!

Sense HAT activity

We also brought along a set of Sense HATs and set them up with the excellent Raspberry Pi Foundation Sense HAT pixel art activity.

Although not as popular as the DOTS boards, Dean and Art were certainly kept busy helping stacks of kids create some awesome pixel art using Python!

Of course, there were a number of creepers created.
Of course, there were a number of creepers created.

Thanks

Big thanks to the wonderful team of Northern Ireland Raspberry Jam volunteers who were able to make it down for the day and for W5 for having us. We all had a great day!

NI Raspberry Jam team at Destination Space. From left to right. Vincent Lee, Andrew Mulholland (myself), Dean Welch, Artemiy Knipe, Sam Stuart.
NI Raspberry Jam team at Destination Space.
From left to right.
Vincent Lee, Andrew Mulholland (myself), Dean Welch, Artemiy Knipe, Sam Stuart.