I am currently trying to wirelessly send data from an EEG headset to another arduino over RF. I am using a code based on the arduino brain library taken from an EEG tutorial. The original code looks like this,
#include <Brain.h>
// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);
void setup(){
Serial.begin(9600);
}
void loop(){
if (brain.update()) {
Serial.println(brain.readErrors());
Serial.println(brain.readCSV());
//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"
}
}
As you can see, according to the writer of this code, the readCSV function gets the brain data and returns it as a char. It is actually several comma delineated values. I am having trouble coming up with a code to send that data. The receiver is a 433Mhz RF Transmitter and Receiver Link Kit. How would I send this data? Would I need to encode and decode it? This is some transmitter/receiver code I have modified to use the brain library but it does not work. I have tried testing it by creating a fake char that was formatted the same way as the brain data to see if it would send and it did not.
Transmiter
#include <VirtualWire.h>
char Brainmsg = new char[11];
#include <Brain.h>
// Set up the brain parser, pass it the hardware serial object you want to listen on.
Brain brain(Serial);
void setup(){
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
Serial.begin(9600);
}
void loop(){
if (brain.update()) {
Brainmsg = brain.readErrors();
digitalWrite(13, true); // Turn on a light to show transmitting
vw_send((uint8_t *)Brainmsg, strlen(Brainmsg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
Serial.println(brain.readErrors());
Brainmsg = brain.readCSV();
digitalWrite(13, true); // Turn on a light to show transmitting
vw_send((uint8_t *)Brainmsg, strlen(Brainmsg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false); // Turn off a light after transmission
Serial.println(brain.readCSV());
}
}
Reciever
/*
Sensor Receiver
By Markus Ulfberg 2012-07-06
Gets a sensor reading 0-1023 in a char array
from RF Transmitter unit via VirtualWire
converts char array back to integer
*/
#include <VirtualWire.h>
// LED's
int ledPin = 13;
// RF Transmission container
char Brainmsg[1];
void setup() {
Serial.begin(9600);
// sets the digital pin as output
pinMode(ledPin, OUTPUT);
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
vw_set_ptt_inverted(true);
// Bits per sec
vw_setup(2000);
// Start the receiver PLL running
vw_rx_start();
} // END void setup
void loop(){
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Non-blocking
if (vw_get_message(buf, &buflen))
{
int i;
// Turn on a light to show received good message
digitalWrite(13, true);
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
// Fill Brainmsg array with corresponding
// chars from buffer.
Brainmsg[i] = char(buf[i]);
}
// Null terminate the char array
// This needs to be done otherwise problems will occur
// when the incoming messages has less digits than the
// one before.
Brainmsg[buflen] = '\0';
// DEBUG
Serial.println(Brainmsg);
// END DEBUG
// Turn off light to and await next message
digitalWrite(13, false);
}
}
Any advice would be helpful. Thanks in advanced.