Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Use Expyriment script on Android devices

I would like use simple Scripts, made with Expyriment, for visual stimuli presentations and answer collections on a samsung galaxy Tab S2 (android 7.0). But I have problems when I try to run them. The example experiments "" works correctly but if I only add the drawing of a circle or the use of circular (instead of rectangular) keys the program no longer works. Can you tell me what is the problem or what I wrong? There are limitations on the Python/Expyriment commands that are recognized during the execution of experiments in android. Thank you.


  • Very difficult to say without knowing your code, sorry.

  • This is the code:

    I wrote in bold the changes to the original program ""

    Thanks you

    very much

    #!/usr/bin/env python

    # -*- coding: utf-8 -*-


    A line bisection task.

    This example is appropriate to illustrates the use of the Android runtime environment for Exypriment on tablet PC.


    from __future__ import division

    from expyriment import control, stimuli, io, design, misc

    # settings

    design.defaults.experiment_background_colour = misc.constants.C_GREY

    design.defaults.experiment_foreground_colour = misc.constants.C_BLACK

    line_length = 200

    def line_bisection_task(line_length, position):

      # make button

      button = stimuli.Rectangle(size=(40,20),

            position=(exp.screen.size[0]//2-25, 15-exp.screen.size[1]//2))

      button_text = stimuli.TextLine(text="ok", position=button.position, text_colour=misc.constants.C_WHITE)

      mark_position = None

      while True:

        canvas = stimuli.BlankScreen()

        line = stimuli.Rectangle(size=(line_length,3), position=position,



        if mark_position is not None:

          # plot button and mark line on canvas



          markline = stimuli.Rectangle(size=(1,25),

                position=(mark_position, line.position[1]),



        # present stimulus


        # wait for mouse or touch screen response

        _id, pos, _rt = exp.mouse.wait_press()

        # process clicked position position

        if abs(pos[1]-line.position[1])<=50 and\


          mark_position = pos[0]


          if button.overlapping_with_position(pos): # is button pressed

            return mark_position - line.position[0]

    ### init ###

    exp = control.initialize()

    # create touch button box

    buttonA = stimuli.Circle(radius= 20, position=(-60, 0))

    buttonB = stimuli.Circle(radius= 20, position=(60, 0))

    textA = stimuli.TextLine(text="quit", position=buttonA.position, text_colour=misc.constants.C_WHITE)

    textB = stimuli.TextLine(text="next", position=buttonB.position, text_colour=misc.constants.C_WHITE)

    touchButtonBox = io.TouchScreenButtonBox(button_fields=[buttonA, buttonB], stimuli=[textA, textB])

    ### start ###



    # trial loop

    while True:

      # find random position

      rx, ry = ((exp.screen.size[0]-line_length)//2, (exp.screen.size[1]-50)//2)

      pos = [design.randomize.rand_int(-rx, rx), design.randomize.rand_int(-ry, ry)]

      # present task

      judgment = line_bisection_task(line_length, position=pos)

      # save data +[judgment])

      # ask for new trail

      btn, _rt = touchButtonBox.wait()

      if btn==buttonA:


    ## end##


  • The Android Runtime is currently still based on Expyriment 0.7.0. The Circle stimulus in this release does not have a parameter called "radius", but one called "diameter".

  • I have installed experiment 0.7.0 on my PC and modified the program. Now it works correctly on the PC and on the tablet.

    Thanks you very much

  • Glad it works now for you!

  • I would like to know if it is possible to create a python/Expyriment 7 code to record vocal responses. This is because the code should then be used on an android tablet; this code should then be usable with the Expyriment's App on an android tablet.

    Thank you.

  • You could have a look at sounddevice maybe.

  • Yes, sounddevice should be fine but I think it is not present in the Android Runtime and I can't use it with the tablet.

Sign In or Register to comment.