i cant get attention and meditation level from neurosky mindwave mobile.

the link i follow to get those attention and meditation level.

circuit connection :

arduino mega2560 ------- bluetooth module BC417

  1. vcc(5v) ----- ------- vcc
    2.gnd --------------- gnd
  2. tx (tx0) -------------rx
  3. 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.

#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
}

Very similar thread here