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.