On the programming side of things, last night I wrote a short, simple sketch to use the Brain Library to retrieve "Signal Strength", "Attention" and "Meditation" values from the TGAM1 chip/board in the headsets. It's intended for use with a direct wired connection to the headset board, but should work with the data stream that you'll receive via Bluetooth, after it's been processed by the Brain Library.
Because this code will run on a small custom Arduino-based board connected directly to the headset board, after extraction using the Brain Library, the data is sent out serially at 19200 baud to an APC220 433MHz RF transceiver module, also in the headset, that will pass it on to a separate "base" board for use in controlling 'whatever'.
S@#t, I'll be happy if I can turn a LED on and off initially, or brighten and dim one with PWM, (first step to motor speed control).
I'm only using the "Signal Strength", "Attention" and "Meditation" values, as mentioned. It's really the "Attention" value that matters at first.
I didn't do it like in the example I posted the other day, which retrieved comma-separated values from the Brain Library in ASCII format, which then had to be re-parsed to extract the values. Way too slow for my liking.
Instead I went for data values only, in "uint8_t" form. Much quicker, and much more usable.
I noticed when reading through the Brain Library files that they didn't clear the error string between packets, so for my purpose I modified their library, at the very beginning of the "Brain::update()" function, to clear any error from parsing the previous packet, with this line:-
Here's the Arduino sketch, in a mix of C and Arduino languages. It compiles fine in the Arduino IDE, but is otherwise untested. (I'll test it for bugs and modify as necessary when my Arduino arrives.)
Note that it's written using the 'SoftwareSerial' library, and not with the hardware serial library, but it's easily converted. I wanted to test out the Arduino 'SoftwareSerial' library.
Pin 5 connects to the TGAM1 board in the headset for receiving the raw data at 9600 baud, and Pin6 connects to the APC220 module for transmitting it to the 'base board' at 19200. I added liberal comments so it's easy for you to follow:-
I haven't written any code for the 'base board' yet. And I'll probably modify this sketch to add 'sync' bytes at the beginning of each 'packet', as qualifiers to know when valid data is arriving. Something simple, like "QUAL", immediately befor the data bytes.
Next up, I'll write a sketch in 'Processing' to take the Brain Library's full-data csv output and display it graphically on the PC screen, for diagnostics and testing. Good, too, for helping to train the brain to concentrate and meditate to improve those aspects for control purposes.
It'll display "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma".
This is the format of the data from the Brain Library:-
200,0,0,70022,1415627,296609,25469,7758,19291,6073,220596
I've never used 'Processing' before, apart from a quick test a few days ago, but I'll soon get the hang of it, (I hope).
Because this code will run on a small custom Arduino-based board connected directly to the headset board, after extraction using the Brain Library, the data is sent out serially at 19200 baud to an APC220 433MHz RF transceiver module, also in the headset, that will pass it on to a separate "base" board for use in controlling 'whatever'.
S@#t, I'll be happy if I can turn a LED on and off initially, or brighten and dim one with PWM, (first step to motor speed control).
I'm only using the "Signal Strength", "Attention" and "Meditation" values, as mentioned. It's really the "Attention" value that matters at first.
I didn't do it like in the example I posted the other day, which retrieved comma-separated values from the Brain Library in ASCII format, which then had to be re-parsed to extract the values. Way too slow for my liking.
Instead I went for data values only, in "uint8_t" form. Much quicker, and much more usable.
I noticed when reading through the Brain Library files that they didn't clear the error string between packets, so for my purpose I modified their library, at the very beginning of the "Brain::update()" function, to clear any error from parsing the previous packet, with this line:-
Code:
latestError[0]='\0';
Here's the Arduino sketch, in a mix of C and Arduino languages. It compiles fine in the Arduino IDE, but is otherwise untested. (I'll test it for bugs and modify as necessary when my Arduino arrives.)
Note that it's written using the 'SoftwareSerial' library, and not with the hardware serial library, but it's easily converted. I wanted to test out the Arduino 'SoftwareSerial' library.
Pin 5 connects to the TGAM1 board in the headset for receiving the raw data at 9600 baud, and Pin6 connects to the APC220 module for transmitting it to the 'base board' at 19200. I added liberal comments so it's easy for you to follow:-
Code:
// MyBrainLibTest.ino
// My first Brain Library test.
// Written by Steve Carroll, 12.9.2015.
#include <Brain.h>
#include <SoftwareSerial.h>
SoftwareSerial MySerial(5,6); // RX on p5, TX on p6.
Brain TestBrain(MySerial);
uint8_t BrainBands[3]; // An array to hold the data.
void setup()
{
MySerial.begin(9600);
}
void loop()
{
if(TestBrain.update()) // Get the latest headset data.
{
char* pErrors=TestBrain.readErrors(); // Only use the data if there were no errors.
if(strcmp(pErrors,"")==0)
{ // Collect the required data from the library:-
BrainBands[0]=TestBrain.readSignalQuality();
BrainBands[1]=TestBrain.readAttention();
BrainBands[2]=TestBrain.readMeditation();
SendDataOut();
}
}
}
void SendDataOut()
{
MySerial.end(); // Close the serial port and
MySerial.begin(19200); // change to 19200 baud.
MySerial.write(BrainBands,3); // Send the data to the APC220 module.
MySerial.end(); // Close the serial port and
MySerial.begin(9600); // change back to 9600 baud.
}
I haven't written any code for the 'base board' yet. And I'll probably modify this sketch to add 'sync' bytes at the beginning of each 'packet', as qualifiers to know when valid data is arriving. Something simple, like "QUAL", immediately befor the data bytes.
Next up, I'll write a sketch in 'Processing' to take the Brain Library's full-data csv output and display it graphically on the PC screen, for diagnostics and testing. Good, too, for helping to train the brain to concentrate and meditate to improve those aspects for control purposes.
It'll display "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma".
This is the format of the data from the Brain Library:-
200,0,0,70022,1415627,296609,25469,7758,19291,6073,220596
I've never used 'Processing' before, apart from a quick test a few days ago, but I'll soon get the hang of it, (I hope).
Last edited: