From bcd4dae66c187f37e7b92769ec11cef2b6d48086 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 23 Oct 2015 14:46:42 +0100 Subject: mindflex --- src/HW/mindflex/.gitignore | 2 + src/HW/mindflex/document.en.rest.txt | 153 ++++++++++++++++++++++++++++++++++ src/HW/mindflex/document.it.rest.txt | 156 +++++++++++++++++++++++++++++++++++ src/HW/mindflex/du2html.xsl | 1 + 4 files changed, 312 insertions(+) create mode 100644 src/HW/mindflex/.gitignore create mode 100644 src/HW/mindflex/document.en.rest.txt create mode 100644 src/HW/mindflex/document.it.rest.txt create mode 120000 src/HW/mindflex/du2html.xsl diff --git a/src/HW/mindflex/.gitignore b/src/HW/mindflex/.gitignore new file mode 100644 index 0000000..08d33d4 --- /dev/null +++ b/src/HW/mindflex/.gitignore @@ -0,0 +1,2 @@ +/document.en.du.xml +/document.it.du.xml diff --git a/src/HW/mindflex/document.en.rest.txt b/src/HW/mindflex/document.en.rest.txt new file mode 100644 index 0000000..472a19a --- /dev/null +++ b/src/HW/mindflex/document.en.rest.txt @@ -0,0 +1,153 @@ +======================== +Playing with a Mind Flex +======================== +:CreationDate: 2015-10-23 13:11:34 +:Id: HW/mindflex +:tags: - hardware + - software + +Some time ago I bought a `Mind Flex`_, with the idea of interfacing it +to some motors, and control a thing **with my mind**!. + +Of course it sat unused for years. + +Then I got myself a `MicroView`_, because it was pretty. + +Of course it, too, sat unused for years. + +Today I finally put the two together. + +.. _`Mind Flex`: http://store.neurosky.com/products/mindflex +.. _`MicroView`: http://learn.microview.io/Intro/general-overview-of-microview.html + +Software setup +============== + +First of all, I had to set up the Arduino IDE + compilers. On a Gentoo +system it's a bit tricky, but thanks to `a very clear post on the +Apollo NG site`_ I got it installed:: + + emerge arduino crossdev dev-java/rxtx + + USE="multilib -cxx" crossdev -s1 --without-headers \ + --target avr \ + --gcc 4.5.4 --binutils 2.21.1-r1 --libc 1.7.0 + + USE="multilib cxx" crossdev -s4 \ + --target avr \ + --gcc 4.5.4 --binutils 2.21.1-r1 --libc 1.7.0 + + ln -nsf /usr/x86_64-pc-linux-gnu/avr/lib/ldscripts \ + /usr/avr/lib/ldscripts + + ln -nsf /usr/x86_64-pc-linux-gnu/avr/lib/ldscripts \ + /usr/x86_64-pc-linux-gnu/avr/binutils-bin/2.20.1/ldscripts + + cd /usr/avr/lib + + ln -nsf avr5/crtm328p.o . + ln -nsf avr6/crtm2561.o . + ln -nsf avr6/crtm2560.o . + +.. _`a very clear post on the Apollo NG site`: https://apollo.open-resource.org/mission:log:2015:01:20:gentoo-crossdev-compile-avr-gcc-for-arduino-and-cura + +Arduino libraries +----------------- + +I needed two libraries: the one to `read the Neurosky EEG data`_, and +the one to `control the MicroView hardware`_. + +I cloned them in my "sketchbook" directory:: + + mkdir -p ~/sketchbook/libraries + cd ~/sketchbook/libraries + + git clone git@github.com:geekammo/MicroView-Arduino-Library.git \ + MicroView + + git clone git@github.com:kitschpatrol/Brain + +Note that the MicroView library needs to be in a folder called +``MicroView``, not ``MicroView-Arduino-Library``: the Arduino IDE +really dislikes dashes in library names. + +.. _`read the Neurosky EEG data`: https://github.com/kitschpatrol/Brain +.. _`control the MicroView hardware`: https://github.com/geekammo/MicroView-Arduino-Library/ + +Hardware setup +============== + +I followed the instruction at `Frontier Nerds`_, soldering a wire to +the "T" pin of the Neurosky board, one wire to ground, and (my +addition) one wire to battery "+". This way I can power the MicroView +from the same batteries as the Mind Flex: when I tried powering them +separately, the Neurosky board seemed to have serious difficulty +getting a signal, probably because of noise on the power line. + +I then connected (currently via a small breadboard) the MicroView to +the wires: ground to pin 8, power to pin 16, signal to pin 9 (serial +receive). + +.. _`Frontier Nerds`: http://www.frontiernerds.com/brain-hack + +The program +=========== + +This is the very simple program I wrote:: + + #include + #include + + // the MindFlex is connected to the serial input + Brain brain(Serial); + + void setup() { + // the MindFlex speaks 9600 bps + Serial.begin(9600); + // setup the MicroView display + uView.begin(); + uView.clear(ALL); + // use the smallest font, 5x7 + uView.setFontType(0); + } + + const int hist_width=3; + const int hist_pad=1; + + void loop() { + if (brain.update()) { // do we have data to show? + uView.clear(PAGE); + + // print the signal quality, 0=good, 200=no signal + uView.setCursor(0,0); uView.print(brain.readSignalQuality()); + + // print the two "high level" signals + uView.setCursor(0,9); uView.print(brain.readAttention()); + uView.setCursor(18,9); uView.print(brain.readMeditation()); + + // we then have 8 frequency bands + const uint32_t* power = brain.readPowerArray(); + // find the maximum value, for scaling + uint32_t max_value=0; + for (int x=0;x<8;++x) { + if (power[x] > max_value) { + max_value = power[x]; + } + } + + // draw a simple bar chart + for (int x=0;x<8;++x) { + int x0 = (hist_width + hist_pad) * x; + // we have 30 vertical pixels + int height = power[x] * 30 / max_value; + for (int o=0;o + #include + + // il MindFlex è connesso alla seriale + Brain brain(Serial); + + void setup() { + // il MindFlex parla a 9600 bps + Serial.begin(9600); + // prepara il display del MicroView + uView.begin(); + uView.clear(ALL); + // usa il font più piccolo, 5x7 + uView.setFontType(0); + } + + const int hist_width=3; + const int hist_pad=1; + + void loop() { + if (brain.update()) { // abbiamo dati da mostrare? + uView.clear(PAGE); + + // mostra la qualità del segnale, 0=buono, 200=nessun segnale + uView.setCursor(0,0); uView.print(brain.readSignalQuality()); + + // mostra i due segnali di "alto livello" + uView.setCursor(0,9); uView.print(brain.readAttention()); + uView.setCursor(18,9); uView.print(brain.readMeditation()); + + // ci sono poi 8 bande di frequenza + const uint32_t* power = brain.readPowerArray(); + // trova il massimo, per scalarle + uint32_t max_value=0; + for (int x=0;x<8;++x) { + if (power[x] > max_value) { + max_value = power[x]; + } + } + + // disegna un semplice istogramma + for (int x=0;x<8;++x) { + int x0 = (hist_width + hist_pad) * x; + // abbiamo 30 pixel in verticale + int height = power[x] * 30 / max_value; + for (int o=0;o