All functions of this toolbox involved in the presentation of stimuli on the screen (e.g. words and images) will display their results immediately. This means that everything the function is told to present will be presented on the screen right after the function is called (for advanced users: the ‘Flip’ command from the Psychophysics Toolbox is executed in every function call).
**Example (1)**
~~~
~~~matlab
initWindow(2);
showText(‘HelloWorld’);
~~~
...
...
@@ -13,7 +13,7 @@ showText(‘Hello World’);
A problem here may occur when you want to combine different presenting functions, e.g. to present text and an image or different texts on different locations on the screen. That is why most presenting functions have the option to use the input argument ‘dontFlip’. When this option is used, the stimulus presentation happens off-screen one after the other (for advanced users: everything will be saved to an internal buffer). As soon as a presenting function is called without the ‘dontFlip’ option everything that was stored internally will be displayed at once. This makes it possible to build up a presentation screen consisting of different input arguments. It also makes possible the combination of images and text. This process works pretty fast and you won’t have any problems of making several ‘dontFlip’ calls and displaying them all within the next frame.
**Example (2)**
~~~
~~~matlab
initWindow(2);
showText('Hello World','x',25,'y',25,'dontFlip');
showText('I am','dontFlip');
...
...
@@ -30,7 +30,7 @@ The Raspberry Pi is an affordable single board computer that is powerful enough
To use our Toolbox on a Raspberry Pi all you have to do is to download the image of the Raspberry Pi and write it to a compatible SD card with at least 16GB. After this step is done connect the SD card to the Raspberry Pi and boot it. Everything is set up already and you can start immediately using our toolbox.
To update the OTBR or the psychophysics toolbox manually you can download the newest versions and replace or add them in the folder XXXX/XXXX/XXX/XXX. All steps presented in chapter 1.1 and 1.2 remain the same.
To update the OTBR or the psychophysics toolbox manually you can download the newest versions and replace or add them in the folder XXXX/XXXX/XXX/XXX. All steps presented in chapter [1.1](/Getting-started#installation-and-setup) and [1.2](/Getting-started#setup-an-experiment) remain the same.
## Using a Raspberry Pi as local or remote computer
...
...
@@ -40,17 +40,17 @@ If you want to use a Raspberry as a remote device, you are able to do that witho
The first step is similar to the procedure described above: download the image file for the Raspberry Pi and flash an SD card. After the Raspberry is up and running modify one file to change the behavior of the Raspberry:
Modify the Octave internal file ‘/home/pi/.octaverc’. This file is called when Octave starts. You can open it with a simple text editor and enter matlab code at the end of the file. This code will then be called directly after starting Octave and before any user input can be made. Use this option to call initOTBR in this file followed by connect2ControlComputer (see section 14.1.). This will initialize the toolbox on the raspberry system. With this changes the Raspberry will now wait for input from the control computer after a reboot.
Modify the Octave internal file ‘/home/pi/.octaverc’. This file is called when Octave starts. You can open it with a simple text editor and enter matlab code at the end of the file. This code will then be called directly after starting Octave and before any user input can be made. Use this option to call [initOTBR](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/initOTBR.m) in this file followed by [connect2ControlComputer](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Network/ExperimentalComputer/connect2ControlComputer.m)(see[section 14.1.](/Network-remote-computer#connect2controlcomputer)). This will initialize the toolbox on the raspberry system. With this changes the Raspberry will now wait for input from the control computer after a reboot.
Before rebooting the Raspberry Pi make sure to check the IP address of the Raspberry. Therefore we created a Link on the Desktop “Change IP address here” that helps you to modify the IP address if necessary.
All other steps can now be performed on the control computer. First make sure to enter all remote host IP addresses in section 10 of myHardwareSetup. In case you use only one Raspberry Pi of course only one IP address is needed. In your experimental script you now need to call connect2Host to establish a network communication to all remote host (Raspberry Pi) that are defined in myHardwareSetup.m.
All other steps can now be performed on the control computer. First make sure to enter all remote host IP addresses in section 10 of [myHardwareSetup](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/myHardwareSetup.m). In case you use only one Raspberry Pi of course only one IP address is needed. In your experimental script you now need to call [connect2Host](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Network/ControlComputer/connect2Host.m) to establish a network communication to all remote host (Raspberry Pi) that are defined in [myHardwareSetup.m](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/myHardwareSetup.m).
To run an actual experiment the Raspberry system needs the experimental files first. That includes stimuli, commands and a place to put results. Send your entire experimental folder by using the sendExperiment2Host command.
To run an actual experiment the Raspberry system needs the experimental files first. That includes stimuli, commands and a place to put results. Send your entire experimental folder by using the [sendExperiment2Host](Network/ControlComputer/sendExperiment2Host.m) command.
The next thing you want to do is to send a command to the remote host. Call sendCommand2Host for this. This function enables you to send any matlab command you like to the host via the established communication. Be aware that the commands need to be entered as strings. The function printCmd will do this for you. Use the output from printCmd as input for sendCommand2Host. E.g. sendCommand2Host(_printCmd([], 'keyBuffer', 10, 'goodkey', (1:3), 'badkey', 4)_);
The next thing you want to do is to send a command to the remote host. Call [sendCommand2Host](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Network/ControlComputer/sendCommand2Host.m) for this. This function enables you to send any matlab command you like to the host via the established communication. Be aware that the commands need to be entered as strings. The function [printCmd](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/printCmd.m) will do this for you. Use the output from [printCmd](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/printCmd.m) as input for [sendCommand2Host](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Network/ControlComputer/sendCommand2Host.m). E.g. sendCommand2Host(_printCmd([], 'keyBuffer', 10, 'goodkey', (1:3), 'badkey', 4)_);
During the experiment your keyBuffer results will now be saved as variables on the remote host (Raspberry Pi). Do not forget to call getKeyBufferResults on your control computer to transfer these results, otherwise you will not be able to save it. After finishing an experiment and transferring your results always call disconnectFromHost (as implied in 1.4. Function Tree) to shut down the connection as well as the remote host. After disconnecting from a remote host we recommend to reboot the Raspberry before starting a new experiment. Call disconnectFromHost(‘reboot’) to reboot and consider to restart MATLAB or Octave on your local computer.
During the experiment your [keyBuffer](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/IO/keyBuffer.m) results will now be saved as variables on the remote host (Raspberry Pi). Do not forget to call [getKeyBufferResults](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Network/ControlComputer/getKeyBufferResult.m) on your control computer to transfer these results, otherwise you will not be able to save it. After finishing an experiment and transferring your results always call [disconnectFromHost](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Network/ControlComputer/disconnectFromHost.m)(as implied in [1.4. Function Tree](/Getting-started#function-tree)) to shut down the connection as well as the remote host. After disconnecting from a remote host we recommend to reboot the Raspberry before starting a new experiment. Call disconnectFromHost(‘reboot’) to reboot and consider to restart MATLAB or Octave on your local computer.
You can include all of the commands mentioned above in your experimental script on your control computer. When everything is set up you don’t need to do more than running this scrip to conduct an experiment.
...
...
@@ -58,24 +58,59 @@ You can include all of the commands mentioned above in your experimental script
This toolbox comprises the option to communicate between an MRI scanner and an experimental computer. To use this option you need to connect the devices via parallel port and call the functions described below in the correct order.
At first you need to initialize basic functions. Therefore you call initMRIChatPart1. This will start the program triggerCounter2_MCR9-2.exe, which organizes the communication with the parallel port. The program will open an own window displaying user information and the number of triggers sent, their timing and the intervals between scans. After the experiment is done and the window is closed properly the trigger information will be saved to a specific file using the date and time of the experiment as name. The application can be stopped by pressing escape.
At first you need to initialize basic functions. Therefore you call [initMRIChatPart1](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/initMRIChatPart1.m). This will start the program triggerCounter2_MCR9-2.exe, which organizes the communication with the parallel port. The program will open an own window displaying user information and the number of triggers sent, their timing and the intervals between scans. After the experiment is done and the window is closed properly the trigger information will be saved to a specific file using the date and time of the experiment as name. The application can be stopped by pressing escape.
Before continuing you need to open a presentation window (initWindow), this is mandatory for the following functions. After you initialized the presentation window you can call initMRIChatPart2. Here you define the number of scans you want to wait before actually starting the experiment. User information about the overall process will appear on the presentation window automatically.
Before continuing you need to open a presentation window ([initWindow](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Screen/initWindow.m)), this is mandatory for the following functions. After you initialized the presentation window you can call [initMRIChatPart2](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/initMRIChatPart2.m). Here you define the number of scans you want to wait before actually starting the experiment. User information about the overall process will appear on the presentation window automatically.
Lastly if you have to send triggers from the experimental computer to external devices you have to use the function sendTriggerMRI. During an MRI experiment you will not be able to use parChat or parChatWord for trigger events. That is because these functions directly connect to the parallel port, which in this case is being occupied by the program triggerCounter2. In contrast sendTriggerMRI uses the triggerCounter2 application to send triggers via the parallel port.
Lastly if you have to send triggers from the experimental computer to external devices you have to use the function [sendTriggerMRI](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/sendTriggerMRI.m). During an MRI experiment you will not be able to use parChat or parChatWord for trigger events. That is because these functions directly connect to the parallel port, which in this case is being occupied by the program triggerCounter2. In contrast [sendTriggerMRI](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/sendTriggerMRI.m) uses the triggerCounter2 application to send triggers via the parallel port.
The following example provides a very simple MRI experiment that contains all features necessary, as well as the use of [sendTriggerMRI](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/sendTriggerMRI.m) connected to the display of user information. You can use it as baseline for your own experiments.
~~~matlab
%% Example for Scanner
% trigger signal must be set to pin 10 at the parallel port!
%% Init toolbox
initOTBR;
%% Init variables
scans2Wait=4;
%% Init MRI part 1
mmap=initMRIChatPart1;
%% Init screen and wait for scanner to start
initWindow(1);
% Wait for scanner
initMRIChatPart2(mmap,scans2Wait);
showText('Hello');
The following example provides a very simple MRI experiment that contains all features necessary, as well as the use of sendTriggerMRI connected to the display of user information. You can use it as baseline for your own experiments.
When your experiment focuses on a specific time course it may be helpful to mark specific events, such as a stimulus display, with certain event codes, for example triggers. Especially in EEG and MRI experiments it can be very helpful for connecting recordings to behavioral responses. The OTBR toolbox can send triggers from e.g. an experimental computer to a control computer using a parallel port or other supported IO devices. Functions that are capable of using the parallel port directly are sendTriggerMRI, parChat and parChatWord. The first one has been explained in the previous chapter. The other two can be used for example during EEG or other behavioral experiments that use external devices.
When your experiment focuses on a specific time course it may be helpful to mark specific events, such as a stimulus display, with certain event codes, for example triggers. Especially in EEG and MRI experiments it can be very helpful for connecting recordings to behavioral responses. The OTBR toolbox can send triggers from e.g. an experimental computer to a control computer using a parallel port or other supported IO devices. Functions that are capable of using the parallel port directly are [sendTriggerMRI](https://gitlab.ruhr-uni-bochum.de/ikn/OTBR/-/blob/master/Tools/sendTriggerMRI.m), parChat and parChatWord. The first one has been explained in the previous chapter. The other two can be used for example during EEG or other behavioral experiments that use external devices.
The function parChat can activate or deactivate single pins of the parallel port, which can be used as trigger. The function requires one or two input arguments. When two arguments are given the function can be used to activate or deactivate pin 2-9 of the parallel port. The first argument defines the pin (‘1’=pin2, ‘2’=pin3, etc.) the second argument defines the status (on/off). If only one argument is given it can be used to listen to pin 10-15 of the parallel port (‘1’=pin10, ‘2’=pin11, etc.). The following list shows all possible outcomes and the necessary arguments to achieve them.
In contrast to parChat the function parChatWord has the advantage to activate several pins at once. Therefor it uses all 8 bits of the data port (pin 2-9). It needs only one input argument, which is the decimal value of an array representing a binary number. Using this option takes several steps:
First you should think about which pind you want to activate and convert this into an array with 8 digits.
First you should think about which pin you want to activate and convert this into an array with 8 digits.
**Example**
...
...
@@ -102,7 +137,7 @@ Next you have to convert your array into a decimal value. You can use the matlab
**Example**
~~~
~~~matlab
bin2dec(‘01010001’)
ans=81
~~~
...
...
@@ -111,7 +146,7 @@ This also works the opposite way, therefore you need to use dec2bin.
**Example**
~~~
~~~matlab
dec2bin(81,8)
ans=‘01010001’
% the first input argument in the decimal value, the second argument is the minimal amount of digits
...
...
@@ -121,7 +156,7 @@ Now you can use this decimal number as input for parChatWord.
**Example**
~~~
~~~matlab
parChatWord(81)
~~~
:arrow_right: activate pin 2, 6 and 8
...
...
@@ -130,9 +165,9 @@ Finally, you can deactivate all pins at once using ‘0’ as input argument.
**Example**
~~~
~~~matlab
parChatWord(0)
~~~
:arrow_right: deactivate all pins (2-9)
Keep in mind that every option mentioned in this chapter needs a valid connection via parallel port!
\ No newline at end of file
Keep in mind that every option mentioned in this chapter needs a valid connection via parallel port!