nrf24l01 communication help plz!!!!!!

i have a micro im usinf as a controller to control a rc car that is using a mega im using the mega with the seeedstudios motorshield …the serial monitor for the micro ust puts out a constant 255 …and for th mega does nothing

mega code

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "MotorDriver.h"
int msg[1];
RF24 radio(9,53);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(void)
{
   Serial.begin(9600);
  radio.begin();
 radio.openReadingPipe(1,pipe);
 radio.startListening();
 motordriver.init();
  motordriver.setSpeed(50,MOTORB);
  motordriver.setSpeed(50,MOTORA);
}

void loop(void){
if(radio.available()){
  bool done = false;
  while (!done){
    done = radio.read(msg, 1);
    Serial.println(msg[0]);
    if (msg[0] == 111){
      delay(10);
      motordriver.goForward();
    
}
else{
  motordriver.stop();
}
  }
    }

else{Serial.println("No radio available");}}

micro code

#include "MotorDriver.h"
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int msg[1];
RF24 radio(9,53);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void)
{
   motordriver.init();
  motordriver.setSpeed(50,MOTORB);
  motordriver.setSpeed(50,MOTORA);
 Serial.begin(9600);
radio.begin();
  radio.openWritingPipe(pipe);
 

}


void loop(void)
{
  // if there is data ready
  if ( digitalRead(SW1) == HIGH){
    msg[0] = 111;
    radio.write(msg, 1);}}

I tried to follow your code but your random indenting and stupid outdenting made that impossible.

Every } goes on a line ALL BY ITSELF. Tools + Auto Format would that atrocious looking code.

if it helps i copied the code from this video https://www.youtube.com/watch?v=HO5PgWyOEFc

Bump plz help

Bump plz help

Have you fixed your ugly code? If not. I suggest that you bump yourself.

Yes and thank you for the constructive criticism

int msg[1];

What's the point of a 1 element array?

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
int msg[1];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void)
{
  Serial.begin(9600);

  radio.begin();
  radio.openWritingPipe(pipe);
}

void loop(void)
{
  // if there is data ready
  if ( digitalRead(SW1) == HIGH)
  {
    msg[0] = 111;
    radio.write(msg, 1);
  }
}




secound module code


#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
int msg[1];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int motorPin1 = 3;
int motorPin2 = 4;
void setup(void)
{
  Serial.begin(9600);
  while (!Serial);
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
}

void loop(void) {
  if (radio.available())
  {
    bool done = false;
    while (!done) {
      done = radio.read(msg, 1);
      Serial.println(msg[0]);
      if (msg[0] == 111)
      {
        delay(10);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);

      }
      else
      {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
      }
    }
  }

  else {
    Serial.println("No radio available");
  }
}
  if ( digitalRead(SW1) == HIGH)
  {
    msg[0] = 111;
    radio.write(msg, 1);
  }

Suspect that you want to transmit ONCE when the switch BECOMES pressed, not over and over again, as fast as possible, while the switch IS pressed.

Are we to guess which code runs on the Mega and which code runs on the Micro?

The first code writes nothing to the Serial Monitor application, so it would appear that that is not the code running on the Micro. Therefore, it must be the code for the Mega that does nothing. That leads me to suspect your switch wiring.

On the other hand, it doesn’t seem possible that the second code runs on the Micro, either.

i would like i to remain as long as the button is pushed as it will act as my forward on the wireless car..... and i know the mega uses 9 and 53 instead of 9 and 10 per this link http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo im asuming i only need to change it on the mega code. the micro i would like to use as the controller and mount the mega into the car is there something differant i need to do with coding in micro then others?

i would like i to remain as long as the button is pushed as it will act as my forward on the wireless car

Nonsense. You send one value when the switch BECOMES pressed. You send another when the switch BECOMES released. You do NOT send data continuously.

so i finally have both modules comunicating per the getingstarted example but with my code here the code that defines the motor pins just puts out a constant 111 thays my msg[0] and the other simple does nothing still...now it should only be sending that if i have the buntton pushed on the controller end i beleave but even so if its constantly 111 then the motor should be spining

if (msg[0] == 111) { delay(10); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW);

Let us know when you get the radios off of the hardware serial port, so that you can debug the code on each Arduino.

this code just serial prints everything and i get this error with it

Arduino: 1.6.3 (Windows 8.1), Board: “Arduino Micro”

REMOTECARRX.ino: In function ‘void loop()’:

REMOTECARRX.ino:33:3: error: ‘else’ without a previous ‘if’

Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
int msg[1];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int SW1 = 7;

void setup(void)
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);

}

void loop(void)
{
  // if there is data ready
  if ( digitalRead(SW1) == HIGH);
  {
    msg[0] = 111;
    radio.write(msg, 1);
    Serial.println("Forward");
  }
  if ( digitalRead(SW1) == LOW);
  {
    msg[0] = 100;
    radio.write(msg, 1);
    Serial.println("Stop");
  }
  else
  {
    Serial.println("No signal");
  }
}
if ( digitalRead(SW1) == LOW);

If shouldn't have a semicolon. That counts as the one statement after the if, so the next block ins't conditional. Since you have all this unconditional code before the else, it's an else without an if.

thank you!
well now the mega code on the receaving end just serial puts out Forward
111
forward
111
even when the button is not pressed but yet does not do what its supposed to do if it receave the 111 msg…

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
int msg[1];
RF24 radio(9, 10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int motorPin1 = 3;
int motorPin2 = 4;
void setup(void)
{
  Serial.begin(9600);

  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
}

void loop(void) {
  if (radio.available())
  {
    bool done = false;
    while (!done)
    {
      done = radio.read(msg, 1);
      Serial.println(msg[0]);
      if (msg[0] == 111)
      {
        delay(10);
        Serial.println("Forward");
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);

      }
      else
      {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
      }
    }
  }
  else 
  {
    Serial.println("No radio available");
  }
}

Once msg[0] is 111, what makes it take on some other value?

    bool done = false;
    while (!done)

Each time loop() gets called, you try to read from the radio. The value of done tells you whether or not you were successful. But, you ignore that and assume that you read something. I don't understand that.

When there is nothing to read, the msg array is not trashed.

i think i see what your saying... would this make more sense?

void loop(void) { if (radio.available()) { Serial.println("available"); } radio.read(msg, 1); Serial.println(msg[0]); if (msg[0] == 111) { delay(10); Serial.println("Forward"); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW);

}

would this make more sense?

No.

 if (radio.available())
  {
    Serial.println("available");
    }
      radio.read(msg, 1);
      Serial.println(msg[0]);
      if (msg[0] == 111)
      {

If there is anything to read, print a message. Then, regardless of whether or not there is anything to read, read it. Then, regardless of whether the read was successful, use the data that you read sometime in the past.

I really don't think that that is going to work.

radio.read() returns a value. Don't discard it. Don't use msg[0] unless you did read something.

Of course, it would be easier to just set msg[0] to something else after using the value. Then, until there IS new data, successfully read, msg[0] won't still be 111.