Hi , I have the BCI-OSC license and i want to send mental commands to control the motors of a robotic car , the problem is I can’t make a successful connection between the software and arduino ( I’m using Ethernet shield to connect the arduino uno to the Router and to the laptop by wifi because my router have only 1 port )
The problem is when I upload my code it gives me “ Failed to configure Ethernet using DHCP“ in the serial monitor .. So could you help me to know where the problem is ??
here is my code :
include
include
include
include
int ctrl_IN1 = 8;
int ctrl_IN2 = 7;
int ctrl_ENABLE1 = 3; //enable right
//left side motor control
int ctrl_IN3 = 6;
int ctrl_IN4 = 5;
byte ip[] = { 192, 168, 8, 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(ctrl_IN1, OUTPUT);
pinMode(ctrl_IN2, OUTPUT);
pinMode(ctrl_IN3, OUTPUT);
pinMode(ctrl_IN4, OUTPUT);
pinMode(ctrl_ENABLE1, OUTPUT);
pinMode(ctrl_ENABLE2, OUTPUT);
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);
}
Hi , I have the BCI-OSC license and i want to send mental commands to control the motors of a robotic car , the problem is I can’t make a successful connection between the software and arduino ( I’m using Ethernet shield to connect the arduino uno to the Router and to the laptop by wifi because my router have only 1 port ) The problem is when I upload my code it gives me “ Failed to configure Ethernet using DHCP“ in the serial monitor .. So could you help me to know where the problem is ??
here is my code :
include
include
include
include
int ctrl_IN1 = 8; int ctrl_IN2 = 7; int ctrl_ENABLE1 = 3; //enable right //left side motor control int ctrl_IN3 = 6; int ctrl_IN4 = 5; byte ip[] = { 192, 168, 8, 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(ctrl_IN1, OUTPUT); pinMode(ctrl_IN2, OUTPUT); pinMode(ctrl_IN3, OUTPUT); pinMode(ctrl_IN4, OUTPUT); pinMode(ctrl_ENABLE1, OUTPUT); pinMode(ctrl_ENABLE2, OUTPUT); 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: "); 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: "); } else if(msg.match("/push", addrOffset)) { Serial.print("MC - Push: "); digitalWrite(ctrl_IN1, HIGH); //7,6,5,4 digitalWrite(ctrl_IN2, LOW); digitalWrite(ctrl_IN3, HIGH); digitalWrite(ctrl_IN4, LOW); } else if(msg.match("/pull", addrOffset)) { Serial.print("MC - Pull: "); digitalWrite(ctrl_IN1, LOW); digitalWrite(ctrl_IN2, HIGH); digitalWrite(ctrl_IN3, LOW); digitalWrite(ctrl_IN4, HIGH); } 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); } }