How do I save a radio.read to a value?

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 :wink:

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 want to send values (e.g. as integers) rather than ASCII text, simply do so.
This code

  radio.write(&text, sizeof(text));

works for any type of variable that happens to be named "text", so change the name to something sensible. Same for the read function.

If you want to convert text strings into values, use standard functions like strtol().

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

Renamed as jremington asked; also:

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

...R

By "rename" i meant to use both an appropriate variable for the data you want to send, and to name it sensibly.

Try this, with similar modifications to the RX program:

#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);
}

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);
    
  }


}

Get rid of the brackets on data_to_send.

Learn about the differences between variables and arrays and how to index array variables.

paradoxlnx:

    Serial.println(data_to_send[32], DEC );

There are two problems with that line.

Because you have a number in square brackets it will only print the character at that position

And, there is no position numbered 32 because arrays are indexed from 0 and the other end is, therefore, 31

Just do

Serial.println(data_to_send);

like in the examples in Serial Input Basics

...R