Closed Doody02 closed 3 years ago
@Doody02 i don't see their code above connect to your machine(Emotiv BCI). can you send me that part?
@hoangphamemotiv of course I will upload it now
@Doody02 that is about Emotiv BCI config. how about your Arduino code to connect to your PC via Ethernet or Wifi?
// you can find this written on the board of some Arduino Ethernets or shields byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // NOTE: Alternatively, you can assign a fixed IP to configure your Ethernet shield. byte ip[] = { 192, 168, 0, 154 }; int serverPort = 8500; // Emotiv BCI out port //Create UDP message object EthernetUDP Udp; void setup(){ Serial.begin(9600); //9600 for a "normal" Arduino board (Uno for example). 115200 for a Teensy ++2 Serial.println("Emotiv BCI OSC test"); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(LED5, OUTPUT);
// start the Ethernet connection:
// NOTE: Alternatively, you can assign a fixed IP to configure your Ethernet shield.
Ethernet.begin(mac, ip);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
while(true);
}
// print your local IP address:
Serial.print("Arduino IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
Udp.begin(serverPort);
}
void loop(){
//process received data from Emotiv BCI
OSCMsgReceive();
}
void OSCMsgReceive() {
int size = Udp.parsePacket();
if(size > 0) {
OSCBundle bundleIN;
while(size--)
bundleIN.fill(Udp.read());
if(!bundleIN.hasError()){
bundleIN.route("/fac/eyeAct", processFEEyeAct); // Facial_Expressions
bundleIN.route("/fac/uAct", processFEUAct); // Facial_Expressions
bundleIN.route("/fac/lAct", processFELAct); // Facial_Expressions
bundleIN.route("/com", processMC); // Mental_Commands
bundleIN.route("/met", processPM); // Performance_Metrics
}
}
}
void processFEEyeAct(OSCMessage &msg, int addrOffset) {
if(msg.match("/lookL", addrOffset)) {
Serial.println("FE - Look Left");
} else if(msg.match("/lookR", addrOffset)) {
Serial.println("FE - Look Right");
} else if(msg.match("/blink", addrOffset)) {
Serial.println("FE - Blink");
} else if(msg.match("/winkL", addrOffset)) {
Serial.println("FE - Wink Left");
} else if(msg.match("/winkR", addrOffset)) {
Serial.println("FE - Wink Right");
}
}
void processFEUAct(OSCMessage &msg, int addrOffset) { if(msg.match("/frown", addrOffset)) { if(msg.isFloat(0)) { Serial.print("FE - Frown: "); } } else if(msg.match("/surprise", addrOffset)) { Serial.print("FE - Surprise: "); }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processFELAct(OSCMessage &msg, int addrOffset) { if(msg.match("/clench", addrOffset)) { Serial.print("FE - Clench: "); } else if(msg.match("/laugh", addrOffset)) { Serial.print("FE - Laugh: "); } else if(msg.match("/smile", addrOffset)) { Serial.print("FE - Smile: "); } else if(msg.match("/smirkLeft", addrOffset)) { Serial.print("FE - Smirk Left: "); } else if(msg.match("/smirkRight", addrOffset)) { Serial.print("FE - Smirk Right: "); }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processMC(OSCMessage &msg, int addrOffset) {
if(msg.match("/neutral", addrOffset)) {
Serial.print("MC - Neutral: ");
} else if(msg.match("/push", addrOffset)) {
Serial.print("MC - Push: ");
} else if(msg.match("/pull", addrOffset)) {
Serial.print("MC - Pull: ");
} else if(msg.match("/left", addrOffset)) {
Serial.print("MC - Left: ");
} else if(msg.match("/right", addrOffset)) {
Serial.print("MC - Right: ");
} else if(msg.match("/lift", addrOffset)) {
Serial.print("MC - lift: ");
} else if(msg.match("/drop", addrOffset)) {
Serial.print("MC - drop: ");
} else if(msg.match("/rotateLeft", addrOffset)) {
Serial.print("MC - rotateLeft: ");
} else if(msg.match("/rotateRight", addrOffset)) {
Serial.print("MC - rotateRight: ");
} else if(msg.match("/rotateClockwise", addrOffset)) {
Serial.print("MC - rotateClockwise: ");
} else if(msg.match("/rotateCounterClockwise", addrOffset)) {
Serial.print("MC - rotateCounterClockwise: ");
} else if(msg.match("/rotateForwards", addrOffset)) {
Serial.print("MC - rotateForwards: ");
} else if(msg.match("/rotateReverse", addrOffset)) {
Serial.print("MC - rotateReverse: ");
} else if(msg.match("/disappear", addrOffset)) {
Serial.print("MC - disappear: ");
}
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processPM(OSCMessage &msg, int addrOffset) { if(msg.match("/foc", addrOffset)) { Serial.print("PM - focus: "); } else if(msg.match("/int", addrOffset)) { Serial.print("PM - interest: "); } else if(msg.match("/rel", addrOffset)) { Serial.print("PM - relaxation: "); } else if(msg.match("/str", addrOffset)) { Serial.print("PM - stress: "); } else if(msg.match("/exc", addrOffset)) { Serial.print("PM - excitement: "); } else if(msg.match("/eng", addrOffset)) { Serial.print("PM - engagement: "); } // else if(msg.match("/cognitiveStress", addrOffset)) { // Serial.print("PM - cognitiveStress: "); // } // else if(msg.match("/visualAttention", addrOffset)) { // Serial.print("PM - visualAttention: "); // } // else if(msg.match("/auditoryAttention", addrOffset)) { // Serial.print("PM - auditoryAttention: "); // }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
// I think that is it
@Doody02 seem you missed to add code of controling LED in the processMC() function. and to use Mental Commands detections, you need to training detection (like: push, pull, right, left....) and wearing your headset to receive detection data. note: Mental commands is different with Motion. Document of Emotiv detections, you can find from Emotiv BCI app
@hoangphamemotiv Do u have by any chance the code for controlling LED , also I do use the sensor while testing knowing that I have train all of ( push , pull , right , left ) with 2 train each . I do take my caution knowing that motion really do Affect the brain wave and change its pattern.
If my only problem is the LED code would you kindly please help me with this matter .
Thanks in advanced ....
you need adding LED code in which detection you want to control: for example: void processMC(OSCMessage &msg, int addrOffset) { if(msg.match("/neutral", addrOffset)) { Serial.print("MC - Neutral: "); digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); } else if(msg.match("/push", addrOffset)) { Serial.print("MC - Push: "); digitalWrite(LM1, HIGH); } else if(msg.match("/pull", addrOffset)) { Serial.print("MC - Pull: "); digitalWrite(LM2, HIGH); }
@hoangphamemotiv so the code will look like this right , but i still get the error of compile whenever i put it diffrent error appears .
// you can find this written on the board of some Arduino Ethernets or shields byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // NOTE: Alternatively, you can assign a fixed IP to configure your Ethernet shield. byte ip[] = { 192, 168, 1, 1 }; int serverPort = 8500; // Emotiv BCI out port //Create UDP message object EthernetUDP Udp; void setup(){ Serial.begin(9600); //9600 for a "normal" Arduino board (Uno for example). 115200 for a Teensy ++2 Serial.println("Emotiv BCI OSC test"); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(LED5, OUTPUT);
// start the Ethernet connection: // NOTE: Alternatively, you can assign a fixed IP to configure your Ethernet shield. Ethernet.begin(mac, ip); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: while(true); } // print your local IP address: Serial.print("Arduino IP address: "); for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } Serial.println(); Udp.begin(serverPort); }
void loop(){
//process received data from Emotiv BCI
OSCMsgReceive();
}
void OSCMsgReceive() {
int size = Udp.parsePacket();
if(size > 0) {
OSCBundle bundleIN;
while(size--)
bundleIN.fill(Udp.read());
if(!bundleIN.hasError()){
bundleIN.route("/fac/eyeAct", processFEEyeAct); // Facial_Expressions
bundleIN.route("/fac/uAct", processFEUAct); // Facial_Expressions
bundleIN.route("/fac/lAct", processFELAct); // Facial_Expressions
bundleIN.route("/com", processMC); // Mental_Commands
bundleIN.route("/met", processPM); // Performance_Metrics
}
}
}
void processFEEyeAct(OSCMessage &msg, int addrOffset) {
if(msg.match("/lookL", addrOffset)) {
Serial.println("FE - Look Left");
} else if(msg.match("/lookR", addrOffset)) {
Serial.println("FE - Look Right");
} else if(msg.match("/blink", addrOffset)) {
Serial.println("FE - Blink");
} else if(msg.match("/winkL", addrOffset)) {
Serial.println("FE - Wink Left");
} else if(msg.match("/winkR", addrOffset)) {
Serial.println("FE - Wink Right");
}
}
void processFEUAct(OSCMessage &msg, int addrOffset) { if(msg.match("/frown", addrOffset)) { if(msg.isFloat(0)) { Serial.print("FE - Frown: "); } } else if(msg.match("/surprise", addrOffset)) { Serial.print("FE - Surprise: "); }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processFELAct(OSCMessage &msg, int addrOffset) { if(msg.match("/clench", addrOffset)) { Serial.print("FE - Clench: "); } else if(msg.match("/laugh", addrOffset)) { Serial.print("FE - Laugh: "); } else if(msg.match("/smile", addrOffset)) { Serial.print("FE - Smile: "); } else if(msg.match("/smirkLeft", addrOffset)) { Serial.print("FE - Smirk Left: "); } else if(msg.match("/smirkRight", addrOffset)) { Serial.print("FE - Smirk Right: "); }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processMC(OSCMessage &msg, int addrOffset) {
if(msg.match("/neutral", addrOffset)) {
Serial.print("MC - Neutral: ");
} else if(msg.match("/push", addrOffset)) {
Serial.print("MC - Push: ");
} else if(msg.match("/pull", addrOffset)) {
Serial.print("MC - Pull: ");
} else if(msg.match("/left", addrOffset)) {
Serial.print("MC - Left: ");
} else if(msg.match("/right", addrOffset)) {
Serial.print("MC - Right: ");
} else if(msg.match("/lift", addrOffset)) {
Serial.print("MC - lift: ");
} else if(msg.match("/drop", addrOffset)) {
Serial.print("MC - drop: ");
} else if(msg.match("/rotateLeft", addrOffset)) {
Serial.print("MC - rotateLeft: ");
} else if(msg.match("/rotateRight", addrOffset)) {
Serial.print("MC - rotateRight: ");
} else if(msg.match("/rotateClockwise", addrOffset)) {
Serial.print("MC - rotateClockwise: ");
} else if(msg.match("/rotateCounterClockwise", addrOffset)) {
Serial.print("MC - rotateCounterClockwise: ");
} else if(msg.match("/rotateForwards", addrOffset)) {
Serial.print("MC - rotateForwards: ");
} else if(msg.match("/rotateReverse", addrOffset)) {
Serial.print("MC - rotateReverse: ");
} else if(msg.match("/disappear", addrOffset)) {
Serial.print("MC - disappear: ");
}
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processPM(OSCMessage &msg, int addrOffset) { if(msg.match("/foc", addrOffset)) { Serial.print("PM - focus: "); } else if(msg.match("/int", addrOffset)) { Serial.print("PM - interest: "); } else if(msg.match("/rel", addrOffset)) { Serial.print("PM - relaxation: "); } else if(msg.match("/str", addrOffset)) { Serial.print("PM - stress: "); } else if(msg.match("/exc", addrOffset)) { Serial.print("PM - excitement: "); } else if(msg.match("/eng", addrOffset)) { Serial.print("PM - engagement: "); } void processMC(OSCMessage &msg, int addrOffset) { if(msg.match("/neutral", addrOffset)) { Serial.print("MC - Neutral: "); digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); } else if(msg.match("/push", addrOffset)) { Serial.print("MC - Push: "); digitalWrite(LM1, HIGH); } else if(msg.match("/pull", addrOffset)) { Serial.print("MC - Pull: "); digitalWrite(LM2, HIGH); } // else if(msg.match("/cognitiveStress", addrOffset)) { // Serial.print("PM - cognitiveStress: "); // } // else if(msg.match("/visualAttention", addrOffset)) { // Serial.print("PM - visualAttention: "); // } // else if(msg.match("/auditoryAttention", addrOffset)) { // Serial.print("PM - auditoryAttention: "); // }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
you have 2 functions with the same name: processMC
I modified the code and it compiled perfectly but still the LED wont turn on .
// you can find this written on the board of some Arduino Ethernets or shields byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // NOTE: Alternatively, you can assign a fixed IP to configure your Ethernet shield. byte ip[] = { 192, 168, 1, 1 }; int serverPort = 8500; // Emotiv BCI out port //Create UDP message object EthernetUDP Udp; void setup(){ Serial.begin(9600); //9600 for a "normal" Arduino board (Uno for example). 115200 for a Teensy ++2 Serial.println("Emotiv BCI OSC test"); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(LED5, OUTPUT);
// start the Ethernet connection: // NOTE: Alternatively, you can assign a fixed IP to configure your Ethernet shield. Ethernet.begin(mac, ip); if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: while(true); } // print your local IP address: Serial.print("Arduino IP address: "); for (byte thisByte = 0; thisByte < 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } Serial.println(); Udp.begin(serverPort); }
void loop(){
//process received data from Emotiv BCI
OSCMsgReceive();
}
void OSCMsgReceive() {
int size = Udp.parsePacket();
if(size > 0) {
OSCBundle bundleIN;
while(size--)
bundleIN.fill(Udp.read());
if(!bundleIN.hasError()){
bundleIN.route("/fac/eyeAct", processFEEyeAct); // Facial_Expressions
bundleIN.route("/fac/uAct", processFEUAct); // Facial_Expressions
bundleIN.route("/fac/lAct", processFELAct); // Facial_Expressions
bundleIN.route("/com", processMC); // Mental_Commands
bundleIN.route("/met", processPM); // Performance_Metrics
}
}
}
void processFEEyeAct(OSCMessage &msg, int addrOffset) {
if(msg.match("/lookL", addrOffset)) {
Serial.println("FE - Look Left");
} else if(msg.match("/lookR", addrOffset)) {
Serial.println("FE - Look Right");
} else if(msg.match("/blink", addrOffset)) {
Serial.println("FE - Blink");
} else if(msg.match("/winkL", addrOffset)) {
Serial.println("FE - Wink Left");
} else if(msg.match("/winkR", addrOffset)) {
Serial.println("FE - Wink Right");
}
}
void processFEUAct(OSCMessage &msg, int addrOffset) { if(msg.match("/frown", addrOffset)) { if(msg.isFloat(0)) { Serial.print("FE - Frown: "); } } else if(msg.match("/surprise", addrOffset)) { Serial.print("FE - Surprise: "); }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processFELAct(OSCMessage &msg, int addrOffset) { if(msg.match("/clench", addrOffset)) { Serial.print("FE - Clench: "); } else if(msg.match("/laugh", addrOffset)) { Serial.print("FE - Laugh: "); } else if(msg.match("/smile", addrOffset)) { Serial.print("FE - Smile: "); digitalWrite(LED2, HIGH); } else if(msg.match("/smirkLeft", addrOffset)) { Serial.print("FE - Smirk Left: "); } else if(msg.match("/smirkRight", addrOffset)) { Serial.print("FE - Smirk Right: "); }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } } / void processMC(OSCMessage &msg, int addrOffset) { if(msg.match("/neutral", addrOffset)) { Serial.print("MC - Neutral: "); digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); } else if(msg.match("/push", addrOffset)) { Serial.print("MC - Push: "); digitalWrite(LM1, HIGH); } else if(msg.match("/pull", addrOffset)) { Serial.print("MC - Pull: "); digitalWrite(LM2, HIGH); }/
void processMC(OSCMessage &msg, int addrOffset) {
if(msg.match("/neutral", addrOffset)) {
Serial.print("MC - Neutral: ");
digitalWrite(LED5, HIGH);
} else if(msg.match("/push", addrOffset)) {
Serial.print("MC - Push: ");
digitalWrite(LED1, HIGH);
} else if(msg.match("/pull", addrOffset)) {
Serial.print("MC - Pull: ");
} else if(msg.match("/left", addrOffset)) {
Serial.print("MC - Left: ");
digitalWrite(LED4, HIGH);
} else if(msg.match("/right", addrOffset)) {
Serial. print("MC - Right: ");
digitalWrite(LED3, HIGH);
} else if(msg.match("/lift", addrOffset)) {
Serial.print("MC - lift: ");
} else if(msg.match("/drop", addrOffset)) {
Serial.print("MC - drop: ");
} else if(msg.match("/rotateLeft", addrOffset)) {
Serial.print("MC - rotateLeft: ");
} else if(msg.match("/rotateRight", addrOffset)) {
Serial.print("MC - rotateRight: ");
} else if(msg.match("/rotateClockwise", addrOffset)) {
Serial.print("MC - rotateClockwise: ");
} else if(msg.match("/rotateCounterClockwise", addrOffset)) {
Serial.print("MC - rotateCounterClockwise: ");
} else if(msg.match("/rotateForwards", addrOffset)) {
Serial.print("MC - rotateForwards: ");
} else if(msg.match("/rotateReverse", addrOffset)) {
Serial.print("MC - rotateReverse: ");
} else if(msg.match("/disappear", addrOffset)) {
Serial.print("MC - disappear: ");
}
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
void processPM(OSCMessage &msg, int addrOffset) { if(msg.match("/foc", addrOffset)) { Serial.print("PM - focus: "); } else if(msg.match("/int", addrOffset)) { Serial.print("PM - interest: "); } else if(msg.match("/rel", addrOffset)) { Serial.print("PM - relaxation: "); } else if(msg.match("/str", addrOffset)) { Serial.print("PM - stress: "); } else if(msg.match("/exc", addrOffset)) { Serial.print("PM - excitement: "); } else if(msg.match("/eng", addrOffset)) { Serial.print("PM - engagement: "); } // else if(msg.match("/cognitiveStress", addrOffset)) { // Serial.print("PM - cognitiveStress: "); // } // else if(msg.match("/visualAttention", addrOffset)) { // Serial.print("PM - visualAttention: "); // } // else if(msg.match("/auditoryAttention", addrOffset)) { // Serial.print("PM - auditoryAttention: "); // }
if(msg.isFloat(0)) { float value = msg.getFloat(0); Serial.println(value); } }
could it be the BCI OSC .
@Doody02 . i think you can try yourself step by step. the first step you should make sure you connected success your board with wifi/Ethernet. i suggest you connect via Ethernet, it is easier. after that you can connect your board to PC via serial port for debuging to see if data sent to your board.
back to your code. i think you should not use ip: byte ip[] = { 192, 168, 1, 1 };
1- the board is successfully connected via ethernet . 2- the serial port is connected as well . 3- I deleted the byte ip + {192 , 168 ,1 ,1 }
would please kindly advise , i am sorry for asking too much I just wanna know where is the flow .
deeply thankful for the assets.
thank you so much for the help , it worked with Ethernet perfectly it turns out all i need is the IP from the switch I had .
Greetings, I've tried to control the LED in arduino uno with using emotive epoc x and data stream on BCI OSC.
I followed this link
https://github.com/Emotiv/opensoundcontrol/tree/master/examples/EmotivOSC_Adruino
But the light won't work , am sure that I followed the instructions as this link above, would you kindly please advise about the arduiono uno code .
here is the pic above I uploaded the structure .
I tried the Arduino uno code in the link and it didnt work so I tried this ;
define LS 2 // left sensor
define RS 3 // right sensor
define LM1 5 // left motor M1a
define LM2 4 // left motor M2b
define RM1 7 // right motor M2a
define RM2 6 // right motor M2b
void setup() { pinMode(LS, INPUT); pinMode(RS, INPUT); pinMode(LM1, OUTPUT); pinMode(LM2, OUTPUT); pinMode(RM1, OUTPUT); pinMode(RM2, OUTPUT); } void loop() { if(!digitalRead(LS) && !digitalRead(RS)) // Move Forward on line { digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW); } if(digitalRead(LS) && !digitalRead(RS)) // Turn left by rotationg left motor in backward direction and right ones in forward digitalWrite(LM1, LOW); digitalWrite(LM2, HIGH); digitalWrite(RM1, HIGH); digitalWrite(RM2, LOW); } if(!digitalRead(LS) && digitalRead(RS)) // Turn right by rotating right motor in backward direction and left ones in forward digitalWrite(LM1, HIGH); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, HIGH); }
if(digitalRead(LS)&& digitalRead(RS)) // Finish line, stop both motors { digitalWrite(LM1, LOW); digitalWrite(LM2, LOW); digitalWrite(RM1, LOW); digitalWrite(RM2, LOW); } }