Dear Dr Sanders,
I hope you’re well! I have a few questions about the BPod system that I was hoping you could help me with.
We’ve currently set up the hardware for the BPod and are able to run example behavioural protocols such as the Auditory Go/NoGo protocol that is used in the Kepecs lab (Hyun Jae was kind enough to send us the example script). In their protocol, they only use a single stimulus (auditory) and this is presented via the ASUS sound card (which we also have).
For my particular experiments, I would like to run 2 stimulus modalities - tactile (vibrating button) and auditory. At the moment, we are able to use a TTL trigger (BNCState) on BPod to present the tactile stim through an external Arduino Uno, and use the same code as Hyun Jae’s to present the auditory stim (via the soundcard).
The arduino running the tactile stimulus listens for a TTL trigger then plays a hard coded square wave through our stimulus. This means that I can only present 1 vibration frequency via the Arduino, when ideally, I’d like to randomly present 1 frequency (out of a pool of 5-6) per trial.
We’re trying to work out a way to get the BPod to communicate with the external Arduino to send instructions about which frequency to play on every trial. We thought the simplest approach would be to open serial port (MATLABs serial function) and write values to our stimulus Arduino. Our communications with the Arduino are working as expected, we can update the parameters of the square wave in this way reliably. We’ve then tried to incorporate this into our bpod protocol, creating an output function argument in AddState to allow us to call a function that would send values to Arduino. We modified the AddState function to additionally check to see if the key value pair are in a list of strings, which include the function name we want to call. If so, we run evalin on the value, assuming that we passed our function at that point
%%From AddState.m lines 122 - 147
%% Add output actions
OutputActionNames = BpodSystem.OutputActionNames;
%TODO: link to a list of available functions
OutputFunctionNames = {'Hi' , 'VibGenerator' } % Our functions
for x = 1:2:length(OutputActions)
Value = OutputActions{x+1};
TargetEventCode = find(strcmp(OutputActions{x}, OutputActionNames));
if ~isempty(TargetEventCode)
sma.OutputMatrix(CurrentState,TargetEventCode) = Value;
else
TargetEventCode = find(strcmp(OutputActions{x}, OutputFunctionNames));
if ~isempty(TargetEventCode)
evalin('base', Value) %if value exists it must be a function....
% do Output_function
else
error(['Check spelling of your output actions for state: ' sma.StateNames{x} '.']);
end
end
end
We tested this part of the code, and found that we could run MATLAB functions in this way. We tested with a simple function that just printed “Hi” to the command window.
We next tried to run a function (VibeGenerator) from this code. We used our modified AddState to call our function to communicate with our Arduino. This failed because the serialport object (ser) was created outside the functions workspace, in the workspace of the AddState function. We tried to open our serial port object in the base workspace, and to use evalin(... 'base'), neither of these worked.
So basically I think what we want to know is how can we open our serial port object once, and still have it available to a function called by Bpod?
Would you happen to have any advice/example code about how to get this running? We’d really appreciate any information you could provide. Thanks so much for your time!
We have included the files that we attempted to modify/create, in case that helps.
Kind regards,
Dasuni Alwis