Void Loop Stops when using RCSwitch library

Hi there

I’m working on a small project that uses both the Brain Library, and the RC switch library. It’s really simple, when one of the brain values is higher than the other, the switch is on, and when it’s not, it’s off. I’ve got it so that it activates the switch, but then it stops looping, and reading values from the hacked MindFlex. Any help on this?

Below is my code, can anyone help so that it doesn’t stop looping after myswitch.SwitchOn(1,1);

#include <Brain.h>
#include <RCSwitch.h>


Brain brain(Serial);
RCSwitch mySwitch = RCSwitch();

const int sigPin = 13;
const int postPin = 6 ;


void setup() {
        pinMode(sigPin, OUTPUT);	
        pinMode(postPin, OUTPUT);
        mySwitch.enableTransmit(2);

	Serial.begin(9600);
}

void loop() {
	
	if (brain.update()) {
  		Serial.println(brain.readErrors());
		Serial.println(brain.readCSV());
	}


      if(brain.readSignalQuality() == 0) {
      digitalWrite(sigPin, HIGH);
          if(brain.readMeditation() >= brain.readAttention()){
          digitalWrite(postPin, HIGH);
          mySwitch.switchOn(1, 1);
          delay(2000);
          }else{ 
          digitalWrite(postPin, LOW);
          mySwitch.switchOff(1, 1);
          }
      }else{
      digitalWrite(sigPin, LOW);
      }

Thanks in advance guys, that’s the only thing stopping this project from working!

RCSwitch mySwitch = RCSwitch();

This is wrong. You never invoke a constructor directly.

A link to the library would be useful.

How do you know that the code blocks in the switchOn() method? What is supposed to be being switched on? Is it?

This is the library. https://code.google.com/p/rc-switch/

This is how it told me to set it up in the start, based on the examples and such.

It turns on a remote control wall socket. It does actually turn it on, but then I stop getting new information in the Serial, so it obviously stops the loop somewhere.

so it obviously stops the loop somewhere.

Obviously. But, you have no idea where. More Serial.print() statements is the answer, not jumping to conclusions.

I'm working on a small project that uses both the Brain Library

What, exactly is the Serial port being used for? Talking to the PC OR talking to some other device. Both is the wrong answer.

The serial port is being used for reading data from the NeuroSky chip in the Mindflex headset, so I can't print to the serial. I'm assuming it stops after the switchon, because the light comes on and it runs my appliance.

so I can't print to the serial.

Then, what is this for?

       Serial.println(brain.readErrors());
        Serial.println(brain.readCSV());

One could conclude that the device that supplied the data already knew the data.

Why is the device not connected to a software serial port, so you can debug?

You could use another method to debug, like turning an LED on or off.

I've tested with an LED and everytime it turns the switch on, it then stops everything. No more reading the data, won't even activate the LED, It just prevents the loop from happening any further.

PaulS:

so I can't print to the serial.

Then, what is this for?

         Serial.println(brain.readErrors());
        Serial.println(brain.readCSV());

One could conclude that the device that supplied the data already knew the data. Why is the device not connected to a software serial port, so you can debug? You could use another method to debug, like turning an LED on or off.

From the github page for the Brain library at https://github.com/kitschpatrol/Arduino-Brain-Library...

Note that the connection to the Neurosky headset is half-duplex — it will use up the RX pin on your Arduino, but you will still be able to send data back to a PC via USB. (Although in this case you won't be able to send data to the Arduino from the PC.)

Dozz, have you posted your entire code? There was a missing brace at the end of loop(), so it makes one wonder what else might be missing.

As well, I have to ask what sigPin and postPin are hooked up to.

That's all I've got to the code, I just didn't copy all the way down to the bottom.

The two pins are infact just simple LED's.

Place a few Serial.println() statements in there...

One after each if, one after each else, and one after each mySwitch operation.. Make them uniqe; for example:

    Serial.println("Test 1");

    Serial.println("Test 2");
    // etc.