Transmission stops after X seconds/transmissions (nrf24l01+)

So I’ve an analog stick connected to Arduino Uno and the Uno connected to nr424… this is the code below it works for like a few seconds then stops I have some delays commented out, they were my last ditch effort to get it working

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

RF24 radio(7, 8);

const byte address[6] = “00001”;
const byte MaxDataChars = 9;

int raw_X_axis = 0;
int raw_Y_axis = 0;
int X_axis = 8;
int Y_axis = 7;

char transmitChars [MaxDataChars] = “”;
char startMarker [2] = {’<’};
char comma [2]= {’,’};
char endMarker[2] = {’>’};
char Xaxis [4];
char Yaxis [4];

void setup() {
//Serial.begin (9600);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
//radio.stopListening();
radio.setRetries(15,5);
radio.openWritingPipe(address);
}

void loop() {

//Analog stick values are mapped to be able to send
//delay(10);
raw_X_axis = analogRead(A0);
X_axis = map(raw_X_axis, 0, 1023, 0, 255);
//delay(1);
raw_Y_axis = analogRead(A1);
Y_axis = map(raw_Y_axis, 0, 1023, 0, 255);
//delay(1);
itoa(X_axis, Xaxis, 10); //turns the integer values into arrays for easier transmossion
//delay(1);
itoa(Y_axis, Yaxis, 10);

/*Serial.print (“X axis =”);
Serial.println (Xaxis);

Serial.print (“Y axis =”);
Serial.println (Yaxis);
*/

//Bellow puts the values into one array called transmitChars
//delay(1);
strcat(transmitChars,startMarker);
//delay(1);
strcat(transmitChars, Xaxis);
//delay(1);
strcat(transmitChars,comma);
//delay(1);
strcat(transmitChars,Yaxis);
//delay(1);
strcat(transmitChars,endMarker);
//delay(1);
//delay(10);
/Serial.println(transmitChars);
Serial.flush();
/
//Serial.print (“Sendig”);
radio.write(&transmitChars, sizeof(transmitChars)); //Sends the array
//delay(10);
}

This is the receiver code for a nano that currently has LEDs on the outputs 9 and 10 that get brighter and dimmer depending on the PWM. Been working on this for too long, hopefully you guys can see something I’m missing or suggest a better way to do something.

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

RF24 radio(7, 8);

const byte MaxDataChars = 32;
const byte address[6] = “00001”;

const int left_wheels = 9;
const int right_wheels = 10;

int X_axis = 0;
int Y_axis = 0;
char raw_X_axis;
int serialCount = 0;
char command[MaxDataChars];
char tempChars[MaxDataChars];
char data[MaxDataChars];
boolean newData = false;

void setup() {
pinMode(left_wheels, OUTPUT);
pinMode(right_wheels, OUTPUT);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.openReadingPipe(1, address);
radio.startListening();
//Serial.begin (9600);
}
void loop() {
int len =0;

len;
if (radio.available())
{

while (radio.available())
{
//Serial.print (“Receiving”);
len = radio.getDynamicPayloadSize();
radio.read(&tempChars, len);
//String transData = String(tempChars);
/Serial.print(“Recieved array:”);
Serial.print(transData);
//Serial.print(tempChars[0]);
Serial.println();
/
//delay(10);
char * strtokIndx; // this is used by strtok() as an index

strtokIndx = strtok(tempChars,"<,"); // get the first part - the string between ‘<’ and ‘,’
X_axis = atoi(strtokIndx); // convert this part to an integer puts in X_axis

strtokIndx = strtok(NULL, “,>”); // this continues where the previous call left off from ‘,’ to ‘>’
Y_axis = atoi(strtokIndx); // convert this part to an integer puts in Y_axis

/Serial.print("X_Axis = "); //print on serial the text in quotes
Serial.println(X_axis);
delay (100);
Serial.print("Y_Axis = "); //print on serial the text in quotes
Serial.println(Y_axis);
delay (100);
/
//delay(10);
analogWrite (right_wheels, X_axis);
analogWrite(left_wheels, Y_axis);
//delay(10);
}
}
}
A few things commented out that I was using for debugging purposes

nrf_testing_servo.ino (1.44 KB)

nrf_testing__servo_reciever.ino (1.8 KB)

I am guessing you need a null, \0, after each of the strings you are strcat to the output string.

Paul

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R