java.lang.OutOfMemoryError Issue

When running the below code, which supposed to reciever data using a Nrf24, it uploads fine. But when I try to open the serial monitor to verify that it works, I get the following message.

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space

And it won't open. Trying to open in again simply results in the same thing. I am not very good with these things and am at a loss. Any help would be appreciated. My entire sketch is as follows:

#include <nRF24L01.h>
//#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

int fakedata[2];

void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}

void loop()
{
if ( radio.available() )
{
//Read the data payload until we've received everything
bool done = false;
while ( ! done )
{
// get the data payload

done = radio.read( fakedata, sizeof(fakedata) );

Serial.print("[0] = ");
Serial.print("\t");
Serial.print(fakedata[0] , DEC);
Serial.print("\t");
Serial.print("[1] = ");
Serial.print("\t");
Serial.println(fakedata[1] , DEC );
Serial.print("\t");

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

}

Delta_G:
Usually when you see that error it means you've left the closing quote off a string somewhere.

This can happen during compile, not when opening the serial monitor after a successful upload.

In the code there are some basic misunderstandings of the NRF24L01 interface.

  1. radio.available() returns whether data is available, not that there is an operational device.

So in the case of 'there is no data available' (which will happen most of the time)
you are flooding the serial interface with "No radio available" messages, filling the tx buffer up
and slowing your main loop to the speed of the serial running with 9600 baud.

  1. Your while (!done) loop will copy all available packets to the same buffer,
    leaving you with a copy of the last message only.

Both is probably not connected to your crashing serial monitor.

Somehow I have the feeling I have seen this code before, where did you copy it?

Actually, commenting out the else statement seemed to have worked, I guess it was flooding the serial monitor as you suggested. Thanks!

The code came from this page:
https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

The connection info is usefull, but this snippet it more How-Not-To-Do-It.

I applied for a wiki membership to get some influence. :wink:

Hi, My Apologies! I had not updated that code in TOO long a time.

Please see updated page:
https://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

This now recommends the newer RF24 library by TMRH2o which is quite stable.

I have NOT updated the Joystick to Servos page; I am working on that today.