The nRF24L01 - Wire...
 
Notifications
Clear all

The nRF24L01 - Wireless Joystick for Arduino Robot Car with nRF24L01+

40 Posts
13 Users
3 Likes
7,159 Views
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

@rich1860

Thanks, I have found the library but not the youtuber you referred to, do you have a link?


   
ReplyQuote
(@troles)
Member
Joined: 3 years ago
Posts: 14
 
Posted by: @scott

@rich1860

Thanks, I have found the library but not the youtuber you referred to, do you have a link?

I found the youtube video that he suggested, it is :

he gives the code, you have to download it in a .RAR  file (which is a type of zip that i had not used but could open it in winzip, and when unzipped it has code for car adn transmitter, as well as 2 fritz schematics).  I have not tried it yet, but plan to in the next few days.  hoping it helps with the delay issue...  I have tried a few others but have not been happy.  Ultimately I want to get something that responds well with the remote, and then modify the code to get a better response from trying to go "diaganally".  these codes seem to be good for forward, back, turn right, turn left.  But the turn always seems to be more of a twist, and less of a diagonal/vector/curving while moving forward turn when joystick is pushed (for example) to the 2oclock position.  Anyway, all that should be able to be adjusted in the code and the pwm strength and formula.  I just haven't put much time into it because I haven't gotten the nrf24l01 to work well.  (I may even bail on the nrf and go to bluetooth for now, but i am sure that will open up a new can of worms.).  I am still pretty new at all this, but I love it, just wish I had more time to play with it all.  I will post my journey if i find things that can be helpful to others (particularly novices like me).  


   
ReplyQuote
(@rich1860)
Member
Joined: 3 years ago
Posts: 14
 

Thanks for posting the Tube link. I liked this link because it was already written for a four wheel robot. The time delay seems to me is because of the reliable code used in RadioHead. That may be an overkill in a robot since speed is a big factor when controlling the device. Look at the library in RadioHead, it may be possible to convert the reliable code to "one transmission" code, which should go faster. My code probably could be improved, but it is good enough for the students to build their own robot. I would rather see them get into the code and figure out how to make it work better if they want to. And BTW, I am really a novice at the programming, as I mentor the students on building FIRST robots, but others mentor on programming.


   
ReplyQuote
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

Thanks Troles, I think that like you, I'm having trouble with the reliability of Nrf24-01's and perhaps should consider Bluetooth. These modules don't seem to be all that popular in arduino projects and there's probably a reason for that. Still on the lookout for any code like this which drives a servo if anyone sees one. Thanks again.


   
ReplyQuote
 Arlo
(@arlo)
Member
Joined: 3 years ago
Posts: 24
 

@scott

Hi Scott,

       I ran across this searching for adding servos for a pan and tilt to a camera mounted to an Elegoo smart robot 3.0. It  seems you can make the Radiohead library use Timer 2 instead of trying to make the servo library use it. I had to open up the Radiohead library then open the RH_ASK.ccp file. Scroll down about 25 lines to #define RH_ASK_ARDUINO_USE_TIMER2

and uncomment it.

Hope this helps

        Arlo

 


   
ReplyQuote
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

@arlo

Well done Arlo, I'd never have worked that out myself. I'll give it a try. 


   
ReplyQuote
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

Oh dear. I went to "RH_ASK.ccp" and found this block, and uncommented the bottom line to read as below:

// RH_ASK on Arduino uses Timer 1 to generate interrupts 8 times per bit interval
// Define RH_ASK_ARDUINO_USE_TIMER2 if you want to use Timer 2 instead of Timer 1 on Arduino
// You may need this to work around other librraies that insist on using timer 1
// Should be moved to header file
define RH_ASK_ARDUINO_USE_TIMER2

Ran the program and got this error:

A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:34:1: error: 'define' does not name a type; did you mean 'rewind'?
define RH_ASK_ARDUINO_USE_TIMER2
^~~~~~
rewind
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp: In member function 'virtual bool RH_ASK::init()':
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:72:5: error: 'thisASKDriver' was not declared in this scope
thisASKDriver = this;
^~~~~~~~~~~~~
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp: In function 'void __vector_11()':
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:716:5: error: 'thisASKDriver' was not declared in this scope
thisASKDriver->handleTimerInterrupt();

Does anyone know what I did?

This post was modified 3 years ago 2 times by Scott

   
ReplyQuote
 Arlo
(@arlo)
Member
Joined: 3 years ago
Posts: 24
 

@scott

Scott, are you still trying to use Servo. Timer2 library. It might be causing a reverse conflict with servo and radiohead both trying to use timer 2 now. I didn't have to use it at all to get Bill's code and servo library to play nice together.


   
ReplyQuote
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

@arlo,

No, I've now removed that from the library and reinstalled arduino IDE to be safe. I did an experiment to see what happened if I commented out "define RH_ASK_ARDUINO_USE_TIMER2" and got this:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

libraries\Servo\avr\Servo.cpp.o (symbol from plugin): In function `ServoCount':
(.text+0x0): multiple definition of `__vector_11'
libraries\RadioHead\RH_ASK.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.

 

I uncommented it again and got this back:

Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"

A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:34:1: error: 'define' does not name a type; did you mean 'rewind'?
define RH_ASK_ARDUINO_USE_TIMER2
^~~~~~
rewind
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp: In member function 'virtual bool RH_ASK::init()':
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:72:5: error: 'thisASKDriver' was not declared in this scope
thisASKDriver = this;
^~~~~~~~~~~~~
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp: In function 'void __vector_11()':
A:\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:716:5: error: 'thisASKDriver' was not declared in this scope
thisASKDriver->handleTimerInterrupt();
^~~~~~~~~~~~~
exit status 1
Error compiling for board Arduino Uno.

It also throws the above error with Bill's original "nRF24L01+ Joystick Receiver for Robot Car" code, which has no servo libraries enabled.

 

Thanks for your time on this. 

 


   
ReplyQuote
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

Scratch that, I didn't put in the # you said at the beginning of:

#define RH_ASK_ARDUINO_USE_TIMER2

 

I'll carry on and see how I go.

Thanks again.

 

 


   
ReplyQuote
(@scott)
Member
Joined: 3 years ago
Posts: 11
 

@arlo

Mate, you sussed it, thanks so much. It's been weeks and I thought I was going to have to give up.

Scott.


   
ReplyQuote
 Arlo
(@arlo)
Member
Joined: 3 years ago
Posts: 24
 

@scott Hopefully you will not run into the same thing I did. I could get the servo sketch to work or Bill's to work but not at the same time, through trial and error (heavy on the error part) I finally was able to modify Bill's a little to make it work with two joysticks, one for the car and one for the pan and tilt. If you run into this roadblock let me know and I will post the code so you can see what I did.

                               Arlo


   
ReplyQuote
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
 

Hi All, 

My transceivers came in, so I wired up the first sketches, client and server demo. With a lot of trials, I got something working.

* The client sends the canned message, for sure, because the server picks it up.

* The server receives the message, and prints "Hello World" to the serial monitor. So that's confirmed.

* Then the server reports, to the serial monitor, that it sent a response back.

* The client, meanwhile, continually complains of no response back from server, Is the Server running?

So, as I see it, the server says it sends a response, but maybe it really didn't, or it failed. If the server really did send a response, then the client didn't pick it up correctly. So the server messed up, or the client, or maybe both.

I followed along the conversation between Geoff and @codecage, looking for similarities, and looking for good debugging tips.

Has anyone else had a result like I describe above?

I will post code if it helps. This demo is the first, simple one, not the reliable datagram one.

Thanks, John.a

In theory, theory and practice are the same.
In practice, they're different.


   
ReplyQuote
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
 

Forgot to add: this is all running on serial ports /dev/ttyUSB0 and /dev/ttyUSB1, on my Pi 4 with Arduino 1.8.13 (I think). After some youtube digging I found a way to make it work. You just get one Arduino IDE session going, then open the IDE again, another instance, for the other connection. I am using two Arduino Nanos, both connected to a powered USB hub, connected to the Raspberry Pi 4. I think I'm going to be using this technique a lot, for working with transmitter and receiver experiments.

In theory, theory and practice are the same.
In practice, they're different.


   
ReplyQuote
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
 

Here is a picture of my setup, as described above.

Screenshot from 2021 08 16 11 08 19

This is for the reliable datagram demo, with the xmit on the left, with its USB0 serial monitor above the code. On the right is the receiver sketch, with its USB1 serial monitor above it.

So, the "client" side gets some joystick values, tries to send them, and then reports failure of sendtoWait(). On the right, the "server" side starts up OK, far as I can tell, but never receives any transmissions. The "Receiver loop() begin" note appears every 10 minutes, just so I can know it is actually connected.

I should mention that I did get a successful transfer, two datagrams in all these trials. So I'm not sure what to think.

 

In theory, theory and practice are the same.
In practice, they're different.


   
ReplyQuote
Page 2 / 3