Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
199 views3 pages

Matlab Meditation Data Reader

This Matlab code connects to a Neurosky Mindwave Mobile headset via serial port to read meditation levels. It loads the ThinkGear DLL, connects to the specified COM port, reads packets in a loop and plots the meditation value data in real-time. On completion, it releases the serial port connection.

Uploaded by

Muthukumaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
199 views3 pages

Matlab Meditation Data Reader

This Matlab code connects to a Neurosky Mindwave Mobile headset via serial port to read meditation levels. It loads the ThinkGear DLL, connects to the specified COM port, reads packets in a loop and plots the meditation value data in real-time. On completion, it releases the serial port connection.

Uploaded by

Muthukumaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

4/4/2016

MatlabcodetoreadMeditationusingMindwaveMobile

MatlabcodetoreadMeditationusingMindwavemobile

%ClearScreen
clc
%ClearVariables
clearall
%Closefigures
closeall

%Preallocatebuffer
data_med=zeros(1,256)

%ComportSelection
portnum1=7
%COMPort#
comPortName1=sprintf('\\\\.\\COM%d',portnum1)

%BaudrateforusewithTG_Connect()andTG_SetBaudrate().
TG_BAUD_115200=115200

%DataformatforusewithTG_Connect()andTG_SetDataFormat().
TG_STREAM_PACKETS=0
%DatatypethatcanberequestedfromTG_GetValue().

TG_DATA_MEDITATION=3

%loadthinkgeardll
loadlibrary('Thinkgear.dll')

%TodisplayinCommandWindow
fprintf('Thinkgear.dllloaded\n')

%getdllversion
dllVersion=calllib('Thinkgear','TG_GetDriverVersion')

%Todisplayincommandwindow
fprintf('ThinkGearDLLversion:%d\n',dllVersion)

%GetaconnectionIDhandletoThinkGear
connectionId1=calllib('Thinkgear','TG_GetNewConnectionId')
if(connectionId1<0)
https://www.pantechsolutions.net/matlabcodetoreadmeditationusingmindwavemobile

1/3

4/4/2016

MatlabcodetoreadMeditationusingMindwaveMobile

error(sprintf('ERROR:TG_GetNewConnectionId()returned%d.\n',connectionId1))
end

%AttempttoconnecttheconnectionIDhandletoserialport"COM3"

errCode

calllib('Thinkgear',

'TG_Connect',

connectionId1,comPortName1,TG_BAUD_115200,TG_STREAM_PACKETS)
if(errCode<0)
error(sprintf('ERROR:TG_Connect()returned%d.\n',errCode))
end

fprintf('Connected.ReadingPackets...\n')

i=0
j=0

%TodisplayinCommandWindow

disp('ReadingBrainwaves')

figure
whilei<20
if(calllib('Thinkgear','TG_ReadPackets',connectionId1,1)==1)%ifapacketwasread...
if(calllib('Thinkgear','TG_GetValueStatus',connectionId1,TG_DATA_MEDITATION)~=0)
j=j+1
i=i+1
%ReadattentionValusfromthinkgearpackets
data_med(j)=calllib('Thinkgear','TG_GetValue',connectionId1,TG_DATA_MEDITATION)
%TodisplayinCommandWindow
disp(data_med(j))
%PlotGraph
plot(data_med)

title('Meditation')
%Delaytodisplaygraph
pause(1)
end
end
end

%TodisplayinCommandWindow
disp('LoopCompleted')
https://www.pantechsolutions.net/matlabcodetoreadmeditationusingmindwavemobile

2/3

4/4/2016

MatlabcodetoreadMeditationusingMindwaveMobile

%Releasethecommport
calllib('Thinkgear','TG_FreeConnection',connectionId1)

https://www.pantechsolutions.net/matlabcodetoreadmeditationusingmindwavemobile

3/3

You might also like