{"id":913,"date":"2012-03-15T16:00:56","date_gmt":"2012-03-15T08:00:56","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=913"},"modified":"2012-03-15T16:08:43","modified_gmt":"2012-03-15T08:08:43","slug":"neurosky-mindwave-and-processing","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2012\/03\/15\/neurosky-mindwave-and-processing\/","title":{"rendered":"Neurosky MindWave and Processing"},"content":{"rendered":"<p>This is my first trial run of a <a href=\"http:\/\/neurosky.com\/Products\/MindWave.aspx\">Neurosky MindWave<\/a> sensor with a custom program written in <a href=\"http:\/\/www.processing.org\">Processing<\/a>. The connection architecture is quite straight forward. The <a href=\"http:\/\/developer.neurosky.com\/docs\/doku.php?id=thinkgear_connector_tgc\">ThinkGear connector<\/a> is a background process that reads from the IR serial port to obtain the brainwave signals and distributes them through a TCP socket server (localhost with port 13854).<br \/>\n&nbsp;<br \/>\n<iframe loading=\"lazy\" width=\"480\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/r_MjjnCMDHQ?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><br \/>\n&nbsp;<br \/>\nThere are a number of Java socket clients implementation. I use the <a href=\"http:\/\/crea.tion.to\/processing\/thinkgear-java-socket\">ThinkGear Java<\/a> library from <a href=\"http:\/\/crea.tion.to\/\">Creation<\/a>.<\/p>\n<p><a href=\"http:\/\/eric-blue.com\/\">Eric Blue<\/a> has another <a href=\"http:\/\/eric-blue.com\/2011\/07\/13\/neurosky-brainwave-visualizer\/\">Processing based visualizer<\/a> using the MindWave.<\/p>\n<p><a href=\"http:\/\/www.zeroshore.com\/\">ZeroShore<\/a> has another implementation with an animation called <a href=\"http:\/\/www.zeroshore.com\/2011\/06\/playing-around-with-neurosky-and-processing\/\">HyperCat<\/a>.<br \/>\n&nbsp;<br \/>\n<strong>Sample Code<\/strong><\/p>\n<pre lang=\"java\">\r\nimport processing.video.*;\r\nimport neurosky.*;\r\nimport org.json.*;\r\n\r\nThinkGearSocket neuroSocket;\r\nint attention = 0;\r\nint meditation = 0;\r\nint blinkSt = 0;\r\nPFont font;\r\nint blink = 0;\r\nCapture cap;\r\n\r\nvoid setup() \r\n{\r\n  size(640, 480);\r\n  ThinkGearSocket neuroSocket = new ThinkGearSocket(this);\r\n  try \r\n  {\r\n    neuroSocket.start();\r\n  } \r\n  catch (ConnectException e) {\r\n    e.printStackTrace();\r\n  }\r\n  smooth();\r\n  font = loadFont(\"MyriadPro-Regular-24.vlw\");\r\n  textFont(font);\r\n  frameRate(25);\r\n  cap = new Capture(this, width, height);\r\n  noStroke();\r\n}\r\n\r\nvoid draw() \r\n{\r\n  background(0);\r\n\r\n  image(cap, 0, 0);\r\n  fill(255, 255, 0);\r\n  text(\"Attention: \"+attention, 20, 150);\r\n  fill(255, 255, 0, 160);\r\n  rect(200, 130, attention*3, 40);\r\n  fill(255, 255, 0);\r\n  text(\"Meditation: \"+meditation, 20, 250);\r\n  fill(255, 255, 0, 160);\r\n  rect(200, 230, meditation*3, 40);\r\n\r\n  if (blink>0) \r\n  {\r\n    fill(255, 255, 0);\r\n    text(\"Blink: \" + blinkSt, 20, 350);\r\n    if (blink>15) \r\n    {\r\n      blink = 0;\r\n    } \r\n    else \r\n    {\r\n      blink++;\r\n    }\r\n  }\r\n}\r\n\r\nvoid captureEvent(Capture _c) \r\n{\r\n  _c.read();\r\n}\r\n\r\nvoid attentionEvent(int attentionLevel) \r\n{\r\n  attention = attentionLevel;\r\n}\r\n\r\nvoid meditationEvent(int meditationLevel) \r\n{\r\n  meditation = meditationLevel;\r\n}\r\n\r\nvoid blinkEvent(int blinkStrength) \r\n{\r\n  blinkSt = blinkStrength;\r\n  blink = 1;\r\n}\r\n\t\r\nvoid stop() {\r\n  neuroSocket.stop();\r\n  super.stop();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is my first trial run of a Neurosky MindWave sensor with a custom program written in Processing. The connection architecture is quite straight forward. The ThinkGear connector is a background process that reads from the IR serial port to obtain the brainwave signals and distributes them through a TCP socket server (localhost with port [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,66],"tags":[95,62],"class_list":["post-913","post","type-post","status-publish","format-standard","hentry","category-research","category-testing","tag-mindwave","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=913"}],"version-history":[{"count":4,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/913\/revisions"}],"predecessor-version":[{"id":917,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/913\/revisions\/917"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=913"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}