Howdy, Stranger!

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

Supported by

Extending sketchpad

Hi All,

The device we need to control is a pinpad, connected via USB-serial connection. Every pin is controlled individually, sending "cryptic" strings.
I am wondering how to extend sketchpad functionality. What i need, is fixed set of switchable elements, saving their state in editing mode and replaying the state to serial port in the experiment mode. I'm quite new to the Python and don't want this project to extend to the next 150 years.
Basically, i need to know if this kind of extension is possible in Opensesame and the complexity of the entire task.


  • Hi,

    Your description is not entirely clear to me. What exactly do you want to do? Do you simply want to mirror the output of the display on the pinpad, so that the pinpad is basically a tactile monitor? Or do you want to do something else?


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

  • Hi Sebastiaan,

    for the first iteration i want the string to be parsed and displayed on the screen in graphical form, representing the extended and retracted pins. Eg. string "xA1A4B1B4y" will extend pins on the left and right sides of the pad, on the 1st and 3rd rows (the actual pad is in 6x4 configuration, but Braille and custom ones are available on demand).
    During the experiment, the string must be transmitted via serial port to the actual device and may be displayed graphically on the screen.

    For the second iteration i expect the string to be created graphically, enabling or disabling GUI elements.

  • Hi,

    So if I understand correctly (of which I'm not sure), you want to add text to a canvas/ sketchpad, and then have this text be automatically sent to the device. Right?

    In that case, you could monkey-patch the canvas backend. The script below shows the general idea. This creates two custom functions:

    • custom_text, which remembers all text strings; and
    • custom_show, which does something with all text strings when the canvas is shown. (In your case that would entail sending the string through the serial port.)

    Serial-port communication itself is quite easy in Python. You can use the serial module:

    Does that help at all?


    from openexp._canvas.legacy import legacy
    def custom_text(self, text, *args, **kwargs):
        print('Adding text: %s' % text)
        if not hasattr(self, '_all_text'):
            self._all_text = []
        self._original_text(text, *args, **kwargs)
    def custom_show(self):
        while hasattr(self, '_all_text') and self._all_text:
            text = self._all_text.pop()
            print('Send %s' % text)
            # Some code here to send text via serial port
    legacy._original_text = legacy.text
    legacy.text = custom_text
    legacy._original_show = = custom_show

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

Sign In or Register to comment.