Them codes aint workin

Now that I have your attention =P

I need some help with my code pretty please, when I run the script nothing happens. The code is set to print a serial message on startup so I can tell that it works but when the code its loaded, no message. I load other code and I get a message but not this code.

Would you mind telling me wtf is going on?

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

RF24 radio(7, 8);

float tempC;
int reading;
int tempPin = 0;
char Mesg[32] = "FAIL";
char receive_payload[33]; // +1 to allow room for a terminating NULL char
String sCompile = "";
unsigned long timer;
int MesgL;

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

const int min_payload_size = 4;
const int max_payload_size = 32;

void setup() {
  Serial.begin(115200);
  Serial.begin("Test1");
  delay(20);
  analogReference(INTERNAL);
  Serial.begin("Initializing...");

  radio.begin();
  radio.enableDynamicPayloads();
  // optionally, increase the delay between retries & # of retries
  radio.setRetries(100, 600);

  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1, pipes[1]);

  radio.startListening();
  // radio.printDetails();

}

void loop() {
  reading = analogRead(tempPin);
  tempC = reading / 9.31;
  Serial.println(tempC);
  delay(1000);
  timer = millis();
  sCompile = "Temp: " + String(tempC) + ", " + "Time: " + timer;
  sCompile.toCharArray(Mesg, 32);
  MesgL = sizeof(Mesg) + 1;

  radio.stopListening();
  Serial.println("Sending message: ");
  Serial.println(sCompile);
  Serial.println("Length: " + MesgL);
  radio.write(Mesg, MesgL);

  radio.startListening();

  // Wait here until we get a response, or timeout
  unsigned long started_waiting_at = millis();
  bool timeout = false;
  while ( ! radio.available() && ! timeout )
    if (millis() - started_waiting_at > 500 )
      timeout = true;

  // Describe the results
  if ( timeout )
  {
    Serial.println(F("Failed, response timed out."));
  }
  else
  {
    // Grab the response, compare, and send to debugging spew
    uint8_t len = radio.getDynamicPayloadSize();

    // If a corrupt dynamic payload is received, it will be flushed
    if (!len) {
      return;
    }

    radio.read( receive_payload, len );

    // Put a zero at the end for easy printing
    receive_payload[len] = 0;

    // Spew it
    Serial.print(F("Got response size="));
    Serial.print(len);
    Serial.print(F(" value="));
    Serial.println(receive_payload);
  }

  // Try again 1s later
  delay(100);
}

P.S.

The code reads a temp sensor, compiles a message and then sends said message over RF24 to my PI. Well that’s what it is suppose to do, but shes dead Jim.

Try putting some delays after the Serial.begin and each Serial.print.
Make sure that where possible, you're using the F() macro to keep the constant strings in flash.

Thanks for the tip, I'll see if it works, wanted to give an update, Still no serial but the receiving node she is now getting the packages.

*Le Edit:

Nope didn't make a difference, I get the packages but no Serial. In practice this aint a problem but I need it for debugging puposes.

All the delays are doing is making sure the serial messages are getting out before allowing the processor on to do the next thing.
It won't cure your problem, but it should make it a little easier to tell where things are going wrong.
A Serial.flush should do the same thing.

Hi,
You only need one Serial.begin
The others should be Serial.print or Serial.println

Tom... :slight_smile:

Ha! I missed the second "begin" (...and third) - I only saw the string, and assumed a print!

Need another coffee.

bahahahaha I have no idea how I missed it, great spot, I was tearing my hair out not understanding why my other test code was working and not hits one. Many thanks =D

Simple nRF24L01+ Tutorial

...R