labjack EEG triggers

468 views
Skip to first unread message

Thomas Bullock

unread,
Mar 14, 2016, 6:34:05 PM3/14/16
to psychopy-users
Dear group

I have a question regarding how to send a range of different trigger codes to our EEG machine (Brain Products ActiChamp) via a LabJack U3 device.  I'm running PsychoPy version 1.83.04 and am working exclusively with the coder interface.  My OS is Ubuntu 14.04.

I have the labjack drivers installed and have successfully managed to send trigger codes using the script below:

import u3
ports = u3.U3()
FIO4 = 6008  #the address of line FIO4
ports.writeRegister(FIO4,1)# set high (value=209)
ports.writeRegister(FIO4,0)# set low (value=208)

However, I'm unsure how to send codes with different values (i.e. not just 209 and 208)

I typically write experiments in matlab/psychtoolbox, and send triggers using the code snippet below, where 'thisTrigger' can be any value from 0 to 255.  I'm essentially just looking for the same functionality in PsychoPy.

lj.setDIO([0,thisTrigger,0])
    WaitSecs(.005);
    lj.setDIO([0,0,0])

If anyone knows how to do this or can point me towards some resources I'd really appreciated it.

Thanks

Tom




Andrew

unread,
Mar 15, 2016, 4:28:15 PM3/15/16
to psychopy-users
Hi Tom,

I think you'll find what you need near the end of this thread.

Best,
Andrew

Thomas Bullock

unread,
Mar 16, 2016, 2:02:15 PM3/16/16
to psychopy-users
Hi Andrew

Thank you for directing me towards that thread - this does seem to be exactly what I'm looking for!

However, when I run the script below I don't register any triggers.  Does this look correct to you, or am I missing something?  The script doesn't throw up any error messages, so it's hard to troubleshoot.

Thanks

Tom

#########

from __future__ import division

import u3

#set trigger
byte=1

class U3(u3.U3):
    def setData(self, byte, endian='big', address=6701):
        self.writeRegister(address, 0xFF00 + (byte&0xFF))

##########

Andrew

unread,
Mar 16, 2016, 8:07:13 PM3/16/16
to psychopy-users
a couple of quick thoughts ...

* make sure to send a zero first because the labjack initializes with all bits set high. 

* try changing the port address to "6008" instead of "6701"

Thomas Bullock

unread,
Mar 16, 2016, 9:26:48 PM3/16/16
to psychopy-users
Thank you for the suggestions - unfortunately neither resolved the issues.

Normally setting the port address to "6008" does work.  For example, I can send the codes 255 and 245 using the following example:

############################
import u3, time

#setup labjack U3

ports = u3.U3()
FIO4 = 6008  #the address of line FIO4
ports.writeRegister(FIO4,0)#start low
time.sleep(.5)
ports.writeRegister(FIO4,1) # sends code 255
time.sleep(.5)
ports.writeRegister(FIO4,0) # sends code 254
#############################

However, when I try and use the new code to send triggers, nothing registers.  For reference, the script I'm using is below (I'm just trying to send trigger code 25).

#############################
from __future__ import division
import time
import u3

class U3(u3.U3):
    def setData(self, byte, endian='big', address=6008):
       
        time.sleep(1)
        # send zero
        byte=0
        self.writeRegister(address, 0xFF00 + (byte&0xFF))
       
        time.sleep(1)
        # send trigger code
        byte=25
        self.writeRegister(address, 0xFF00 + (byte&0xFF))
       
        time.sleep(1)
        #send zero
        byte=0
        self.writeRegister(address, 0xFF00 + (byte&0xFF))

#####################################

Best

Tom

Andrew

unread,
Mar 17, 2016, 3:04:54 PM3/17/16
to psychopy-users
Hi Tom,

I'm not sure what the issue is. I've attached the code from a little pilot study I've been running (I built the study in Builder, but i've attached the compiled script). I've also attached the modified version (modified from version included in the standalone installation) of labjacks.py  Note, I use the terminals on the side of the Labjack (EIO) so you'll want to change the address in labjacks.py.

Hope this helps.

Best,
Andrew
labjacks.py
pilot01.py

Thomas Bullock

unread,
Mar 18, 2016, 1:17:58 AM3/18/16
to psychopy-users
Hi Andrew

Thank you - having the opportunity to look at your pilot experiment really helped.  I was able to get the LabJack to send triggers 1-255 using a tester script that I wrote (below).

However, this only works correctly with the original labjacks.py script.  When I replace the old script with the new version of the labjacks.py script that you set me, all triggers just appear as "1".

It appears that the only change in the old and updated labjacks scripts is with the self.writeRegister function at the end, so it must have something to do with that.  I'll do some more investigating tomorrow...

Cheers

Tom

#############################
# Tom test labjack

from psychopy.hardware import labjacks
import time
p_port = labjacks.U3()

# initial set port to zero
byte=0
p_port.setData(byte, endian='big', address=6008)

for byte in range(1,255):
   
    time.sleep(.5) # wait between triggers
   
    p_port.setData(byte)    # send trigger
    time.sleep(.005)     # wait
    p_port.setData(0)   # zero port
   
    print byte # print to output
   
#close labjack
p_port.close()
####################################

Andrew

unread,
Mar 18, 2016, 6:26:07 AM3/18/16
to psychopy-users
Try address 6700 instead of 6008 when using the new version of labjacks.py. I *think* that'll do the trick.

Thomas Bullock

unread,
Mar 18, 2016, 12:38:10 PM3/18/16
to psychopy-users
Address 6701 worked for me with the new version of labjacks.py (6700 didn't send any triggers).  Perhaps this is specific to different OS/LabJack Models (for reference, I'm running  U3 on Ubuntu 14.04)?

Thank you again for your help with resolving this issue!

Tom
Reply all
Reply to author
Forward
0 new messages