here's the link Interfacing Mindwave Mobile with Arduino
circuit connection :
arduino mega2560 ------- bluetooth module BC417
- vcc(5v) ----- ------- vcc
-2.gnd --------------- gnd - tx (tx0) -------------rx
- rx ( rx0 )--------------tx
after wearing the head set the poor quality level is reducing 200 to 0 but the attention and meditation level remains always 0 since last packet is always more than 1500 ms.
heres the main code of connection:
#define BAUDRATE 57600
#define DEBUGOUTPUT 0
#define powercontrol 10
// checksum variables
byte generatedChecksum = 0;
byte checksum = 0;
int payloadLength = 0;
byte payloadData[64] = {0};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;
// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;
void setup()
{
Serial.begin(BAUDRATE); // USB
}
byte ReadOneByte()
{
int ByteRead;
while(!Serial.available());
ByteRead = Serial.read();
#if DEBUGOUTPUT
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug purposes)
#endif
return ByteRead;
}
void loop()
{
// Look for sync bytes
if(ReadOneByte() == 170)
{
if(ReadOneByte() == 170)
{
payloadLength = ReadOneByte();
if(payloadLength > 169) //Payload length can not be greater than 169
return;
generatedChecksum = 0;
for(int i = 0; i < payloadLength; i++)
{
payloadData = ReadOneByte(); //Read payload into memory
_ generatedChecksum += payloadData*;_
_ } _
_ checksum = ReadOneByte(); //Read checksum byte from stream _
_ generatedChecksum = 255 - generatedChecksum; //Take one's compliment of generated checksum*_
* if(checksum == generatedChecksum)*
* { *
* poorQuality = 200;*
* attention = 0;*
* meditation = 0;*
* for(int i = 0; i < payloadLength; i++)*
* { // Parse the payload*
_ switch (payloadData*)
{
case 2:
i++;
poorQuality = payloadData;
bigPacket = true;
break;
case 4:
i++;
attention = payloadData;
break;
case 5:
i++;
meditation = payloadData;
break;
case 0x80:
i = i + 3;
break;
case 0x83:
i = i + 25;
break;
default:
break;
} // switch*
* } // for loop*
#if !DEBUGOUTPUT
// *** Add your code here
if(bigPacket)
{*_
* Serial.print("PoorQuality: ");*
* Serial.print(poorQuality, DEC);*
* Serial.print(" Attention: ");*
* Serial.print(attention, DEC);*
* Serial.print(" Time since last packet: ");*
* Serial.print(millis() - lastReceivedPacket, DEC);*
* lastReceivedPacket = millis();*
* Serial.print("\n");*
* switch(attention / 10)*
* {*
* } *
* }*
*#endif *
* bigPacket = false; *
* }*
* else {*
* // Checksum Error*
* } // end if else for checksum*
* } // end if read 0xAA byte*
} // end if read 0xAA byte
}