Go Down

Topic: nrf24l01+ module communication (Read 918 times) previous topic - next topic

DovydasNorkunas

Jun 05, 2019, 04:19 pm Last Edit: Jun 05, 2019, 06:39 pm by DovydasNorkunas
I am currently trying to make two boards communicate with each other where one sends potentiometer data, and other receives it and according to it moves servo motor. I am using this tutorial (https://www.youtube.com/watch?v=oIobOWXOJJg), but this is probably tenth tutorial i am using, because none of them worked. Neither this works, but each time when I upload transmitters code servo motor goes to position that potentiometer shows. If I move potentiometer afterwards - nothing happens, but again, after re uploading same transmitter code, if potentiometer is in different position servo motor moves there. I did not changed anything to source code so I wont clutter this post with it, but if it would be good to have it here, just say and i will put it. Controlling Servo motor is not my main goal with those wireless modules, i am just trying to learn how to work with them, so it is very frustrating that nothing works. It would be awesome if you could refer me to reliable information sources. Probably i did not explained it very well so ask me anything, i will try my best to do it.

vinceherman

It is always a good idea to post the code.  Use code tags.

Have you read through the Simple nRF24L01+ 2.4GHz transceiver demo posted by Robin2?

DovydasNorkunas

Thank you very much for your response. I will try this tutorial, it seems to be promising. Here is code I used:


Transmitter code:


/*
---- Transmitter Code ----
Mert Arduino Tutorial & Projects (YouTube)
Please Subscribe for Support
*/

#include <SPI.h>                      //the communication interface with the modem
#include "RF24.h"                     //the library which helps us to control the radio modem

int msg[1];

RF24 radio(5,10);                     //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
                                     
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.


void setup(void){
  radio.begin();                      //it activates the modem.
  radio.openWritingPipe(pipe);        //sets the address of the receiver to which the program will send data.
}

void loop(void){
  msg[0] =  map (analogRead(0), 0, 1023, 0, 179);
  radio.write(msg, 1);
}


Receiver code:


/*
---- Receiver Code ----
Mert Arduino Tutorial & Projects (YouTube)
Please Subscribe for Support
*/

#include <Servo.h>    //the library which helps us to control the servo motor
#include <SPI.h>      //the communication interface with the modem
#include "RF24.h"     //the library which helps us to control the radio modem

Servo myServo;        //define the servo name

RF24 radio(5,10);     /*This object represents a modem connected to the Arduino.
                      Arguments 5 and 10 are a digital pin numbers to which signals
                      CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int msg[1];

void setup(){
  myServo.attach(3);                //3 is a digital pin to which servo signal connected.
  radio.begin();                    //it activates the modem.
  radio.openReadingPipe(1, pipe);   //determines the address of our modem which receive data.
  radio.startListening();           //enable receiving data via modem
  }

void loop(){
  if(radio.available()){            //checks whether any data have arrived at the address of the modem
    bool done = false;              //returns a "true" value if we received some data, or "false" if no data.
    while (!done) {
      done = radio.read(msg, 1);
      myServo.write(msg[0]);
    }
  }
}

PaulS

Code: [Select]
  radio.write(msg, 1);
msg is an int. An int is NOT 1 byte long.

You don't need an int to hold values in the range 0 to 179.

You DO need code tags!
The art of getting good answers lies in asking good questions.

Go Up