nrf24l01

I am trying to use the nrf24l01 module to control a servo from a button across 2 nanos. I can send text but I can't see how to control a servo. Can someone help.

As you have not posted your programs it is hard to help with such a vague question.

I presume you are sending the value that is required for servo.write() ?

...R Simple nRF24L01+ Tutorial

here are the codes…

RF_Client.ino (1.86 KB)

RF_Server.ino (1.78 KB)

For short programs please include them in your post between tags so we don't have to download them. Your code should

look like this

and that also makes it easy to copy to a text editor

I am not familiar with the RF24 library you are using.

Have you tried the examples in the link I gave you?

...R

I did look at it but it does not show how to tell the program if a specific code is sent to move the servo which is the problem i am having.

MR-Turtle:
I did look at it but it does not show how to tell the program if a specific code is sent to move the servo which is the problem i am having.

What specific code?

Can you make the servo do what you want without wireless? If not get that working first.

If so then you just need to send the same data using the wireless. Try it with the first example in my tutorial.

…R

I can controll the servo without wireless. The specific code is the data that is sent when a button is prest the tell the servo to move. Non of the examples you give show how to controll a servo.

MR-Turtle: The specific code is the data that is sent when a button is prest the tell the servo to move

Please post a typical example of that data. At the moment I have no idea what you are trying to do.

...R

You seem to misunderstand something fundamental. You can't send a code that will just automagically cause a servo to move. You can send some numbers over but te receiver program has to receive those numbers and decide what to do with them. The receiver gets the number and then calls servo.write() with that number.

MR-Turtle: I can controll the servo without wireless. The specific code is the data that is sent when a button is prest the tell the servo to move. Non of the examples you give show how to controll a servo.

It is not possible for any list of examples (key word there) to exhaustively cover every single project that someone would attempt to make, and it kind of misses the point. Interpreting and adapting the examples to suit your need is your responsibility. If you want exactly what you need to be handed straight to you, pay someone to make it, there's a section here on the forum for that.

If my understanding of what you're asking for is correct, Reply #1 of Robin's thread already has an excellent skeleton to work from. It gets data, then it does something with the data. In Robin's example, that something is "print to the Serial Monitor". For your project, you want that something to be "change the angle of a servo". The change should be trivial.

This is exactly what i want the code to do. I want to use a button to wirelessly control a servo. I want to know how to tell the code that what the client is sending to the server is the position i want the servo to do. I don't want someone to write the code for me i just need to know how to convert what the client sends to me to a int that the servo can use. The client is sending the position to the server i just want to convert the (char*)buf to an int the servo can use.

To convert ascii to integer use atoi.

i don't understand, what is atoi

atoi

MR-Turtle: i just need to know how to convert what the client sends to me to a int that the servo can use. The client is sending the position to the server i just want to convert the (char*)buf to an int the servo can use.

Look at the parse example in Serial Input Basics

But, to be honest, things are much simpler with an nRF24 because you can send an int and receive an int without any need for conversion. The second example in my tutorial sends ints in the ackPayload. The same techniqe can be used to adapt the first example to send int values.

...R

I don't see in what part of the code you put what is supposed to be sent for the simple tx to the simple rx. all that is being sent for the receiving part is...

SimpleRxAckPayload Starting Data received Message 1 ackPayload sent 108, -4001

and the transmitter is saying...

Source File /mnt/sdb1/SGT-Prog/Arduino/ForumDemos/nRF24Tutorial/SimpleTxAckPayload.ino SimpleTxAckPayload Starting Data Sent Message 1 Tx failed Data Sent Message 1 Tx failed Data Sent Message 1 Tx failed

this is from Robin 2's example.

Please post a photo of a simple drawing showing how YOU have everything connected.

And please post the exact code that YOU have uploaded to your Arduinos.

The examples do work.

...R

// SimpleTxAckPayload - 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';
int ackData[2] = {-1, -1}; // to hold the two values coming from the slave
bool newData = false;

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

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

void setup() {

    Serial.begin(9600);
    Serial.println(F("Source File /mnt/sdb1/SGT-Prog/Arduino/ForumDemos/nRF24Tutorial/SimpleTxAckPayload.ino"));
    Serial.println("SimpleTxAckPayload Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );

    radio.enableAckPayload();

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

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

void loop() {

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

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

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) {
        if ( radio.isAckPayloadAvailable() ) {
            radio.read(&ackData, sizeof(ackData));
            newData = true;
        }
        else {
            Serial.println("  Acknowledge but no data ");
        }
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }

    prevMillis = millis();
 }


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

void showData() {
    if (newData == true) {
        Serial.print("  Acknowledge data ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
}

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

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}
// 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
int ackData[2] = {109, -4000}; // the two values to be sent to the master
bool newData = false;

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

void setup() {

    Serial.begin(9600);

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

    radio.enableAckPayload();
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data

    radio.startListening();
}

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

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

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

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

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

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        Serial.print(" ackPayload sent ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        newData = false;
    }
}

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

void updateReplyData() {
    ackData[0] -= 1;
    ackData[1] -= 1;
    if (ackData[0] < 100) {
        ackData[0] = 109;
    }
    if (ackData[1] < -4009) {
        ackData[1] = -4000;
    }
    radio.writeAckPayload(0, &ackData, sizeof(ackData)); // load the payload for the next time
}

and the pics are to big to upload there all connected as you have them in the example

You have not uploaded a MATCHED PAIR of programs. The program SimpleRx is intended to work with SimpleTx and the program SimpleTxAckPayload is intended to work with SimpleRxAckPayload. I had hoped that would have been obvious.

…R

I have uploaded the wrong code I am useing both askpayload