My TX works, sends text.
on the RX side, I need the content of the radio.read to be saved to a value. (I marked the location of the problem, but I lack the skills to write this text to a value.
As basic as possible please. The content or format of the value that is currently sent, will not change - much
TX (just sends "700000000001")
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
void setup()
{
 radio.begin();
 radio.setRetries(15, 15);
 radio.openWritingPipe(rxAddr);
Â
 radio.stopListening();
}
void loop()
{
 const char text[] = "700000000001";
 radio.write(&text, sizeof(text));
Â
 delay(1000);
}
RX
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const int testLed = 4;
const byte rxAddr[6] = "00001";
char radioCode = 0;
void setup()
{
 pinMode(testLed, OUTPUT);
 digitalWrite(testLed,LOW);
 Â
 while (!Serial);
 Serial.begin(9600);
 Serial.println("Setup");
Â
 radio.begin();
 radio.openReadingPipe(0, rxAddr);
Â
 radio.startListening();
}
void loop()
{Â
 if (radio.available())
 {
 char text[32] = {0};
  radio.read(&text, sizeof(text));
  Serial.println("Incoming: ");
  Serial.println(text);
  radioCode = text; ///////////I KNOW THIS IS THE PROBLEM
 Â
  Serial.println("radioCode: ");
  Serial.println(radioCode);
 }
Â
 if (radioCode == "700000000001"){
  digitalWrite(testLed,HIGH);
  delay(200);
  digitalWrite(testLed,LOW);
  delay(200);
  }
}
If you just want to make a copy of the array text[] then you can use strcpy(). You can see how that is used in the parse example in Serial Input Basics
Robin2:
If you just want to make a copy of the array text[] then you can use strcpy(). You can see how that is used in the parse example in Serial Input Basics
...R
I've tried to implement your str code, but implementation hasn't changed anything, my output for radioCode is still blank.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const int testLed = 4;
const byte rxAddr[6] = "00001";
char radioCode = 0;
const byte numChars = 32;
char tempChars[numChars];
void setup()
{
pinMode(testLed, OUTPUT);
digitalWrite(testLed,LOW);
while (!Serial);
Serial.begin(9600);
Serial.println("Setup");
radio.begin();
radio.openReadingPipe(0, rxAddr);
radio.startListening();
}
void loop()
{
if (radio.available())
{
char radioText[32] = {0};
radio.read(&radioText, sizeof(radioText));
Serial.println("Incoming: ");
Serial.println(radioText);
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars,","); // get the first part - the string
strcpy(radioText, strtokIndx);
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
radioCode = atoi(strtokIndx); // convert this part to an integer
Serial.println("radioCode: ");
Serial.println(radioCode);
}
if (radioCode == "700000000001"){
digitalWrite(testLed,HIGH);
delay(200);
digitalWrite(testLed,LOW);
delay(200);
}
}
it's also very complex to understand this as your script is built very well, but with it's end markers, newData and parsing not really basic imo.
Can I copy the arraytext in my initial script only using strcpy?
You seem to have focused on the wrong part of my example, and made things more complicated than necessary
The use of strcpy() in these lines from my example is what I intended
void loop() {
  recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);
      // this temporary copy is necessary to protect the original data
      // because strtok() used in parseData() replaces the commas with \0
Make sure you have created a big enough array to take the copy of the complete message including its terminating NULL
Hmm, tried to implement what @Robn2 and @jremington are talking about, but to no avail, message is now not correct.
The value that is received is -16931, couldn't find the meaning of this code.
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
const byte rxAddr[6] = "00001";
void setup()
{
 radio.begin();
 radio.setRetries(15, 15);
 radio.openWritingPipe(rxAddr);
 radio.stopListening();
}
void loop()
{
 int data_to_send = 701;
 radio.write(&data_to_send, sizeof(data_to_send));
 delay(1000);
}
Receiver:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8);
int testLed = 4;
const byte rxAddr[6] = "00001";
void setup()
{
 pinMode(testLed, OUTPUT);
 Â
 while (!Serial);
 Serial.begin(9600);
Â
 radio.begin();
 radio.openReadingPipe(0, rxAddr);
Â
 radio.startListening();
}
void loop()
{
 if (radio.available())
 {
  /*char text[32] = {0};
  radio.read(&text, sizeof(text));*/
  int data_to_send[32] = {0};
  radio.read(&data_to_send, sizeof(data_to_send));
 Â
  Serial.println(data_to_send[32], DEC );
  digitalWrite(testLed,HIGH);
  delay(200);
  digitalWrite(testLed,LOW);
  delay(200);
 Â
 }
}