serial.print causes reset in combination with RF24 radio

Today i got a strange issue while programming an Arduino with RF24 Radio.

I was using Serial.print in the main loop to debug code. Found that whenever the radio.read() command was used and after that a new Serial.print command was given the arduino completely resets.

Have tried everything, other arduino, new radio module, delay before Serial.print, etc.

I know for sure that the radio is receiving information correctly. I have sent several values from an other radio module and one of them should make pin 5 high. That happend correctly. When pasting the code that make pin 5 high behind the Serial.print line nothing happend. (i deleted that part of pin 5 in my example code)

What i want is that the arduino can Serial.print the received intensity values so i can read them. It’s that simple…

Hope you can help me out,
Thanks in advance!

//----------------------------------------------------- LIBRARY CODE -----------------------------------------------------\\
#include <SPI.h>
#include "RF24.h"

//----------------------------------------------------- LIBRARY CODE -----------------------------------------------------\\




RF24 radio(7,8);
byte addresses[][6] = {"1Node","2Node"};

int intensity = 0;







void setup() {
  Serial.begin(115200);
  Serial.println("Setup reset");

  radio.begin();
  radio.setPALevel(RF24_PA_LOW);                                    // Set the PA Level MAX (>250m)
  radio.openWritingPipe(addresses[1]);                              // Open communication Pipe 1
  radio.openReadingPipe(1,addresses[1]);                            // Listen on communication Pipe 1
  radio.openReadingPipe(2,addresses[0]);                            // Listen on communication Pipe 2
  radio.startListening(); 
}

void loop() {
  if(radio.available()){
    while(radio.available()) {
      radio.read( &intensity, sizeof(unsigned long) );
    }
    radio.stopListening();
    Serial.print("Hello World");
    radio.startListening();
  }
}

Set pin 10 as an output. If it is not connected to anything then noise (possibly radiated from the serial output) can put your Arduino into SPI receive mode.

If this doesn't work, let us know where you got rf24.h from. A quick google search shows there are at least two versions out there.

Thanks for your reply!

I will check it monday

This looks a bit fishy

radio.read( &intensity, sizeof(unsigned long)

considering that intensity is an int.

My guess is that your code is saving the incoming data in places it has no business being.

It should be

radio.read( &intensity, sizeof(intensity)

I got my nRF24s working with this Tutorial

The pair of programs in this link may be useful.

They require the TMRh20 version of the RF24 library which solves some problems from the earlier ManiacBug version

…R

First of all, thanks Robin2 and MorganS for replying.

The real issue was my wrong declaration of intensity. I made it an unsigned long instead of an integer and the problem was fixed.

Set pin 10 as output shows no difference but I've done it to prevent any disruptions in the future.

Thanks for helping me out!