{"id":1238,"date":"2011-12-14T00:00:13","date_gmt":"2011-12-13T23:00:13","guid":{"rendered":"http:\/\/blogs.ukoln.ac.uk\/ukolndev\/?p=1238"},"modified":"2014-01-07T21:42:44","modified_gmt":"2014-01-07T21:42:44","slug":"blink-detection-and-attention-evaluation-the-neurosky-mindwave","status":"publish","type":"post","link":"https:\/\/www.emmatonkin.com\/ukolndev\/2011\/12\/14\/blink-detection-and-attention-evaluation-the-neurosky-mindwave\/","title":{"rendered":"Blink detection and attention evaluation: the NeuroSky MindWave"},"content":{"rendered":"<h2>Hardware for UX evaluation<\/h2>\n<p>As part of Project Sunflower, we took various approaches to interface evaluation. Alongside heuristic evaluation, walkthroughs and so forth, we also used various bits of hardware to support trials. This post describes setup and sample code for the NeuroSky MindWave, an inexpensive BCI (brain-computer interface &#8211; think &#8216;electroencephalogram&#8217;, or &#8216;brain wave monitoring&#8217;) that uses a single sensor placed on the forehead to measure eye blinks, &#8216;attention&#8217; and &#8216;meditation&#8217;. These two latter variables shouldn&#8217;t be taken at (scuse the pun) face value; according to a report by Travis Ross, they&#8217;re based on a <a href=\"http:\/\/www.motivateplay.com\/2011\/03\/gdc-wednesday-neuroskys-eeg-controller\/\">proprietary algorithm<\/a>, with attention reported to relate to beta waves, hence linked to wakefulness\/focus, and meditation linked to alpha waves &#8211; level of calm. Vague, admittedly, but then these devices are priced for and in large part targeted at the consumer market. If you&#8217;ve ever seen those <a href=\"http:\/\/company.neurosky.com\/products\/force-trainer\/\">Mattel Jedi force-trainer toys,<\/a> those are based around the same technology.<\/p>\n<h2>Setup<\/h2>\n<p>Having installed the software prerequisites and drivers, the next thing is to run the Thinkgear Connector. This is an extremely helpful little piece of kit, which listens to the USB radio link and makes the sensor data available to applications. This reduces the connection step to a couple of lines of code. Since the Thinkgear Connector will return JSON upon request, the data packets are easy to parse.<\/p>\n<h2>Code<\/h2>\n<pre>import sys\r\nimport json\r\nimport time\r\nfrom telnetlib import Telnet\r\n\r\ntn=Telnet('localhost',13854);\r\nstart=time.clock();\r\n\r\ni=0;\r\n# app registration step (in this instance unnecessary)\r\n#\u00a0tn.write('{\"appName\": \"Example\", \"appKey\": \"9f54141b4b4c567c558d3a76cb8d715cbde03096\"}');\r\ntn.write('{\"enableRawOutput\": true, \"format\": \"Json\"}');\r\n\r\noutfile=\"null\";\r\nif len(sys.argv)&gt;1:\r\n        outfile=sys.argv[len(sys.argv)-1];\r\n        outfptr=open(outfile,'w');\r\n\r\n#\u00a0default values\r\neSenseDict={'attention':0, 'meditation':0};\r\nwaveDict={'lowGamma':0, 'highGamma':0, 'highAlpha':0, 'delta':0, 'highBeta':0, 'lowAlpha':0, 'lowBeta':0, 'theta':0};\r\nsignalLevel=0;\r\n\r\nwhile i<\/pre>\n<p>(Edit: The above code is truncated. See <a href=\"https:\/\/github.com\/etonkin\/neurosky-telnet\">https:\/\/github.com\/etonkin\/neurosky-telnet<\/a> for full code)<\/p>\n<h2>Example output<\/h2>\n<p>The code as written above produces very simple CSV output, which has the benefit of being very easy to plot using something like Gnuplot:<\/p>\n<pre>plot \"test-output.log\" using 1:3 with lines, \"\" using 1:4 with lines, \"\" using 1:5 with lines<\/pre>\n<table style=\"border: 0;\">\n<tbody>\n<tr>\n<td>\n<p><div id=\"attachment_1245\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.emmatonkin.com\/ukolndev\/wp-content\/uploads\/sites\/2\/2011\/12\/grammar1.png\"><img aria-describedby=\"caption-attachment-1245\" class=\"wp-image-1245\" title=\"Working on a language problem.\" alt=\"Graph of three variables: working on a language problem.\" src=\"http:\/\/www.emmatonkin.com\/ukolndev\/wp-content\/uploads\/sites\/2\/2011\/12\/grammar1.png\" width=\"300\" \/><\/a><p id=\"caption-attachment-1245\" class=\"wp-caption-text\">Some sensor data captured: subject was working on a language problem. Red<\/p><\/div><\/td>\n<td>\n<p><div id=\"attachment_1246\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.emmatonkin.com\/ukolndev\/wp-content\/uploads\/sites\/2\/2011\/12\/watchingtv1.png\"><img aria-describedby=\"caption-attachment-1246\" class=\"wp-image-1246\" title=\"Watching TV\" alt=\"Sensor data. Activity: Watching TV\" src=\"http:\/\/www.emmatonkin.com\/ukolndev\/wp-content\/uploads\/sites\/2\/2011\/12\/watchingtv1.png\" width=\"300\" \/><\/a><p id=\"caption-attachment-1246\" class=\"wp-caption-text\">Sensor data captured: individual was watching TV. Red<\/p><\/div><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note: the number of blinks captured is low enough that the chances are that the MindWave is not picking up all blink events.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hardware for UX evaluation As part of Project Sunflower, we took various approaches to interface evaluation. Alongside heuristic evaluation, walkthroughs and so forth, we also used various bits of hardware to support trials. This post describes setup and sample code for the NeuroSky MindWave, an inexpensive BCI (brain-computer interface &#8211; think &#8216;electroencephalogram&#8217;, or &#8216;brain wave [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,9,13,14,17],"tags":[29,176,46,54,170,66,70,78,82,92],"_links":{"self":[{"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/posts\/1238"}],"collection":[{"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/comments?post=1238"}],"version-history":[{"count":6,"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/posts\/1238\/revisions"}],"predecessor-version":[{"id":1991,"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/posts\/1238\/revisions\/1991"}],"wp:attachment":[{"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/media?parent=1238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/categories?post=1238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.emmatonkin.com\/ukolndev\/wp-json\/wp\/v2\/tags?post=1238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}