Analog Input Module Serial Interface

Description

Allows the state machine or PC to acquire analog waveforms and extract voltage threshold events using the analog input module.

Requires an analog input module board with firmware loaded from:

The analog input module must be connected to a free serial port on the state machine module.

State Machine Command Interface

The state machine command interface consists of bytes sent from the Bpod state machine to the analog input module to start and stop acquisition, data streaming or threshold event transmission.

SerialUSB Command Interface

The SerialUSB command interface allows configuration of the analog input module with MATLAB or Python before a trial begins. It also allows data return from the module's onboard microSD card. The BpodAnalogIn plugin for Bpod/MATLAB wraps this interface. The first two commands are the same as for the state machine interface (though an acknowledgement byte = 1 is returned in each case), and additional commands follow:

Examples

1. % Acquire 1 channel of analog data at 10kHz from an ArCOM serial object in MATLAB: 

A = ArCOMObject('COM43', 115200);

A.write(['A' 1], 'uint8'); % Set the module to read only 1 channel (channel 1)

A.write('F', 'uint8', 10000, 'uint32'); % Set the module to sample at 10kHz

A.write(['L' 1], 'uint8'); % Start logging

Ack = A.read(3, 'uint8'); % Read acknowledgement bytes

pause(1); % Wait 1 second for data to be acquired

A.write(['L' 0], 'uint8'); % Stop logging

A.write('D', 'uint8'); % Request logged data

nSamples = A.read(1, 'uint32'); % read the number of samples acquired

Data = A.read(nSamples , 'uint32'); % read the data

clear A


2. % Start+Stop logging analog data from the Bpod state machine, when the subject enters+exits port 2

% (Assuming the subject has run Bpod and created a BpodAnalogIn object called A

LoadSerialMessages('AnalogIn1', {['L' 1], ['L' 0]});  % Set serial messages 1+2 to start+stop logging

sma = NewStateMachine();

sma = AddState(sma, 'Name', 'WaitForPort2Entry', ...

    'Timer', 0,...

    'StateChangeConditions', {'Port2In', 'WaitForPort2Exit'},...

    'OutputActions', {}); % Sends serial message 1 (Start logging)

sma = AddState(sma, 'Name', 'WaitForPort2Exit', ...

    'Timer', 0,...

    'StateChangeConditions', {'Port2Out', 'StopLogging'},...

    'OutputActions', {'AnalogIn1', 1}); % Sends serial message 1 (Start logging)

sma = AddState(sma, 'Name', 'StopLogging', ...

    'Timer', 0,...

    'StateChangeConditions', {'Tup', 'exit'},...

    'OutputActions', {'AnalogIn1', 2}); % Sends serial message 2 (Stop logging)

SendStateMachine(sma);

RawEvents = RunStateMachine;

Data = A.getData; % Now that the trial has ended, get data acquired while the subject was in the port