Go Down

Topic: Can somebody guide me with nrf24l01 command transmission? (Read 1 time) previous topic - next topic

JeromeAriola

So before we close, let me just clarify some things:

1. The nrf24l01 only sends messages which are at maximum 32 bytes (meaning I can only send at max a message like "HelloMyNameIsJeromeAriolaAndIRun", which is a 32 letter message.)

2. My Arduino can take a message, process it to where if I was to send a "U" message it would tell the motors "Hey I received a message U, meaning I turn on all the motors until he says D or something else"

Lastly, can you show me how you connected your nrf24l01 to the Arduino?

Thanks for all the help

Robin2

Lastly, can you show me how you connected your nrf24l01 to the Arduino?
This is ridiculous. I put all those details in the link I gave you in Reply #1. Have you even read it once?

And, yes, a single nRF24 message has a max of 32 bytes. I suspect that will be at least twice as much as you need, but if you need more you can send 2 or 3 messages.

Quote
2. My Arduino can take a message, process it to where if I was to send a "U" message it would tell the motors "Hey I received a message U, meaning I turn on all the motors until he says D or something else"
I don't know whether this means you know what you are doing or you haven't a clue.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

Gosh I keep missing critical details...

I just want to ask: What is a pipe to be exact? It's been confusing me, because to me I think it's a link or something with slave and master.

And you also said that the address is 5 bytes. Does this mean I can only send at max a 27 byte message? I mean, it's not like I'm gonna need that much, but it's nice to know.

Whandall

I just want to ask: What is a pipe to be exact? It's been confusing me, because to me I think it's a link or something with slave and master.

And you also said that the address is 5 bytes. Does this mean I can only send at max a 27 byte message? I mean, it's not like I'm gonna need that much, but it's nice to know.
Do yourself a favour and read the NRF24L01+ datasheet.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Robin2

IMHO the datasheet does not explain the concept of pipes very well - it just tells you how to use them - and even that is sparse enough as @Whandall's experience in another Thread has shown :)

The idea of pipes can be a bit confusing. Think of them as 6 shelves onto which the mail for different residents in an apartment block can be placed. All the letters come through the same mail slot (the radio receiver listening on Channel N) and when they fall on the floor someone picks them up, looks at the name of the recipient (the address the message was sent to) and puts them on the correct shelf (the pipe that has been assigned the same address as the message) or shreds them if they are for a recipient who lives in another block (i.e. if they are for an address that is not assigned to any of the pipes on this nRF24)

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Whandall

The packet format that is used on air is described very detailed.
(And so the non existent influence of the address size on the payload size).

All information about the addressing/pipes is in the datasheet,
admittedly a little bit scattered over the document.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Robin2

All information about the addressing/pipes is in the datasheet,
admittedly a little bit scattered over the document.
It is so nice to meet someone with such a sunny disposition :)

...R
(PS, I am not disagreeing with your statement - just your assumption that the datasheet will make sense to newbies)
Two or three hours spent thinking and reading documentation solves most programming problems.

Whandall

I had to read it a couple of time before I really understood the mechanisms.  ;)

Since the library basically only interfaces to the chips functions, there is no way around the datasheet
to understand the inner workings and limitations of the communication.

But that is only my humble opinion.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

JeromeAriola

I think I get the whole pipe concept. I really do this time.

Okay, thanks guys. You guys have been great a great help, even when I was very stupid. (thanks especially to Robin2)

I think we're done here, although I'll be coming back for extra help. My nrf24l01s just came in, and i want to try some of the stuff you have taught/showed me.

Thanks a million!

Robin2

there is no way around the datasheet to understand the inner workings and limitations of the communication.
I agree completely - but that does not make it easy for a beginner.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

#25
Mar 23, 2017, 02:40 am Last Edit: Mar 24, 2017, 02:29 am by JeromeAriola
Hey, Robin, I found something that I think might help me with my project, but just needs some expert interpretation.

http://www.blog.aeste.my/?p=3690
 Like what are all the "0x99" etc for and how do I know how and when to use them?

Robin2

Hey, Robin, I found something that I think might help me with my project, but just needs some expert interpretation.

http://www.blog.aeste.my/?p=3690
That link does not work.

However you should know in advance that I put all my efforts at interpretation into the link in Reply #1 and I have no plans to reinvent my wheel.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Whandall

The correct link is probably https://blog.aeste.my/?p=3690

As far as I understand that's the reverse-engineering of a quadcopter communication that uses a NRF.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Robin2

The correct link is probably https://blog.aeste.my/?p=3690
Thanks for that.

It seems to use a fairly obvious system - the sort of thing (in simplified form) I have been trying to get the OP to focus on.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

JeromeAriola

#29
Apr 10, 2017, 06:50 am Last Edit: Apr 11, 2017, 06:28 am by Coding Badly
Hey everyone... I'm back... Sorry for my incompetence in my last thread/question, especially to Robin2 (thanks btw man)

I actually got started on my quadcopter code; last time I was just asking for clarification in my mind. Anyway, I'm working on the radio part of it. I got some stuff down, but it's just that I'm not sure whether I should assign a variable called command on both "sides" (Tx and Rx). in the code, you can see that I have char variables reading from the radio, and a function readCommand() that returns what I thought what the radio reads, based on the packets it receives.

I'm stumped on actually sending the command itself. Check out the code; this is for Rx (I've verified it, and of course there are some errors):

Code: [Select]


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

#include <SPI.h>
#include <Servo.h>

Servo backLeft;
Servo backRight;
Servo frontLeft;
Servo frontRight;

#define CE_PIN 14     //A0 pin
#define CSN_PIN 15    //A1 pin

const byte address[6] = "00001";

RF24 radio(CE_PIN, CSN_PIN);

char U = readCommand();
char D = readCommand();
char RL = readCommand();
char RR = readCommand();
char RF = readCommand();
char RB = readCommand();
char YL = readCommand();
char YR = readCommand();

char readCommand()
{
  radio.startListening();
  return radio.read(&command, sizeof(command));
}

void setup()
{
  radio.begin();
  radio.startListening();
  radio.setDataRate(RF24_250KBPS);
  radio.setPayloadSize(8);
  radio.openReadingPipe(0, 00001);
  radio.setRetries(15, 15);
 
  backLeft.attach(5);
  backRight.attach(6);
  frontLeft.attach(9);
  frontRight.attach(10);
 
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
}

//Movement Functions --not tested with drone; full of assumptions

void hover()
{
  backLeft.write(90);           
  backRight.write(90);         
  frontLeft.write(90);
  frontRight.write(90);
}

void altitudeUp()
{
  backLeft.write(170);
  backRight.write(170);     
  frontLeft.write(170);     
  frontRight.write(170);
}

void altitudeDown()
{
  backLeft.write(60);
  backRight.write(60);
  frontLeft.write(60);
  frontRight.write(60);
}

void rollLeft()
{
  backLeft.write(60);
  backRight.write(135);
  frontLeft.write(60);
  frontRight.write(135);
}

void rollRight()
{
  backLeft.write(135);
  backRight.write(60);
  frontLeft.write(135);
  frontRight.write(60);
}

void rollFront()
{
  backLeft.write(135);
  backRight.write(135);
  frontLeft.write(60);
  frontRight.write(60);
}

void rollBack()
{
  backLeft.write(60);
  backRight.write(60);
  frontLeft.write(135);
  frontRight.write(135);
}

void leftYaw()
{
  backLeft.write(60);
  backRight.write(135);
  frontLeft.write(135);
  frontRight.write(60);
}

void rightYaw()
{
  backLeft.write(135);
  backRight.write(60);
  frontLeft.write(60);
  frontRight.write(135);
}


void loop()
{
  //In the event the radio cannot detect Tx, it just hovers.
  if(!radio.available)
  {
    hover();
  }
 
  //Up Altitude
  if(readCommand() == U)
  {
   altitudeUp();
   }else{
   hover();
  }

  //Down Altitude
  if(readCommand() == D)
  {
    altitudeDown();
    }else{
    hover();
  }

  //Left Roll
  if(readCommand() == RL)
  {
    rollLeft();
    }else{
    hover();
  }

  //Right Roll
  if(readCommand() == RR)
  {
    rollRight();
    }else{
    hover();
  }

  //Front Roll or Pitch Down
  if(readCommand() == RF)
  {
    rollFront();
    }else{
    hover();
  }

  //Back Roll or Pitch Up
  if(readCommand() == RB)
  {
    rollBack();
    }else{
    hover();
  }

  //Left Yaw
  if (readCommand() == YL)
  {
    leftYaw();
    }else{
    hover();
  }

  //Right Yaw
  if(readCommand() == YR)
  {
    rightYaw();
    }else{
    hover();
  }
}



Tx here (note that the command functions are empty for radio communication):

Code: [Select]


#include <stdio.h>
#include <printf.h>
#include <nRF24L01.h>
#include <RF24_config.h>
#include <RF24.h>

//Left Potentiometer Shortcuts in Code
#define up /*leftPotentiometer up voltage value*/           
#define down /*leftPotentiometer down voltage value*/       
#define left /*leftPotentiometer left voltage value*/
#define right /*leftPotentiometer right voltage value*/

#define up /*rightPotentiometer up voltage value*/
#define down /*rightPotentiometer down voltage value*/
#define left /*rightPotentiometer left voltage value*/
#define right /*rightPotentiometer right voltage value*/
 
#define CE_PIN   14
#define CSN_PIN 15

const int leftPot = 14; //A0
const int rightPot = 15; //A1

const byte address[6] = "00001";

char rollForward[3] = "RF";
char rollBackward[3] = "RB";
char leftYaw[3] = "YL";
char rightYaw[3] = "YR";

char rollRight[3] = "RR";
char rollLeft[3] = "RL";
char up[3] = 'U'
char down[3] = 'D'

RF24 radio(CE_PIN, CSN_PIN);

//Left Potentiometer Commands
char rollForward = "RF"
char rollBack = "RB"
char yawLeft = "YL"
char yawRight = "YR"

//Right Potentiometer Commands
char altitudeUp = 'U'
char altitudeDown = 'D'
char rollLeft = "RL"
char rollRight = "RR"



void setup(){
  pinMode(leftPot, INPUT);
  pinMode(rightPot, INPUT);

  radio.begin();
  radio.setPayloadSize(8);
  radio.openWritingPipe(0, address);
  radio.setRetries(15, 15);
}

int readLeftPot(){
  return analogRead(leftPot);
}

int readRightPot(){
  return analogRead(rightPot);
}

void loop(){
  int leftPotValue = readLeftPot();
  int rightPotValue =  readRightPot();

//Right Potentiometer Conditionals 
  if(rightPotValue == /*pot value for up*/){
    /*send a message U */
    }

  if(rightPotValue == /*pot value for down*/){
    /*send message D*/
    }

  if(rightPotValue == /*pot value for left roll*/){
    /*serialWrite RL*/
    /*send the message via radio and serial monitor*/
    }
  if(rightPotValue == /*pot value for right roll*/){
    /*send the message RR*/
    }

//Left Potentiometer Conditionals
  if(leftPotValue == /*pot value for forward roll*/){
    /*send the message RF*/
    }
   
  if(leftPotValue == /*pot value for back roll*/){
    /*send the message RB*/
    }

  if(leftPotValue == /*pot value for left yaw*/){
    /*send the message YL*/
    }
   
  if(leftPotValue == /*pot value for right yaw*/){
    /*send the message YR*/
    }
}



In the lines with radio.read(&command, sizeof(command)), I'm not sure whether the variable command is initialized in Rx or Tx...

*The (8) emoji is a closed parentheses with an eight



Moderator edit: [code] [/code] tags added.


Go Up