Hello! I am a sophomore in our schools engineering class. Our current project is using the Mattle MindFlex game, and modifying the headset to control an RC car. We have gotten this to work with the help of this video How to Hack Toy EEGs | Frontier Nerds . We were able to see the brain waves in processing. Once we had gotten that far we wrote our own code in arduino to parse the raw data packet the headset produced. The code basically says if X ? 60 that car will move forward.
Our code to do this much is
// Arduino Brain Library
// Serial out example, grabs the brain data and sends CSV out over the hardware serial.
// Eric Mika, 2010
#include <Brain.h>
#include <Servo.h>
const int voltPin = 2; //names pin 2 as the voltpin
long interval = 500;
Servo motor; //creates a Servo object called motor
// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);
void setup() {
// Start the hardware serial.
Serial.begin(9600);
pinMode (voltPin, OUTPUT); //sets the voltPin as an Output
digitalWrite(voltPin, HIGH); //send 3 volts to the voltpin
motor.attach(6);
motor.write(90);
}
void loop() {
// Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
if (brain.update()) {
Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
interval = brain.readAttention();
}
if (interval >= 0 && interval <= 100) {
if (interval > 60) {
motor.write(150);
}
else {
motor.write(90);
}
} else {
motor.write(90);
}
}
Now the biggest issue we have is the fact that the headset is wired to the car. Now what we plan to do next is make them wireless. In our lab we have a set of series one xbee's and a pair of series two xbee's and can easily get replacement sets if needed. We have spent the last 3 weeks trying to code the xbee's to transmit the signal from one to another. We know we will need one Arduino Uno mounted to the RC car which we have the shield mounted to the car then the xbee mounted to the shield. On the mindflex we have the Shield mounted to the arduino and the xbee mounted to the shield. We have the set up just not the code to do it. We are taking this project to the state science fair in a month, and think wireless would be a bit cooler then having a huge wire hanging from your head.
We have spent the last 3 weeks trying to code the xbee's to transmit the signal from one to another.
Getting one Arduino to talk to another, via XBees, is pretty simple. Just how simple depends on which kind of XBees you are using (Series 1 for point to point makes the most sense), how you have configured them, and how you are attaching them to the Arduinos.
I'd recommend removing the XBee from that shield, and throwing that shield away. Of all the XBee shields available, that is absolutely the worst of the bunch.
If you are stuck using it, then Serial.print() will send data to the XBee, which will broadcast it. The receiving XBee will put data on the serial port, and you can read it using Serial.available() and Serial.read() (with Serial.begin() on both ends, of course).
Now, how have you configured the XBees? Or have you?
Our series one Xbee's have not been configured yet at all. I can try to find a different shield and order it if we need it to make it work. What shields would you suggest?
Okay sweet I will see if we can order them some time next week. So how would we go about setting up our series one Xbee's. Then how would we go about editing our current code to get the wireless to work?
The next time I am in the lab is on Monday so I wont be able to test anything until then. I am able to communicate threw out the weekend though.
So how would we go about setting up our series one Xbee's.
Set PAN ID, MY, and DL. Leave EVERYTHING else alone. MY on one matches DL on the other, and neither is 0x000 or 0xFFFF.
For instance, set one up with PAN ID = 3333, MY = 8001, and DL = 8000. Set the other with PAN ID = 3333, MY = 8001, and DL = 8001.
Then how would we go about editing our current code to get the wireless to work?
Create an instance of SoftwareSerial, using pins 2 and 3, called xbee. Then, use xbee.begin(), xbee.print(), xbee.write(), xbee.println(), xbee.available(), and xbee.read(), just like Serial.XXX.
Okay so we are writing a code now to send that data from one to another, I will post the code asap. We finished the receiving code for the xbee on the car. Working on the code for the xbee mounted on the headset.
Okay... So we are having issues. The xbees are connected, and we can turn an led on an off with input from the keyboard (H and L key.)
The issue the shield takes up the RX pin. Now we need the RX pin in order to take the raw data from the headset.
now with the xbee shileld mounted onto the mindflex headset we can not plug into the RX pin.
now we have another Xbee connected to the transmitter or the RC car. We know how to wire this to the transmitter. Issue is making code
The code we are using for Arduino connected to the mindflex headset is the following
// Arduino Brain Library
// Serial out example, grabs the brain data and sends CSV out over the hardware serial.
// Eric Mika, 2010
#include <Brain.h>
#include <Servo.h>
const int voltPin = 2; //names pin 2 as the voltpin
long interval = 500;
Servo motor; //creates a Servo object called motor
// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);
void setup() {
// Start the hardware serial.
Serial.begin(9600);
pinMode (voltPin, OUTPUT); //sets the voltPin as an Output
digitalWrite(voltPin, HIGH); //send 3 volts to the voltpin
motor.attach(6);
motor.write(90);
}
void loop() {
// Expect packets about once per second.
// The .readCSV() function returns a string (well, char*) listing the most recent brain data, in the following format:
// "signal strength, attention, meditation, delta, theta, low alpha, high alpha, low beta, high beta, low gamma, high gamma"
if (brain.update()) {
Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
interval = brain.readAttention();
}
if (interval >= 0 && interval <= 100) {
if (interval > 60) {
motor.write(150);
}
else {
motor.write(90);
}
} else {
motor.write(90);
}
}
We need to take this code and make it wireless to communicate with the other xbee mounted onto the RC car. We have series 1, xbees paired together. Could some one edit this code and show us? Then explain to me what you did? I have two weeks to get this done and kinda hit a brick wall lol.
IIRC, all your original shield requires is +5V, gnd, RX and TX. So you could remove it from the the arduino and wire it up manually. Then you can use a softwareSerial instance to talk to the XBee, leaving the hardware serial available.
Could you teach/ explain to me how to connect the rx from the arduino and xbee?
If you have one of the shields I have, it has a switch on it. In one position, RX and TX (pins 0 and 1) and Serial are used to talk to the XBee. In the other position, pins 2 and 3 and an instance of SoftwareSerial is used to talk to the XBee.