Sending data from EEG sensor connected to Arduino over rf using radio head

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.

As you can see, according to the writer of this code, the readCSV function gets the brain data and returns it as a char.

That is not what the author said. The author said that the function returned a pointer to a char (array).

So, why are you not using a pointer?

char *brainCrap = brain.readErrors();

Okay. Thank you for clearing that up. That makes more sense than it returning a char. I didn't know what a pointer was but now that you have explained that it makes sense. The other question I have is if you think I would need to send both Brain.readErrors and readCSV. I think I do.
Here is the updated code.

/*
    SimpleSend
    This sketch transmits a short text message using the VirtualWire library
    connect the Transmitter data pin to Arduino pin 12
    */
    char *Brainmsg;
#include <VirtualWire.h>
#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.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.readCSV());
 
    }
    
   }

I am now going to create a fake array that I can test with this. The question I have is , is this an array of numbers stored as chars. I just seems weird that it is exporting it as a char array instead of the values. And they are comma delineated.
Here is how I was planning on creating fake brain data for testing. Would this work?

char *Brainmsg;
String braindata = Brainmsg = "200,0,0,46185,38494,32585,7639,10915,18850,28676,8507";
char charBuf[50];
braindata.toCharArray(charBuf, 50)
char *Brainmsg= charBuf

So I tested out my revised code with the actual eeg sensor connected and I think my problem is in the receiver code because the transmitter code seems to be working fine.

/* 

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); 
    Serial.println("recieved");
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
    {            
          // Fill Sensor1CharMsg Char 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);
    }
}

It is receiving the message but not displaying it. It prints out my "received " message and nothing else.

The other question I have is if you think I would need to send both Brain.readErrors and readCSV.

You were sending the data to the serial port, in a way that made it impossible to distinguish one from the other. I have no idea what you saw, or how you distinguish one from the other. Therefore, I have no idea which data you want to send.

// RF Transmission container
char Brainmsg[1];

One? Why one? Surely you sent more than one character.

        for (i = 0; i < buflen; i++)
    {           
          // Fill Sensor1CharMsg Char array with corresponding
          // chars from buffer.   
          Brainmsg[i] = char(buf[i]);

You have just stomped all over memory you don't own.

I found issues. I have tried a new code with some success. This is the transmitter portion.

#include <RH_ASK.h>
#include <Brain.h>
#include <SPI.h> // Not actually used but needed to compile
Brain brain(Serial);

RH_ASK driver;

void setup()
{
    Serial.begin(9600);   // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

void loop()
{
   if (brain.update()) {
     char *msg;
       msg = brain.readErrors();
      driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    msg = brain.readCSV();   
        Serial.println(brain.readCSV());
 driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    }
     
}

The problem is I keep getting packet too long error in serial monitor. I am not sure if it has to do with the length I put for the array receiving it or not.

For the receiver code I simply did

uint8_t buf[59]

where 59 is the max number of characters contained in the packet being sent(I simply counted the number of commas and numbers in the longest packet sent by the headset). To add to my confusion, brain.h seems to define max packet length.

"#define MAX_PACKET_LENGTH 32"

Right now it is saying packet too long or adding random characters to the end of the string of numbers. But it is a start because it is sending the data from the headset over rf.

The RadioHead library can not send more than 32 characters in a packet. You need to break your 59 character packets into two or more smaller packets.