About Example 3 - A more complete system of Robin2's tutorial need help please

Hi,
The Example 3 received message with start marker and end marker.
The Robin2's NRF24L01 SimpleTx as below, how to add a start marker '<' and end marker '>' into the message be sent?
I simply added into the line 52 got error.
Thanks
Adam

// Example 3 - Receive with start- and end-markers

const byte numChars = 32;
char receivedChars[numChars];

boolean newData = false;

void setup() {
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
}

void loop() {
    recvWithStartEndMarkers();
    showNewData();
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;
 
    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}
// SimpleTx - the master or the transmitter

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


#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R','x','A','A','A'};


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

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &<dataToSend>, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

ERROR:

Arduino: 1.8.16 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_mar12a\sketch_mar12a.ino: In function 'void send()':

sketch_mar12a:52:26: error: unable to find character literal operator 'operator""dataToSend' with 'char' argument

     rslt = radio.write( &'<'dataToSend'>', sizeof(dataToSend) );

                          ^~~~~~~~~~~~~

Multiple libraries were found for "nRF24L01.h"

 Used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\RF24-master

 Not used: C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\Mirf

exit status 1

unable to find character literal operator 'operator""dataToSend' with 'char' argument



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


You have to try to imagine that not everyone understands what that refers to.

1 Like

You appear to be attempting to mix two different tutorials for unknown reasons.

1 Like

The rf24 packet requires no start nor end markers.

Why are you trying to receive rf24 data with a serial port? To receive data send by the SimpleTx example, use the SimpleRx example and do not change the SimpleTx example.

// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

//===========

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    }
}

If the SimpleRX and SimpleTX programs do not work it is because there is something wrong with your setup. That code has been tested hundreds of times and is known to work. Read and follow the simple rf24 tutorial carefully and you will have a better chance at getting them to work.

1 Like

Great!
Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.