I have two nRF24L01 modules, they are both attached to a sensor shield that has special ports for this type of module, on Arduino Unos.
Sensor shield, with nRF24LO1 in it
I have this code on the Arduino that is sending the signal:
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <SPI.h>
#include <Wire.h>
//0 = stop, 1 = left, 2 = right, 3 = forward, 4 = backwards
long command;
long last_command;
long Joystick_1_X;
long Joystick_1_Y;
long Joystick_1;
void setup() {
// put your setup code here, to run once:
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setTADDR((byte *)"serv1");
Mirf.payload = sizeof(long);
Mirf.config();
Serial.begin(115200);
}
void loop() {
Joystick_1_X = analogRead(A0);
Joystick_1_Y = analogRead(A1);
if(Joystick_1_X < 450){
command = 1;
}else if(Joystick_1_X > 600){
command = 2;
}else if(Joystick_1_Y > 600){
command = 3;
}else if(Joystick_1_Y < 400){
command = 4;
}else{
command = 0;
}
if(command == last_command){
}else{
Mirf.send((byte *)&command);
last_command = command;
}
}
and this code on the Arduino that is receiving
#include "SPI.h"
#include "Mirf.h"
#include "nRF24L01.h"
#include "MirfHardwareSpiDriver.h"
int TN1= 3;
int TN2 = 4;
int ENA = 9;
int TN4 = 5;
int TN3 = 6;
int ENB = 10;
long data;
void setup() {
pinMode(TN1, OUTPUT);
pinMode(TN2, OUTPUT);
pinMode(TN3, OUTPUT);
pinMode(TN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.payload = sizeof(long);
Mirf.config();
Serial.begin(115200);
Serial.print("begin");
}
void loop() {
// put your main code here, to run repeatedly:
receiveCommand();
if(data == 1){
left();
}else if(data == 2){
right();
}else if(data == 3){
forward();
}else if(data == 4){
backwards();
}else if(data == 0){
stop_rover();
}
}
void receiveCommand(){
if(!Mirf.isSending() && Mirf.dataReady()){
Mirf.getData((byte *)&data);
Mirf.rxFifoEmpty();
Serial.print(data);
}else{
Serial.println("No data to be recieved");
}
}
void forward(){
digitalWrite(ENB, HIGH);
digitalWrite(ENA, HIGH);
digitalWrite(TN4, HIGH);
digitalWrite(TN3, LOW);
digitalWrite(TN1, HIGH);
digitalWrite(TN2, LOW);
}
void backwards(){
digitalWrite(ENB, HIGH);
digitalWrite(ENA, HIGH);
digitalWrite(TN4, LOW);
digitalWrite(TN3, HIGH);
digitalWrite(TN1, LOW);
digitalWrite(TN2, HIGH);
}
void left(){
digitalWrite(ENA, HIGH);
digitalWrite(TN1, HIGH);
digitalWrite(TN2, LOW);
}
void right(){
digitalWrite(ENB, HIGH);
digitalWrite(TN4, HIGH);
digitalWrite(TN3, LOW);
}
void stop_rover(){
digitalWrite(ENB, LOW);
digitalWrite(ENA, LOW);
digitalWrite(TN4, LOW);
digitalWrite(TN3, LOW);
digitalWrite(TN1, LOW);
digitalWrite(TN2, LOW);
}
This was working, and the rover did spin its wheels when the remote broadcasted a signal, but then it just stopped. The sensor shield says that they are plugged into the 3V port, I tried using the RF24 library and that did not work either.
Any help would be greatly appreciated.
-
Could you please try the builtin self test checks that come with RF24 library maintained by TMRh20? Do they all work properly?Avamander– Avamander2015年08月13日 20:26:35 +00:00Commented Aug 13, 2015 at 20:26
-
I uploaded the GettingStarted.ino file to two Arduinos the trasmitting node printed out this Now sending Sent 18204112, Got response 0, Round-trip delay 18204112 microseconds Now sending Sent 28434792, Got response 0, Round-trip delay 28434792 microseconds and the receiving node printed out this Sent response 251854848 Sent response 0Richard Beattie– Richard Beattie2015年08月16日 09:18:34 +00:00Commented Aug 16, 2015 at 9:18
-
Something is wrong. Check your wiring and if you can, solder electrolytic caps to the GND and 3.3V pins of the radio module.Avamander– Avamander2015年08月16日 09:35:15 +00:00Commented Aug 16, 2015 at 9:35
-
There is no wiring the nRF24L01 is plugged into a sensor which is on the arduino, I put a picture of the sensor shield with the nRF24L01 above.Richard Beattie– Richard Beattie2015年08月16日 15:48:03 +00:00Commented Aug 16, 2015 at 15:48
-
Are the defined pins in the sketch right? Could you please solder a cap to the power pins of the radio module?Avamander– Avamander2015年08月16日 17:05:41 +00:00Commented Aug 16, 2015 at 17:05
1 Answer 1
Using the MIRF Library that I got from here, and then using this code to send
Mirf.send((byte *)&command);
while(Mirf.isSending()){
}
and this code to receive
if(!Mirf.isSending() && Mirf.dataReady()){
Mirf.getData((byte *)&data);
Mirf.rxFifoEmpty();
else(){
}
I was able to get it to work