Use Wacom graphics tablet in experiment: PeniInizialization and getSamples


(1) How can I correcttly setup a pen device with (e.g. with psychopy.iohub.launchHubServer or is there another way less related to HDF5 files)?

(2) What does pen.getSamples() return?


I have a running experiment, where subjects are presented with images. I want to allow subjects to draw on the Images with a Wacom tablet. I’d like to save the koordinates of the drawing in a list or matrix.

(A) I was able to implement drawing with the mouse, where the drawing starts once the mouse button is clicked. With the pen and tablet, I can move the mouse pointer within this code, but not draw.

(B) I am aware of this wintab demo code, it works on my laptop, but can’t figure out how to tranfer relevant parts to my experiment.

So far I have:

(1) For the setup

  def setup_iohub(win, sess_code=None):
      exp_code = 'wintab_evts_test'
      if sess_code is None:
          sess_code = 'S_{0}'.format(int(time.mktime(time.localtime())))
      # iohub configuration for the Pen device
      kwargs = {'experiment_code': exp_code,
              'session_code': sess_code,
              'wintab.Wintab': {'name': 'pen',
                              'mouse_simulation': {'enable': False,
                                                      'leave_region_timeout': 2.0
      # Launch iohub server with the specified configuration
      return launchHubServer(window=win, **kwargs)
  io = setup_iohub(win)
  keyboard = io.devices.keyboard
  mouse = io.devices.mouse
  pen = io.devices.pen

(2) For the drawing

while continue_drawing:
    # Redraw the background image and the instruction text

    # Fetch the latest samples from the pen
    is_reporting = pen.reporting
    wtab_evts = pen.getSamples()
    if len(wtab_evts) > 0:
        if is_reporting:
            last_evt = wtab_evts[-1]
    # Draw the current pen position and traces

    for evt in wtab_evts:
        if evt.pressure > 0:  # Only record when the pen is touching the tablet
            x, y = evt.x, evt.y
            pen_data.append((x, y))

    win.flip()  # Refresh the screen