Go Down

Topic: unable to print alpha beta etc values from Nuerosky mind wave mobile (Read 206 times) previous topic - next topic

Yashaswi

im using HC-05 to communicate with EEG sensor, i'm using the below code for that With arduino MEGA. But nothing prints in serial monitor why?


 
int LED = 8;                    // yellow one
int LED1 = 7;                   //white one
int BAUDRATE = 57600;

// checksum variables
byte payloadChecksum = 0;
byte CalculatedChecksum;
byte checksum = 0;              //data type byte stores an 8-bit unsigned number, from 0 to 255
int payloadLength = 0;
byte payloadData[64] = {0};
byte poorQuality = 0;
byte attention = 0;
byte meditation = 0;

// system variables
long lastReceivedPacket = 0;
boolean bigPacket = false;
boolean brainwave = false;
void setup() {
  pinMode(LED, OUTPUT);
  pinMode(LED1, OUTPUT);
  digitalWrite(LED, HIGH);   // hello sequence
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
  Serial.begin(57600);       
  delay(500);
  Serial1.begin(57600);     
  delay(500);
  Serial1.print("Communicating... ");
  Serial1.println();
}
byte ReadOneByte() {
   int ByteRead;
  // Wait until there is data
  while(!Serial.available());
  //Get the number of bytes (characters) available for reading from the serial port.
  //This is data that's already arrived and stored in the serial receive buffer (which holds 64 bytes)
  ByteRead = Serial.read();
  return ByteRead; // read incoming serial data
  }

unsigned int delta_wave = 0;
unsigned int theta_wave = 0;
unsigned int low_alpha_wave = 0;
unsigned int high_alpha_wave = 0;
unsigned int low_beta_wave = 0;
unsigned int high_beta_wave = 0;
unsigned int low_gamma_wave = 0;
unsigned int mid_gamma_wave = 0;

void read_waves(int i) {
  delta_wave = read_3byte_int(i);
  i+=3;
  theta_wave = read_3byte_int(i);
  i+=3;
  low_alpha_wave = read_3byte_int(i);
  i+=3;
  high_alpha_wave = read_3byte_int(i);
  i+=3;
  low_beta_wave = read_3byte_int(i);
  i+=3;
  high_beta_wave = read_3byte_int(i);
  i+=3;
  low_gamma_wave = read_3byte_int(i);
  i+=3;
  mid_gamma_wave = read_3byte_int(i);
}

int read_3byte_int(int i) {
  return ((payloadData << 16) + (payloadData[i+1] << 8) + payloadData[i+2]);
}

void loop() {
  // Look for sync bytes
  // Byte order: 0xAA, 0xAA, payloadLength, payloadData,
  // Checksum (sum all the bytes of payload, take lowest 8 bits, then bit inverse on lowest
if(ReadOneByte() == 0xAA) {
if(ReadOneByte() == 0xAA) {
payloadLength = ReadOneByte();
if(payloadLength > 169) //Payload length can not be greater than 169
return;
payloadChecksum = 0;
      for(int i = 0; i < payloadLength; i++) {      //loop until payload length is complete
        payloadData = ReadOneByte();             //Read payload
        payloadChecksum += payloadData;
      }
      checksum = ReadOneByte();                     //Read checksum byte from stream
      payloadChecksum = 255 - payloadChecksum;      //Take one's compliment of generated checksum
      if(checksum == payloadChecksum) {
        poorQuality = 200;
        attention = 0;
        meditation = 0;
 }
     brainwave = false;
     for(int i = 0; i < payloadLength; i++) { // Parse the payload
          switch (payloadData) {
          case 02:
            i++;
            poorQuality = payloadData;
            bigPacket = true;
            break;
          case 04:
            i++;
            attention = payloadData;
            break;
          case 05:
            i++;
            meditation = payloadData;
            break;
          case 0x80:
            i = i + 3;
            break;
          case 0x83:                         // ASIC EEG POWER INT
            i++;
            brainwave = true;
            byte vlen = payloadData;
            //Serial1.print(vlen, DEC);
            //Serial1.println();
            read_waves(i+1);
            i += vlen; // i = i + vlen
            break;
          }                                 // switch
        }                                   // for loop

        if(bigPacket) {
          if(poorQuality == 0){
          }
          else{                             // do nothing
           }
         }


            if(brainwave && attention > 0 && attention < 100) {
            Serial1.print("Attention value is: ");
            Serial1.print(attention, DEC);
            Serial1.println();
            Serial1.print("Delta value is: ");
            Serial1.print(delta_wave, DEC);
            Serial1.println();
            Serial1.print("Theta value is: ");
            Serial1.print(theta_wave, DEC);
      Serial1.println();
            Serial1.print("Low Alpha value is: ");
            Serial1.print(low_alpha_wave, DEC);
            Serial1.println();
            Serial1.print("High Alpha value is: ");
            Serial1.print(high_alpha_wave, DEC);
            Serial1.println();           
            Serial1.print("Alertness value1 is: ");
            Serial1.print(low_beta_wave, DEC);
            Serial1.println();
            Serial1.print("Alertness value2 is: ");
            Serial1.print(high_beta_wave, DEC);
            Serial1.println();           
            Serial1.print(low_gamma_wave, DEC);
            Serial1.println();
            Serial1.print(mid_gamma_wave, DEC);
            Serial1.println();
         }

          if(attention > 40){
            digitalWrite(LED1, HIGH);
          }
          else
            digitalWrite(LED1, LOW);
        }
        }
      }

marwannafea

Make sure that the baud rate in the serial monitor is set to 57600

Make sure that RX Arduino is connected to TX HC-05

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Make sure that the baud rate in the serial monitor is set to 57600

Make sure that RX Arduino is connected to TX HC-05
Definitely a good place to start.

What pins do you have the Bluetooth module connected to and has it paired with the sensors Bluetooth unit?

Can you post a link to the heartbeat sensor please?

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

ardly

Put print statements throughout your code so that you can see where it is and what it is actually doing.
"Facts do not cease to exist because they are ignored" - Aldous Huxley

Go Up