![]() |
Reading real-time data from analog input module - Printable Version +- Forums (https://sanworks.io/forum) +-- Forum: Bpod (https://sanworks.io/forum/forumdisplay.php?fid=1) +--- Forum: Software (https://sanworks.io/forum/forumdisplay.php?fid=6) +--- Thread: Reading real-time data from analog input module (/showthread.php?tid=923) |
Reading real-time data from analog input module - tly627 - 08-29-2020 Hi Josh, I am now trying to record analog signals from a joystick using the analog input modules and send these data to a PC (MATLAB) to control the movement of a virtual object on the screen in real-time. I have read the Bpod wiki and learned that the way to do this should probably be using the 'startUSBStream()' function within 'BpodAnalogIn'. However, I am a bit confused about the data that obj.Port.read(nActiveChannels, 'uint16') returns. Does each columns represent the sample from each channels? If that's the case, I am not sure why the values of the bits aren't changing when I push the joystick. I have used the GUI of 'scope()' to verify that my joystick is functioning so it shouldn't be a hardware problem. Alternatively, do you know if there is a better way to achieve my goal? Thank you in advance! Best, Tin RE: Reading real-time data from analog input module - Josh - 08-30-2020 Hi Tin, The format of the data stream for each sample is: R[XY] where R is character 'R' (byte 0x82) and XY are two bytes representing an unsigned 16-bit integer for each channel that is enabled. So if 3 channels are enabled (you'd have to keep track of which 3) and there are two samples in the buffer you'll get: RXYXYXYRXYXYXY... Lines 860-873 of BpodAnalogIn.m provide one way of parsing the data - and I'm sure it can be done more efficiently depending on your application. I hope this helps! -Josh RE: Reading real-time data from analog input module - tly627 - 09-01-2020 Thank you very much Josh! Best, Tin |