Go Down

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

JeromeAriola

Hello all

I was planning on building a quadcopter that uses nrf24l01 as the wireless communication. But my problem is how do I send, let's say a potentiometer input for yaw, will be sent by Tx to Rx where Rx will tell the nano connected to it to make the motors move.

But online, people doing these demos only send text. So how can i send a command?

Also, my pots are I think 'spring return' or something (similar to xbox controller pots)

Lastly can someone show me a wiring diagram with the nano, nrf24l01, and the pots

Thanks in advance

Robin2

This Simple nRF24L01+ Tutorial should help get you started.

And if you want the joystick to hold position when it is released have a look at this Thread

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

JeromeAriola

#2
Mar 14, 2017, 11:16 pm Last Edit: Mar 14, 2017, 11:23 pm by JeromeAriola
Wow... I haven't seen those threads during my research. Thanks a lot, Robin!
Those nrf24l01 + are practically the same as the pa+lna version, right?

For the command sending, can you give me a more in-depth explanation (sorry, idiots need longer explanations) covering how I can send a yaw or roll command to the other module for it to make the quadcopter's motors move accordingly? (I don't think I get all the "byte business" and packet sending... like "if packet==byte value, move motors...")

Hope you understand what I'm trying to say.

Thanks again!!

Robin2

You need to think of your programs as having separate parts.

One part collects data from sensors and stores it in a suitable place. Another part takes data from that place and sends it by wireless.

The nRF24 has no idea what the data represents. It just sends or receives bytes.

The simplest way is to put the data into an array (of bytes or ints to suit your needs) and send the array. On the receiving side you need to define an identical array to take the incoming data. If you need a collection of data with different data types you can use a struct - but that is more complicated.

Following that it will be a lot easier to help you if you try to adapt one of my examples to your needs. If you only need one-way communication use the first example. For two way communication I recommend the second example.

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

JeromeAriola

Okay, that helped to clarify some thinking about my communication...
So the "commands" are converted into packets in arrays, right? Each command has a different packet size or something.

Correct me if I'm wrong
Jerome

Robin2

Okay, that helped to clarify some thinking about my communication...
So the "commands" are converted into packets in arrays, right? Each command has a different packet size or something.
I think you are still confusing the collection of data from its transmission.

Post an example of the data you want to transmit - (without regard for the wireless details)

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

JeromeAriola

#6
Mar 15, 2017, 11:23 am Last Edit: Mar 15, 2017, 12:14 pm by JeromeAriola
For the example of what I want to send:
   I want to tell the Arduino on Tx to make the motors move so that the quad increases altitude.
Random question: is this worth reading? (https://www.google.com/url?sa=t&source=web&rct=j&url=http://www.diyembedded.com/tutorials/nrf24l01_0/nrf24l01_tutorial_0.pdf&ved=0ahUKEwiv04uepdjSAhWBKJQKHf19AYcQFgh5MA4&usg=AFQjCNEqmGpwhF_xGOOpDMRtwdGfh3Lk4w)
Also, I found something on Images I'm unsure about. It's where the rf module connects to the arduino:

IRQ---------------------nothing   MISO-----------------Pin12
MOSI------------------PWM       SCK-------------------Pin 13
CSN-------------------PWM        CE----------------------PWM
VCC--------------------3.3V        GND-------------------GND


Robin2

For the example of what I want to send:
   I want to tell the Arduino on Tx to make the motors move so that the quad increases altitude.
I need something  much more specific. For example you might want to send a value for motor speed, and another value for direction - so (perhaps) two int values.

In other words, what numbers need to go from the controller to the 'copter?

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

JeromeAriola

Okay so here is some pseudocode (don't know how to write in a C based lang or even Arduino):
 

int motorVal = 0                                                                            //initializer-thing to say motors are off
 if receive signal = <a value equalling altitude> {
    <add a value below 100 for every change in ohms from potentiometer signal>
  }
  for(motorVal =0; motorVal >=100; motorVal++;){
   if <pot value is a certain ohms>{
     motorVal++;
     }

  }


  while (motorVal >= 100 ) {             //if receiving a signal from nrf, and it's above a certain ohms
    allMotors (255)                             //turn motors full speed
  }
 

Robin2

if receive signal = <a value equalling altitude> {
I'm just focusing on this line as it seems to be the only part relevant to the wireless communication.

It seems to expect a single value. But it is a value for height whereas in your Original Post you mentioned yaw. That makes me wonder if you need to send a yaw value as well as a height value. And maybe you need to send other values as well,

To start with, forget all about program code and just describe what needs to happen using plain English.

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

JeromeAriola

Okay... sorry for the bad coding. We'll use altitude from now on.

So because I am trying to make the 'copter go up, I must turn on all the motors to a point where the vehicle elevates, right? What I think should be done in the code is that I would have a value that's zero (motorVal) on the Rx side (if it's false or if pot is a point where it means "not sending a signal"), and if Arduino on Tx sends a "true" value to Rx, Arduino on Rx will update the variable motorVal with a PWM value (255, which is  max if I'm not mistaken). Thus, the vehicle will climb while my pot value on Tx is true and the Rx is receiving a signal.

You were gonna show me the code on how to make the NRF do the transmission, right?
Thanks

SamIAm93

Are you writing your own quadcopter flight controller program for any particular reason? There are tons of arduino based control boards that will get you in the air much easier. The control of the quad will include a PID loop for pitch, roll and yaw. You mention altitude, you will likely need a barometric pressure sensor as GPS altitude won't be accurate enough.

Go buy yourself some nRF24's and go through the tutorials and look at the example code that comes with the libraries. Most of your questions will be answered.

Robin2

You were gonna show me the code on how to make the NRF do the transmission, right?
I did show you - in Reply #1

From the rest of the text in Reply #10 I get the distinct impression that you have not bothered studying the code in the links I gave you. If all you want to do is send a single number to the 'copter then all the code you need is in the nRf24 tutorial. Was I just wasting my time writing Reply #1?

However trying to control a 'copter by sending a single number representing altitude and without any form of direction or position control seems very strange.

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

JeromeAriola

However trying to control a 'copter by sending a single number representing altitude and without any form of direction or position control seems very strange.
I guess that's where the gyroscope enters...

Okay so I actually took time to read everything, because last time I just skimmed though it. Now it seems that my problem is in understanding the real prob: command sending. Right now I see the solution as an of statement, where if it receives a packet or a payload that contains a message like 'Time to go up now!', the slave side, which is the vehicle, will react accordingly.

So maybe...
 if receive message = Time to go up now!,
   all motors full power until I stop receiving this message

And are the 'radio.available' and 'radio.startListening' part of what was in the library that was hash included? (I clearly don't know anything about libraries...)

I really appreciate the effort and help you have given me in this thread and in the other.

Robin2

So maybe...
 if receive message = Time to go up now!,
   all motors full power until I stop receiving this message
Keep the message short so it is easy to figure it out. Rather than "Time to go up now!" just send 'U'

It would be a good idea to send a message perhaps 5 or 10 times per second so that the 'copter will know that the absence of a message means the communication has failed.

But do NOT rely on the absence of a message to mean anything other than a communication failure. Send another message (perhaps 'L' for Level or 'D' for down) when you want something else to happen.

Quote
And are the 'radio.available' and 'radio.startListening' part of what was in the library that was hash included? (I clearly don't know anything about libraries...)
Yes. You really need to study the library documentation carefully. Otherwise you will be buying a new 'copter after a crash.

...R

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy