Magic Presentations with Skywriter

By Russell Barnes. Posted

Amaze your audience with baffling magical powers or mastery of the Force using a Skywriter HAT

Let’s face it: simply using a Raspberry Pi to run the slides for your talk will make the audience think you’re pretty cool. But if that’s not impressive enough, why not dazzle them further by using your telekinetic powers to flip through the presentation and annotate the slides by drawing in the air? You don’t even need to be a graduate of Hogwarts or the Jedi Academy: just get yourself a Skywriter device and some simple Python, and you’re ready to rock.

The Skywriter device uses a grid of transmitting electrodes to generate an electric field that propagates around the surface in three dimensions. When you move your hand above the Skywriter, it disturbs this field and these variations are detected by the receiver electrode grid. These measurements can be used to calculate the position and movement direction of your hand.

This tutorial can be found in The MagPi 39 and was written by Richard Hayler

You'll need...

Skywriter HAT or board
Skywriter API library
Python AutoPy library
LibreOffice Impress

STEP-01

Connect the Skywriter device

If you have a Skywriter HAT, this just connects onto the GPIO pins like other HATs. If you have the larger Skywriter board, you’ll need to connect six GPIO pins to the matching pins at the top, as shown below.

 Pay attention to the wiring diagram!

STEP-02

Install the software

Make sure you have the latest version of Raspbian, with all updates installed. As usual, those helpful Pimoroni Pirates supply a single script to handle the installation, including the full Python API. Like most HATs, the Skywriter needs the I2C bus on the Pi to be enabled, so if you haven’t already got this activated on your Pi, you’ll need to reboot before the Skywriter will work.

$ curl -sSL get.pimoroni.com/skywriter | bash

You’ll also need the AutoPy Python library and its dependencies, so install these with:

$ sudo apt-get install libx11-dev libxtst-dev

…and then:

$ sudo pip install autopy

STEP-03

Test your Skywriter

The Python API has example scripts to help you become familiar with the way Skywriter works:

$ cd Pimoroni/skywriter
$ sudo python test.py

Now wave your hand around in the air just above your Skywriter. You should see three columns of scrolling numbers corresponding to your hand’s position in a three-axis (x/y/z) box over the device. The Python library is preconfigured to recognise certain gestures: a flick (swiping over the Skywriter), a tap or touch (bring your hand down to just above the surface), and, trickiest of all, the Airwheel (wiggle a finger in a circular pattern above the Skywriter). It takes a while to get the hang of reproducing these gestures so that they are always detected, so spend some time practising. You can edit the test.py script and comment out the @skywriter.move() function (which displays the x/y/z numbers) to make it easier to see when you’ve nailed one of the gestures.

STEP-04

Configure your presentation software

Now it’s time to get your presentation software ready. LibreOffice Impress is very similar to Microsoft PowerPoint and works well on the Raspberry Pi. If you don’t need the other applications in the LibreOffice suite, you can just install Impress and the core components using:

$ sudo apt-get install libreoffice-impress

You’re going to use Python code to detect gestures via the Skywriter and generate keyboard taps to control Impress in the normal way. The only extra configuration necessary is to activate the functionality that lets you draw on slides with the mouse. This is done by selecting Slide Show>Slide Show Settings and checking the ‘Mouse pointer as pen’ box.

STEP-05

Use the code

Type up the code from the listing (right) and save it as magic_control.py. You can do this using IDLE or with another text editor of your choice. Start LibreOffice Impress and open your presentation. Then minimise Impress and run your code either through Idle or via the command line:

$ sudo python magic_control.py

Now flip back to Impress and get ready to start your talk or presentation.

 Razzle Dazzle

STEP-06

Dazzle your audience

Start the slideshow by flicking upwards across the Skywriter. You can navigate through the slides by flicking left to right (forward), or right to left (backwards). To end the presentation, flick down across the Skywriter.

To annotate a slide, you need to activate the drawing function. Do this using a tap/touch: you’ll now be controlling the mouse with your hand movements, leaving a trail on the screen just like you’re drawing with a pen. This takes practice, so make sure you’ve spent some time preparing in advance! When you’ve finished drawing, tap/touch again to disengage the pen function.

We all know that, under the pressure of a live performance, things can go wrong. If you want to quickly disable Skywriter control of the presentation, use a double-tap to quit the Python program.

Code listing

Magic_Control.py

#!/usr/bin/env python
import skywriter
import signal
import autopy
import sys

mouse_down = False
#work out how big the screen we're using is.
width, height = autopy.screen.get_size()

@skywriter.move()
def move(x, y, z):
  #print( x, y, z )
  global mouse_down
  if mouse_down: # Only run if we're in drawing mode
      x = (x) * width
      y = (y) * height
      # scale to screen size
      x = int(x)
      y = height - int(y)

      if( y > 799 ):
       y = 799

      autopy.mouse.move(x, y)
      #print( int(x), int(y) )

@skywriter.flick()
def flick(start,finish):
  print('Got a flick!', start, finish)
  if start == "east": # Back through Impress slides
    autopy.key.tap(autopy.key.K_LEFT)
  if start == "west": # Forward through Impress slides
    autopy.key.tap(autopy.key.K_RIGHT)
  if start == "north": # Start slideshow
    autopy.key.tap(autopy.key.K_F5)
  if start == "south": # Quit slideshow
    autopy.key.tap(autopy.key.K_ESCAPE)


@skywriter.double_tap()
def doubletap(position):
  print('Double tap!', position)
  sys.exit() # Emergency stop


@skywriter.tap()
def tap(position):
  global mouse_down
  print('Tap!', position)
  if mouse_down: # Toggle mouse up/dwon
      autopy.mouse.toggle(False)
      mouse_down = False
  else:
      autopy.mouse.toggle(True)
      mouse_down = True

#@skywriter.touch()
#def touch(position):
#  print('Touch!', position)

signal.pause()

https://twitter.com/another_russell

Subscribe