-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blink detection #5
Comments
@mehaghiles I'm afraid you won't be able to do that with an Arduino/serial device (as the communication protocol doesn't support it) You should be able to use their SDK on a computer. See issue #1 for details |
@orgicus Thank you for your response. It took a while for me but i finally found how to detect the blinking eye. I'm working on a project since months and i need to use both of blink detection and the attention value, unfortunatly i have some isues using your library with the code that i have. When I try to use the command "mindwave.update" nothing happens. I was wondering if you could help me solving this problem. |
@mehaghiles Nice work on getting eye blink detection working. I would need to understand which Serial stream you're using and how you have connected the wires between the Arduino and the Bluetooth module. Can you post a minimal version of your sketch and a wiring diagram ? |
Here is the code i use to get the eye blinking detection, anyway it's not mine i found it after many researches on google. The pnly connexion i have is the bluetooth wich recieve data from the headset and is connected to Rx pin, it's almost the same connexion as the one on your librarie because i use both codes without changing the connexions. Anyway here is the code. #define BAUDRATE 57600
boolean DEBUGOUTPUT = false,piekDetected = false;
int Data[512] = {0};
int i = 0, n = 0 ;
int PiekP, PiekM;
long piekTime = 0;
int payloadLength = 0;
byte payloadData[64] = {0};
byte poorQuality = 200;
void setup()
{
Serial.begin(57600);
}
byte ReadOneByte()
{
int ByteRead;
while (!Serial.available());
ByteRead = Serial.read();
return ByteRead;
}
void loop()
{
long Hilf = 0;
if (i >= 512)
i = 0;
if (ReadOneByte() == 170 && ReadOneByte() == 170)
{
payloadLength = ReadOneByte();
if (payloadLength == 4)
{
if (ReadOneByte() == 128 && ReadOneByte() == 2)
{
Hilf = ((long)ReadOneByte() * 256 + (long)ReadOneByte());
if (Hilf > 32767)
Hilf -= (long)(65535);
Data[i] = (int)Hilf;
ReadOneByte();
PiekP += Data[(512 + i - 71) % 512];
PiekP -= Data[(512 + i - 50 - 71) % 512];
if ((PiekP > 3000) && (Data[(512 + i - 70) % 512] < 0) && (PiekP < 13000))
{
if (millis() - piekTime > 100)
{ PiekM = 0;
for (int j = 1; j <= 70; j++)
PiekM += (int)(Data[(512 + i + j - 70) % 512]);
if (PiekM < -3000 && PiekM > -11000) {
if ((millis() - piekTime) < 600)n++; else n = 1;
if(poorQuality == 0)digitalWrite(6,HIGH);else digitalWrite(6,LOW);
piekTime = millis();
piekDetected = true;
}
}
}
i++;
if (DEBUGOUTPUT && i == 512)
{
for (int j = 0; j < 512; j++)
{Data[j];
Serial.print(Data[j]);
Serial.print(";");
}
Serial.println("");
}
}
}
else if(payloadLength < 170){
for (int k = 1; k < payloadLength; k++)
if(ReadOneByte()== 2)poorQuality = ReadOneByte();
}
}
if((millis()-piekTime)>700 && piekDetected == true)Serial.println(n),piekDetected = false;
}
|
@orgicus i wish you'll find a sollution to add the eye blinking detection in your librairie or just find a way to use i in this program because i've tried so many times but it don't work att all |
Hi @mehaghiles What you've sent is is confusing. My short answer is that you shouldn't attempt to get blink data with an Arduino and use a computer with bluetooth where you would run the official Mindwave SDK (ThinkGear API) to get all the data you need. It really depends on what your overall project is trying to acomplish and how you get there. Given that I have no Mindwave headset to test, limited time and you are asking for support on functionality that is nor supported by this library this is the best I can do support additionally: Where did you find this snippet ?
By Rx pin do you mean Arduino pin 0 RX, a different SoftSerial pin ? At the moment I don't have a headset to test, however if you are 100% confident the code you have detects blinks and still want to use my library this what I'd advise:
Here is a rough attempt at merging your code above with the library please note that I can't test the code (without access to the hardware) and I have no guarantee that your code above works perfectly. This is more a guide on how you might want to approach this, not a working solution: #include <Mindwave.h>
Mindwave mindwave;
int* data;
int peakP, peakM;
int i = 0, n = 0;
long peakTime = 0;
boolean peakDetected = false;
void setup() {
Serial.begin(MINDWAVE_BAUDRATE);
}
void updateBlink(){
data = mindwave.eeg();
for(int i = 0 ; i < MINDWAVE_EEG_SIZE; i++){
// print debug data
Serial.print(data[i]);
if(i < MINDWAVE_EEG_SIZE) Serial.print('\t');
// TODO: cleanup / debug / test
peakP += data[(512 + i - 71) % 512];
peakP -= data[(512 + i - 50 - 71) % 512];
if( (peakP > 3000) && (data[(512 + i - 70) % 512] < 0) && (peakP < 130000)){
if (millis() - peakTime > 100){
peakM = 0;
for (int j = 1; j <= 70; j++){
peakM += (int)(data[(512 + i + j - 70) % 512]);
}
if (peakM < -3000 && peakM > -11000) {
if ((millis() - peakTime) < 600)
n++;
else
n = 1;
if(mindwave.quality() == 1000)
digitalWrite(6,HIGH);
else
digitalWrite(6,LOW);
peakTime = millis();
peakDetected = true;
}
}
}
}
Serial.println();
if((millis() - peakTime) > 700 && peakDetected == true){
Serial.println(n);
peakDetected = false;
}
}
void loop() {
mindwave.update(Serial,updateBlink);
} Rather trying to slap random bits of code without understanding them fully try to slow down a bit, break the problem down into smaller simpler chunks. Imagine what the code does line by line then user Also check out this how to program guide. Hope this helps, |
@orgicus i have tried the code you wrote and it's not working. The original code print the times i'm blinking my eyes only when i blink my eyes. But yours update the values wether if there is no blinking detected. And with your code the printed datas ar the raw data received by the headset. |
@mehaghiles Thanks for posting the circuit image: very helpul ! As previously mentioned, my library supports the Mindwave standard ThinkGear API which doesn't include Blink detection. That being said: if it can be accurately extrapolated from the EEG data it would be nice to contribute that for other users as well. At best, I may have a bit of time mid August and would need your time perhaps on remote calls to test/debug with an actual device. If this timeline and level of commitment isn't feasible all I can do is provide guidance but I can't reliably solve this for you. Regarding the code snippet I posted above, as mentioned previously, I posted it as a starting point and you should have no expectation of it working as is. FWIW, having a closer look I notice this in my library: _eeg[j] = ((int)_payloadData[++i] << 16) | ((int)_payloadData[++i] << 8) | (int)_payloadData[++i]; while the code you've posted does this: Hilf = ((long)ReadOneByte() * 256 + (long)ReadOneByte());
if (Hilf > 32767)
Hilf -= (long)(65535); This leads me to believe the From a pragmatic point of view, for a faster solution I would consider one of the following options:
For option 2 you will need to get familiar with ThinkGear Packets(page 9 onwards) and a bit of working with bytes (using hexadecimal, bits/bytes, bitwise operators ( |
@orgicus I'll try to take a look at all these documents and find a solution. I have already trying to work with the Mindwave.cpp code you gave me that i have foun on the Neurosky official website and I'm still trying to arrange the variables so that they are the same in both programs. I find some difficulties because i don't know exactly the role of each variable and how it works. |
@orgicus Here is the original blinking eye detection code wwith all the comments. It will certainly help understanding the code more. if (ReadOneByte() == 170 && ReadOneByte() == 170)// this is the beginning of each new sequence
}// end if 170 170 appeared |
please, can you tell me how you detect eye blink? |
@orgicus @Tafhimbn @mehaghiles I am starting a project that will use eye-blinks, and in my research on the Internet I found an Arduino sketch that uses orgicus' library and successfully detect eye-blinks. Here is the link: https://www.instructables.com/FPV-Virtual-Reality-Arduino-Controlled-Tracked-Rob/ . The code for NeuroSky is in Step 11 and is titled "Code for the Brainwave Controlled Robot:" |
Hi orgicus, I forked the library and integrated the eye blink detection in the code: Feel free to include the changes also in the main branch. Regards, |
Hi @AK-Homberger Great work! It would amazing if you could contribute this feature. Unfortunately today I won't time to fully review. Many thanks, |
i want to detect blinking eyes using your librarie but i don't know if it's possible or how to do this
The text was updated successfully, but these errors were encountered: