'Issues with Arduino radio module interfering with EEG sensor readings
So I am making an EEG headset using the chip from a mindflex headset.
I am trying to send the EEG sensor data wirelessly between 2 Arduinos using a radio module, where 1 of the Arduinos is connected to the sensor and transmitter, and the other is connected to the laptop and receiver.
I've decided to pack the sensor data from the EEG into a data struct that I included as a header file in the receiver and transmitter sketch. Yet when I try to send the data struct from the headset to the receiver, the receiver shows incorrect sensor data.
I connected the headset to Arduino and opened to serial monitor, which showed the same incorrect or missing sensor data as the receiver, yet once I've removed the code that sends the data packet, the sensor readings returned to being normal.
I'm assuming the radio modules are interfering with the way sensor data is sent from the sensor to the Arduino. But I'm not sure.
Does anyone have any idea what might be the issue?
Some info on the pin connections:
Transmitting Aarduino:
Transmitter Data Pin: Pin 12 on Arduino Transmitter VCC: 5V Transmitter GND: GND
EEG Data pin: RX pin on Arduino EEG GND: GND pin on Arduino
Receiver Arduino:
Receiver Data pin: pin 11 on Arduino Receiver VCC: 5V Receiver GND: GND
Transmitter code:
#include <Brain.h>
#include "brain_packets.h" //Data structure file
Brain brain(Serial); //EEG object
RH_ASK sensor; // Radio Object
uint16_t focus_t; //Focus from EEG
uint16_t ss_t; //Signal Strength from EEG
void setup() {
Serial.begin(9600);
sensor.init();
} //Initialise the transmitter
void loop() {
brain_packet data ; // Data struct to store EEG data
if (brain.update()) { // checks if there is new sensor data
ss_t = 200 - brain.readSignalQuality(); // Store EEG signal strength in ss_t
focus_t = brain.readAttention();
} // store EEG focus value in focus_t
data.ss = ss_t; //Store signal strength from sensor as ss in data struct
data.focus = focus_t; // Store focus from sensor as focus in data struct
sensor.send((uint8_t*)&data, sizeof(data)); //Send the data struct to receiver
sensor.waitPacketSent(); // Wait until data is sent until sending another packet
}
Receiver sketch:
#include <SPI.h>
#include "brain_packets.h" // Data struct file
RH_ASK sensor; //Receiver object
uint16_t sig_s;
uint16_t foc;
void setup() {
Serial.begin(9600);
if (!sensor.init()) {
Serial.println("Sensor Com initialisation failed");
} else {
Serial.println("Communications Secured");
}
}
void loop() {
brain_packet data; //Data struct with EEG data
uint8_t datalen = sizeof(data);
if (sensor.recv((uint8_t*)&data, &datalen) && datalen == sizeof(data)) {
foc = (data.focus); //Assign foc to the received focus value
sig_s = (data.ss);
} //Assign sig_s to the received signal strength value
Serial.print("Current Focus: ");
Serial.println(foc);
Serial.print("Signal Strength: ");
Serial.println(sig_s);
Serial.println("");
delay(1000);
}
For the radio module library I used the radiohead library
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
