Compare commits

...

2 commits

Author SHA1 Message Date
Vojtěch Pour a53555446e Added quick start guide. 2022-11-18 21:08:58 +01:00
Vojtěch Pour 713ace2919 Added quick guide 2022-11-18 21:08:37 +01:00
3 changed files with 110 additions and 1 deletions

View file

@ -1,3 +1,4 @@
# Neurosky Mindwave M5Stack Core2 connection
- Neusky Mindwave MAC Address: 98:07:2d:7f:ea:15
- documentation: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol
- documentation: http://developer.neurosky.com/docs/doku.php?id=thinkgear_communications_protocol
- quick start guide: http://download.neurosky.com/public/Products/MindWave%20Mobile%202/MindWave%20Mobile%202%20Quick%20Start%20Guide.pdf

107
parser/core2_C_Parser.ino Normal file
View file

@ -0,0 +1,107 @@
#define BAUDRATE 57600
#define DEBUGOUTPUT 0
// 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;
//////////////////////////
// Microprocessor Setup //
//////////////////////////
void setup(){
Serial1.begin(BAUDRATE); // Serial port 1 (ATMEGA2560)
Serial.begin(BAUDRATE); // USB
}
////////////////////////////////
// Read data from Serial UART //
////////////////////////////////
byte ReadOneByte() {
int ByteRead;
while(!Serial1.available());
ByteRead = Serial1.read();
#if DEBUGOUTPUT
Serial.print((char)ByteRead); // echo the same byte out the USB serial (for debug purposes)
#endif
return ByteRead;
}
/////////////
//MAIN LOOP//
/////////////
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[i] = ReadOneByte(); //Read payload into memory
generatedChecksum += payloadData[i];
}
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[i]) {
case 2:
i++;
poorQuality = payloadData[i];
bigPacket = true;
break;
case 4:
i++;
attention = payloadData[i];
break;
case 5:
i++;
meditation = payloadData[i];
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("Attention: ");
Serial.print(attention);
Serial.print("\n");
}
#endif
bigPacket = false;
}
else {
// Checksum Error
} // end if else for checksum
} // end if read 0xAA byte
} // end if read 0xAA byte
}

View file

@ -57,6 +57,7 @@ int main( int argc, char **argv ) {
* application. See documentation for "Serial I/O" for your
* platform for details.
*/
FILE *stream = 0;
stream = fopen( "COM4", "r" );