Line 1: |
Line 1: |
| + | {{Infobox tsg |
| + | | name = Buttonbox (2018) |
| + | | image = Buttonbox_2018_1.png |
| + | | caption = 2018 Buttonbox |
| + | | downloads = {{bulleted list |
| + | | [https://surfdrive.surf.nl/files/index.php/s/PPTKCyrjLkN4XUO Buttonbox 2018] |
| + | | [https://pypi.python.org/pypi/RuSocSci RuSocSci] (Python package) |
| + | }} |
| + | }} |
| {{Infobox tsg | | {{Infobox tsg |
| | name = Buttonbox | | | name = Buttonbox |
Line 4: |
Line 13: |
| | caption = 2013 Buttonbox | | | caption = 2013 Buttonbox |
| | downloads = {{bulleted list | | | downloads = {{bulleted list |
− | | [[Buttonbox 2013 Hardware|Buttonbox 2013 Hardware Design]] | + | | [https://surfdrive.surf.nl/files/index.php/s/72XEcu2XKSgzxjp Buttonbox 2015] |
− | | [[Media:BITSI_tempalte2015_duemilanove.zip|Code Template 2015 (Duemilanove)]]
| |
| | [https://pypi.python.org/pypi/RuSocSci RuSocSci] (Python package) | | | [https://pypi.python.org/pypi/RuSocSci RuSocSci] (Python package) |
| }} | | }} |
Line 13: |
Line 21: |
| | | |
| The output connector has two binary eight bit ports: input and output. The two ports can be used for responses (input) and stimulus triggers (output). Two 12 bits analog outputs and three 12 bits analog inputs. The output connector has a sound and voicekey which triggers when a amplitude reaches a threshold. By using the serial port, the BITSI can be used platform independently: it works on Windows, Linux and Mac OSX. Most programming environments and stimulus packages support serial communication. | | The output connector has two binary eight bit ports: input and output. The two ports can be used for responses (input) and stimulus triggers (output). Two 12 bits analog outputs and three 12 bits analog inputs. The output connector has a sound and voicekey which triggers when a amplitude reaches a threshold. By using the serial port, the BITSI can be used platform independently: it works on Windows, Linux and Mac OSX. Most programming environments and stimulus packages support serial communication. |
| + | |
| + | There is currently a [[Microsoft Windows driver issue]]. |
| | | |
| == BITSI Protocol == | | == BITSI Protocol == |
Line 52: |
Line 62: |
| ===Output=== | | ===Output=== |
| | | |
− | Output knows two protocols: '''BITSI simple''' or '''BITSI extended'''. To enter a certain protocol two buttons have to be pressed when the BITSIbox is powered. '''Press button H and A for simple mode and H and B for extended mode.''' | + | Output knows two protocols: '''BITSI simple''' or '''BITSI extended'''. To enter a certain protocol two buttons have to be pressed when the BITSIbox is powered or com port opens. '''[2015]Press button H and A for simple mode and H and B for extended mode. [2018]Press button E and A for simple mode and E and B for extended mode.''' |
| | | |
| If no button is pressed when powered it boots the last known protocol. In the simple protocol every byte sent to the BITSI over the serial port, is represented at the 8 bit output. | | If no button is pressed when powered it boots the last known protocol. In the simple protocol every byte sent to the BITSI over the serial port, is represented at the 8 bit output. |
Line 109: |
Line 119: |
| | | |
| The 25 pins female connector has 8 inputs and 8 outputs, respectively 1-8 are inputs and 9-16 are outputs. Three analog input with an analog to digital convertor of 12 bit, pins 17,18,20 and 21. Two analog outputs with an digital to analog convertor of 12 bits on pins 22 and 23. | | The 25 pins female connector has 8 inputs and 8 outputs, respectively 1-8 are inputs and 9-16 are outputs. Three analog input with an analog to digital convertor of 12 bit, pins 17,18,20 and 21. Two analog outputs with an digital to analog convertor of 12 bits on pins 22 and 23. |
| + | |
| + | The inputs 1-8 will be pulled down from 5V to GND when the buttons are pressed. The outputs 9-16 will be pulled up from GND to 5V when the output is activated. |
| | | |
| ===Serial port=== | | ===Serial port=== |
Line 172: |
Line 184: |
| * Rate must be set 115200, Parity to None, Data Bits to 8 and Stop Bits to 1, Uncheck FIFO Interrupt. | | * Rate must be set 115200, Parity to None, Data Bits to 8 and Stop Bits to 1, Uncheck FIFO Interrupt. |
| | | |
− | [[File:Buttonbox1.png]] | + | [[File:Buttonbox2.png]] |
| | | |
| '''Testing Buttonbox''' | | '''Testing Buttonbox''' |
Line 211: |
Line 223: |
| === Python/PsychoPy === | | === Python/PsychoPy === |
| | | |
− | Download this site-package to use the buttonbox: [https://pypi.python.org/pypi/RuSocSci rusocsci] | + | Download this site-package to use the buttonbox: [https://pypi.python.org/pypi/RuSocSci rusocsci] |
| + | |
| + | or use in windows command 'pip install --upgrade rusocsci' |
| | | |
| '''Example using buttons from the buttonbox in Python:''' | | '''Example using buttons from the buttonbox in Python:''' |
Line 275: |
Line 289: |
| # make a buttonbox | | # make a buttonbox |
| ser = serial.Serial("COM2", 115200, timeout = 0.10 ) | | ser = serial.Serial("COM2", 115200, timeout = 0.10 ) |
| + | ser = serial.Serial("/dev/ttyUSB0", 115200, timeout = 0.10 ) |
| | | |
| while True: | | while True: |
Line 339: |
Line 354: |
| % | | % |
| % to run: (receiving incoming data, check code for own purposes) | | % to run: (receiving incoming data, check code for own purposes) |
− | % buttonbox('run',handle); | + | % buttonbox('run'); |
| % | | % |
| % or | | % or |
| % | | % |
− | % to send a marker: (marker: a numeric value) | + | % to send a marker: (marker: a numeric value; Fs: sampling frequency device) |
− | % buttonbox(marker) | + | % buttonbox(marker,Fs) |
| % | | % |
| % or | | % or |
| % | | % |
| % to wait for a buttonpress: | | % to wait for a buttonpress: |
| + | % buttonbox('clear'); (make sure buttonbox buffer is emptied) |
| % key = buttonbox('wait_keypress') | | % key = buttonbox('wait_keypress') |
| % | | % |
| % to close the connection: | | % to close the connection: |
− | % buttonbox('close',handle); | + | % buttonbox('close'); |
− | | |
− | persistent old_hdl % keep handle to COM object persistent
| |
| | | |
| + | persistent old_hdl % keep handle to COM object persistent |
| % set defaults | | % set defaults |
| bb.Device = 'COM2'; | | bb.Device = 'COM2'; |
Line 361: |
Line 376: |
| bb.DataBits = 8; | | bb.DataBits = 8; |
| bb.StopBits = 1; | | bb.StopBits = 1; |
− | bb.Parity = 'none'; | + | bb.Parity = 'none'; |
| | | |
| if nargin < 1 | | if nargin < 1 |
| cmd = 'open'; | | cmd = 'open'; |
| end | | end |
− | if nargin > 1 | + | if nargin > 1 && isstruct(varargin{1}) |
| % user overwrites default settings | | % user overwrites default settings |
| flds = fields(varargin{1}); | | flds = fields(varargin{1}); |
Line 374: |
Line 389: |
| end | | end |
| if nargin==1 && isnumeric(cmd) | | if nargin==1 && isnumeric(cmd) |
| + | error('Please also specify acquisition sampling frequency of device that receives the marker'); |
| + | end |
| + | if nargin > 1 && isnumeric(cmd) |
| marker = cmd; | | marker = cmd; |
| cmd = 'marker'; | | cmd = 'marker'; |
| + | Fs = varargin{1}; |
| end | | end |
| | | |
| + | if ~any(strcmp(cmd,{'open','close'})) |
| + | if isempty(old_hdl) |
| + | help serial_buttonbox_common |
| + | error('Buttonbox not yet initialized'); |
| + | end |
| + | handle = old_hdl; |
| + | end |
| | | |
| switch cmd | | switch cmd |
| case 'marker' | | case 'marker' |
− | if isempty(old_hdl) | + | fwrite(handle, uint8(marker));%IOPort('Write', handle, uint8(marker), 1); % last argument: blocking |
− | help serial_buttonbox_common
| + | WaitSecs(2/Fs); |
− | error('Buttonbox not yet initialized');
| + | fwrite(handle, uint8(0));%IOPort('Write', handle, uint8(0), 0); % last argument: blocking |
− | end
| + | return |
− | handle = old_hdl;
| + | case 'clear' |
− | ret = IOPort('Write', handle, uint8(marker), 1); % last argument: blocking
| + | while(handle.BytesAvailable) |
− | java.lang.Thread.sleep(10); | + | fread(handle, 1); |
− | IOPort('Write', handle, uint8(0), 0); % last argument: blocking | |
− | if ret < 1 | |
− | disp('Marker might not have been written to button box, please verify setup....?'); | |
| end | | end |
| + | ret = []; % meaningless |
| return | | return |
| case 'open' | | case 'open' |
Line 399: |
Line 423: |
| return | | return |
| case 'close' | | case 'close' |
− | if nargin > 0 | + | if nargin > 1 |
| handle = varargin{1}; | | handle = varargin{1}; |
| else | | else |
Line 405: |
Line 429: |
| end | | end |
| fclose(handle); | | fclose(handle); |
− | ret = handle; | + | delete(handle); |
| + | ret = []; |
| return | | return |
| case 'run' | | case 'run' |
| % read incoming data | | % read incoming data |
− | if isempty(old_hdl)
| |
− | help serial_buttonbox_common
| |
− | error('Buttonbox not yet initialized');
| |
− | end
| |
− | handle = old_hdl;
| |
| % code proceeds below .... | | % code proceeds below .... |
| case 'wait_keypress' | | case 'wait_keypress' |
− | % read incoming data | + | % start polling for characters (indicating start of scan) |
− | if isempty(old_hdl)
| + | while(1) |
− | help serial_buttonbox_common
| + | data = []; |
− | error('Buttonbox not yet initialized');
| + | while handle.BytesAvailable |
− | end
| + | navailable = handle.BytesAvailable; |
− | handle = old_hdl;
| + | % read incoming data |
− | while 1
| + | [newdata, cnt] = fread(handle, navailable); |
− | % start polling for characters (indicating start of scan)
| + | % concatenate possible new data |
− | navailable = handle.BytesAvailable; | + | if cnt |
− | if navailable
| + | data = [data newdata(:)]; |
− | data = [];
| |
− | while navailable | |
− | % read incoming data
| |
− | [newdata, cnt] = fread(handle, navailable);
| |
− | % concatenate possible new data
| |
− | if cnt
| |
− | data = [data newdata(:)];
| |
− | end
| |
− | % check if any more data left
| |
− | navailable = handle.BytesAvailable;
| |
| end | | end |
| + | end |
| + | if ~isempty(data) |
| ret = data; | | ret = data; |
| return | | return |
| end | | end |
− | end %while 1 | + | end |
| otherwise | | otherwise |
| fprintf('Unknown option %s\n',cmd); | | fprintf('Unknown option %s\n',cmd); |
| ret = []; | | ret = []; |
− | return | + | return |
− |
| + | end |
− |
| |
− | end | |
| | | |
| %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| % only gets here when cmd = 'run' % | | % only gets here when cmd = 'run' % |
− | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | + | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
− | | |
| % Initialize output figure | | % Initialize output figure |
| win = list_output(' ',[]); | | win = list_output(' ',[]); |
Line 481: |
Line 490: |
| end | | end |
| pause(0.01); | | pause(0.01); |
− | end %while 1 | + | end %while 1 |
| + | |
| + | |
| | | |
| function hdl = open_buttonbox(device) | | function hdl = open_buttonbox(device) |
− | % open handle to serial device (mini buttonbox) | + | % open handle to serial device (mini buttonbox) WaitSecs(0.002); % just to load mex-file into memory |
| try | | try |
| hdl = serial(device.Device, 'Baudrate', device.BaudRate, 'DataBits', device.DataBits, 'StopBits', device.StopBits, 'Parity', device.Parity); | | hdl = serial(device.Device, 'Baudrate', device.BaudRate, 'DataBits', device.DataBits, 'StopBits', device.StopBits, 'Parity', device.Parity); |
Line 496: |
Line 507: |
| fopen(hdl); | | fopen(hdl); |
| end | | end |
− | old_hdl = hdl; | + | old_hdl = hdl; |
− |
| |
| fprintf('Wait for device buttonbox....\n'); | | fprintf('Wait for device buttonbox....\n'); |
| tic | | tic |
Line 505: |
Line 515: |
| fread(hdl, navailable); | | fread(hdl, navailable); |
| end | | end |
− | pause(0.5); | + | pause(0.5); |
− |
| + | end |
− | % while ~IOPort('BytesAvailable', hdl) && toc<10
| |
− | % % wait for welcome message device
| |
− | % end
| |
− | % pause(0.5);
| |
− |
| |
− | % clear buffer
| |
− | %IOPort('flush', hdl);
| |
− | IOPort('purge', hdl);
| |
− |
| |
− | end | |
| | | |
| function win = list_output(line,win) | | function win = list_output(line,win) |
Line 522: |
Line 522: |
| persistent lines | | persistent lines |
| persistent edt | | persistent edt |
− | Maxlines = 40; | + | Maxlines = 40; |
− |
| |
| if isempty(win) | | if isempty(win) |
| % initialize listbox output figure | | % initialize listbox output figure |
Line 530: |
Line 529: |
| ptr=Maxlines; | | ptr=Maxlines; |
| lines(ptr) = {'Buttonbox output:'}; | | lines(ptr) = {'Buttonbox output:'}; |
− | idxs = mod(ptr:ptr+Maxlines-1,Maxlines)+1; | + | idxs = mod(ptr:ptr+Maxlines-1,Maxlines)+1; |
− |
| |
| win = figure(); | | win = figure(); |
| % initialize figure to hold output text | | % initialize figure to hold output text |
Line 545: |
Line 543: |
| set(edt,'String',lines(idxs),'Value',Maxlines); | | set(edt,'String',lines(idxs),'Value',Maxlines); |
| drawnow; | | drawnow; |
− | end | + | end |
− | end</syntaxhighlight> | + | end |
| + | end</syntaxhighlight> |