|
Post by RC Tractor Guy on May 14, 2015 9:24:23 GMT
I didn't try it honestly as i was working through understanding it.. I will try it this werkend as well. Thnaks, Gfink Ah okay, well just check that it worked in case it's something wrong with the original code that I haven't encountered before.
|
|
|
Post by Leif on May 15, 2015 12:18:16 GMT
Hi, i figured it out. It´s working now. I think the main thing was a power issue. I had the receiver arduino uno connected to the pc with a 5 meter usb kabel. thats not very good ^^. I changed it to a 30cm long one. The sender arduino nano is now powered with a 7.4V lipo batterie and has got a lm1117 3.3 V voltage regulater and 4uF capacitor for the nrf24. in the next days i will do a range test outside. hope it transmitts over a hundred meters.
|
|
|
Post by RC Tractor Guy on May 15, 2015 16:50:45 GMT
Great you got it going, maybe the resistance in the 5m cable dropped the voltage too low for the Arduino or something.
100m line of sight might be a bit too far if you're using the modules with the IFAs. If it is you could switch to the SMA modules and use a higher gain or directive antenna to achieve your wireless link.
|
|
|
Post by Leif on May 16, 2015 13:16:34 GMT
Hi,
yes 100 meters is way to far. do you know with wich module i can transmitt over such a distance?
Leif
|
|
|
Post by RC Tractor Guy on May 17, 2015 22:30:27 GMT
There is an NRF24L01+ module with a power amplifier and low noise amplifier all on the one board, couple that with an external antenna and I'd say you'd be able to achieve more than 100m but I don't know for sure I haven't used those. It would probably do it with a normal dipole antenna, you might not need a directive antenna.
|
|
|
Post by GFink on May 27, 2015 11:46:37 GMT
RC Tractor Guy... I want to say thank you very much sir.. from your examples, troubleshooting pointers, and wisdom, I was able to get my simple little sensor project working. Granted it's not perfect, but man what a sense of accomplishment it is just to get this going. As I'd mentioned previously and following your example, below is the simplified code, i'm planning to go back and implement your ID method so I can have multiple sensors, but for now i'd eliminated as I only had (1) sensor. Again THANK YOU for your time and efforts I truly appreciate the help sir... Keep up the good work...
Take Care,
GFink
******************* Transmitter Code ****************************** /* NRF24L01 Module Demo Receiver Code Pin Assignment D0 D1 D2 D3 D4 D5 D6 D7 IRSensor D8 NRF24 CE D9 D10 NRF24 CSN D11 NRF24 MOSI D12 NRF24 MISO D13 NRF24 SCK A0 A1 A2 A3 A4 A5 */
// Variables used in the program //int Move_1 = 125; // Variable used to determine the motor direction delete int v_IRGate = 0x00; int v_IRGate_Old = 0x00; int v_IRGate_Button = LOW; int Data_Val_1 = 0; // Include Libraries #include <SPI.h> #include <RH_NRF24.h>
RH_NRF24 nrf24; // Create NRF24 object uint8_t command[11]; // Create array for data to be sent uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; // Create an array buffer for the NRF24 module void setup() { Serial.begin(9600); pinMode(7, INPUT_PULLUP); // IRGate Sensor nrf24.init(); // Initiailize NRF24 radio module nrf24.setChannel(1); // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm); } void loop() { uint8_t buf[11]; // Create array to store it in uint8_t len = sizeof(buf); if (nrf24.recv(buf, &len)) // Store the data { Data_Val_1 = buf[5]; // Store the new data value Check_Sensors(); } } void Check_Sensors(){ v_IRGate_Button = digitalRead(7); if (v_IRGate_Button==LOW) { command[5]=1; Serial.println (command[5]); } Send_Data(); }
// Function to send the data void Send_Data(){ uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); nrf24.send(command, sizeof(command)); nrf24.waitPacketSent(); } ******************* Transmitter Code ******************************
******************* Receiver Code ****************************** /* NRF24L01 Module Demo Controller Code Pin Assignment D0 D1 D2 D3 D4 D5 D6 D7 IRGate Speaker Alarm D8 NRF24 CE D9 D10 NRF24 CSN D11 NRF24 MOSI D12 NRF24 MISO D13 NRF24 SCK A0 A1 A2 A3 A4 A5 */
// Variables used in the program byte Data_Val_1 = 0x00; // Stores the data value
// Music Info Start int ledPin = 13; int speakerOut = 7; byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p"; // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0; int count2 = 0; int count3 = 0; int MAX_COUNT = 24; int statePin = LOW; // Music Info End
// Include Libraries #include <SPI.h> #include <RH_NRF24.h>
// NRF24 Communication Setup RH_NRF24 nrf24; // Create NRF24 object
void setup() { Serial.begin(9600); pinMode(7, OUTPUT); // Speaker // initialize the radio module nrf24.init(); nrf24.setChannel(1); nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm); } void loop() { if (nrf24.available()) // If the NRF24 has recieved data { uint8_t buf[11]; // Create array to store it in uint8_t len = sizeof(buf); if (nrf24.recv(buf, &len)) // Store the data { Data_Val_1 = buf[5]; // Store the new data value Serial.println (Data_Val_1); } Music(); } } void Music() { analogWrite(speakerOut, 0); for (count = 0; count < MAX_COUNT; count++) { statePin = !statePin; digitalWrite(ledPin, statePin); for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) { for (count2=0;count2<8;count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut,500); delayMicroseconds(tones[count2]); analogWrite(speakerOut, 0); delayMicroseconds(tones[count2]); } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut, 0); delayMicroseconds(100); } } } } }
******************* Receiver Code ******************************
|
|
|
Post by GFink on May 27, 2015 11:52:21 GMT
|
|
|
Post by RC Tractor Guy on May 29, 2015 10:26:36 GMT
RC Tractor Guy... I want to say thank you very much sir.. from your examples, troubleshooting pointers, and wisdom, I was able to get my simple little sensor project working. No problem, I'm glad to hear it is working for you. I tried out a different library suggested by another forum member this week which seems to be better with multiple NRF modules talking to each other and also I think it's a smaller librrary so the code runs much faster. I'll post this update when I'm sure it's working okay and it only requires small changes to the existing code so it might benefit you too. Good suggestions for leif, the low noise amplifier and power amplifier in that module coupled with a good antenna should give a great range.
|
|
|
Post by Buddy on Jun 17, 2015 19:56:12 GMT
Hi tractor guy, looking to make wireless turn signal with 2 pro mini , I have everything communicating do you have something simple program to send 2 separate button variables and receive them on the other side to turn led on and off , a small sample 1 led style I can grow it from there
by the way I am using pins 9,10 as in maniac bug example.
thanks,
|
|
|
Post by RC Tractor Guy on Jun 18, 2015 11:25:54 GMT
looking to make wireless turn signal with 2 pro mini , I have everything communicating do you have something simple program to send 2 separate button variables and receive them on the other side to turn led on and off , a small sample 1 led style I can grow it from there Hi, I just cut the sections you don't need from some of my rc tractor code but I haven't had time to test it. It should work since I don't think I changed anything important. controller: // Define variables int Left_Joy_Button = LOW; int Right_Joy_Button = LOW;
#include <SPI.h> #include "RF24.h"
RF24 radio(9,10);
// Controller Address const uint64_t pipe = 0xE8E8F0F0E1LL;
/*-----( Declare Variables )-----*/ uint8_t command[16]; // 2 element array of unsigned 8-bit type, holding Joystick readings
void setup() { pinMode(2, INPUT_PULLUP); // A Button pinMode(3, INPUT_PULLUP); // B Button
radio.begin(); radio.openWritingPipe(pipe); }
void loop() { Check_Buttons(); delay(100); }
void Check_Buttons(){ // Check Joystick Switches Left_Joy_Button = digitalRead(2); Right_Joy_Button = digitalRead(3);
if (Right_Joy_Button==LOW) {
if (command[0] != 1){ command[0]=1; // Command to turn on right indicator } else { command[0]=0; // Turn off Indicators }
// Wait for switch to be released while (Right_Joy_Button == LOW) { Right_Joy_Button = digitalRead(3); } Send_Data(); } else if (Left_Joy_Button==LOW) {
if (command[1] != 1){ command[1]=1; // Command to turn on right indicator } else { command[1]=0; // Turn off Indicators }
// Wait for switch to be released while (Left_Joy_Button == LOW) { Left_Joy_Button = digitalRead(2); } Send_Data(); } }
// Function to send the data void Send_Data(){ radio.write(command, sizeof(command)); }
receiver: // Variables used in the program byte Data_Val_1 = 0; // Stores the data value byte Data_Val_2 = 0; // Stores the data value byte Old_Data_Val_1 = 0; // Stores the data value byte Old_Data_Val_2 = 0; // Stores the data value
uint8_t buf[16];
#include <SPI.h> #include "RF24.h"
RF24 radio(8,10);
// Controller Addresses const uint64_t Controller_1 = 0xE8E8F0F0E1LL;
void setup() { Serial.begin(9600);
pinMode(3, OUTPUT); // Front Work lights pinMode(5, OUTPUT); // Rear Work Lights
radio.begin(); radio.openReadingPipe(1,Controller_1); radio.startListening(); }
void loop() { Data_Check(); LED_Control(); }
void Data_Check(){ if (radio.available())radio.read(buf, 16);{ Data_Val_1 = buf[0]; // Store the controller left joystick x value Data_Val_2 = buf[1]; // Store the controller left joystick y value } }
void LED_Control(){ if(Data_Val_1!=Old_Data_Val_1){ if(Data_Val_1 == 1){ // Work Lights digitalWrite(3, HIGH); // turn it on } else{ digitalWrite(3, LOW); // turn it on } Old_Data_Val_1=Data_Val_1; }
if(Data_Val_2!=Old_Data_Val_2){ if(Data_Val_2 == 1){ digitalWrite(5, HIGH); // turn it on } else{ digitalWrite(5, LOW); // turn it on } Old_Data_Val_2=Data_Val_2; } }
|
|
|
Post by RC Tractor Guy on Jun 18, 2015 22:14:39 GMT
I think this controller code is what you're looking for
// Define variables int Left_Joy_Button = LOW; int Right_Joy_Button = LOW;
#include <SPI.h> #include "RF24.h"
RF24 radio(9,10);
// Controller Address const uint64_t pipe = 0xE8E8F0F0E1LL;
/*-----( Declare Variables )-----*/ uint8_t command[16]; // 2 element array of unsigned 8-bit type, holding Joystick readings
void setup() { pinMode(2, INPUT); // A Button pinMode(3, INPUT); // B Button
radio.begin(); radio.openWritingPipe(pipe); }
void loop() { Check_Buttons(); delay(100); }
void Check_Buttons(){
// Check Joystick Switches Left_Joy_Button = digitalRead(2); Right_Joy_Button = digitalRead(3);
if (Right_Joy_Button==LOW) { command[0]=0; // Command to turn on right indicator } else { command[0]=1; // Turn off Indicators } if (Left_Joy_Button==LOW) { command[1]=0; // Command to turn on right indicator } else { command[1]=1; // Turn off Indicators }
}
// Function to send the data void Send_Data(){ radio.write(command, sizeof(command)); }
|
|
|
Post by hakuna matata on Jun 21, 2015 10:38:12 GMT
RC Tractor Guy Can you help me ? this is my codes TX and RX but I haven't Joystick Push Button , I used simple Push Button please check my codes and tell my what is the wrong? ---------------------------------------------------------------------------------------- // Transmitter Code // Pin Connections for Arduino UNO /* 1 - GND 2 - VCC 3.3V !!! NOT 5V 3 - CE to Arduino pin 9 4 - CSN to Arduino pin 10 5 - SCK to Arduino pin 13 6 - MOSI to Arduino pin 11 7 - MISO to Arduino pin 12 8 - UNUSED */
/* import needed Libraries*/ #include <SPI.h> // Call SPI Library #include <nRF24L01.h> // Call NRF Version Library #include <RF24.h> // RF24 Header File
/*-----( Declare Constants and Pin Numbers )-----*/ #define CE_PIN 9 #define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/*-----( Declare objects )-----*/ RF24 radio(CE_PIN, CSN_PIN); // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 /*-----( Declare Variables )-----*/
// digital pin 2 has a pushbutton attached to it. Give it a name: int left = 2; int right = 3; int straight = 4; int forward = 5; int back = 7; int light = 6;
// the setup routine runs once when you press reset: void setup() /****** SETUP: RUNS ONCE ******/ { Serial.begin(2400);
radio.begin();//Intializing NRF24L01 Module //Choose a high channel in order to prevent an interference. // optionally, reduce the payload size. seems to radio.setPALevel( RF24_PA_MAX ) ; // max power radio.setDataRate( RF24_250KBPS ) ; //Min speed (for better range from Datasheet) radio.openWritingPipe(pipe);// For Transmitting Operation, Must OpenWritingPipe // make the pushbutton's pin an input: digitalWrite(left,HIGH); digitalWrite(right,HIGH); digitalWrite(straight,HIGH); digitalWrite(forward,HIGH); digitalWrite(light,HIGH); digitalWrite(back,HIGH); pinMode(left, INPUT_PULLUP); pinMode(right, INPUT_PULLUP); pinMode(straight, INPUT_PULLUP); pinMode(forward, INPUT_PULLUP); pinMode(light, INPUT_PULLUP); pinMode(back, INPUT_PULLUP);
}
// the loop routine runs over and over again forever: void loop() { if(digitalRead(forward) == LOW && digitalRead(right) == HIGH && digitalRead(left) == HIGH ){ Serial.print("A"); } else if(digitalRead(forward) == LOW && digitalRead(right) == LOW && digitalRead(left) == HIGH){ Serial.print("B"); } else if(digitalRead(forward) == LOW && digitalRead(left) == LOW && digitalRead(right) == HIGH){ Serial.print("C"); } else if(digitalRead(right) == LOW && digitalRead(left) == HIGH && digitalRead(forward) == HIGH && digitalRead(back) == HIGH){ Serial.print("D"); } else if(digitalRead(left) == LOW && digitalRead(right) == HIGH && digitalRead(forward) == HIGH && digitalRead(back) == HIGH){ Serial.print("E"); } else if(digitalRead(back) == LOW && digitalRead(left) == HIGH && digitalRead(right) == HIGH){ Serial.print("F"); } else if(digitalRead(back) == LOW && digitalRead(right) == LOW && digitalRead(left) == HIGH){ Serial.print("G"); } else if(digitalRead(back) == LOW && digitalRead(left) == LOW && digitalRead(right) == HIGH){ Serial.print("H"); } else if(digitalRead(light) == LOW){ Serial.print("IXD"); } delay(1); // delay in between reads for stability }
--------------------------------------------------------------------------------------------------------- // Receiver Code // Pin Connections for Arduino UNO /* 1 - GND 2 - VCC 3.3V !!! NOT 5V 3 - CE to Arduino pin 9 4 - CSN to Arduino pin 10 5 - SCK to Arduino pin 13 6 - MOSI to Arduino pin 11 7 - MISO to Arduino pin 12 8 - UNUSED */
/*-----( Import needed libraries )-----*/ #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> /*-----( Declare Constants and Pin Numbers )-----*/ #define CE_PIN 9 #define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type const uint64_t pipe = 0xE8E8F0F0E1LL; // Write Same Address of Transmitter
/*-----( Declare objects )-----*/ RF24 radio(CE_PIN, CSN_PIN); // Create a Radio /*-----( Declare Variables )-----*/
// digital pin 2 has a pushbutton attached to it. Give it a name: int left = 2; int right = 3; int straight = 4; int forward = 5; int light = 6; int back = 7; char letter;
// the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(2400); // make the pushbutton's pin an input: digitalWrite(left,LOW); digitalWrite(right,LOW); digitalWrite(straight,LOW); digitalWrite(forward,LOW); digitalWrite(light,LOW); digitalWrite(back,LOW); pinMode(left, OUTPUT); pinMode(right, OUTPUT); pinMode(straight, OUTPUT); pinMode(forward, OUTPUT); pinMode(light, OUTPUT); pinMode(back, OUTPUT); // optionally, reduce the payload size. seems to radio.setPALevel( RF24_PA_MAX ) ; // max power radio.setDataRate( RF24_250KBPS ) ; //Min speed (for better range from Datasheet) radio.openReadingPipe(1,pipe);// Open Reading Pipe to Receiving data radio.startListening(); // Start listening on the pipes opened for reading.
}
// the loop routine runs over and over again forever: void loop() { if (Serial.available() > 0) { // read the incoming byte: letter = char(Serial.read()); //go direct .. if(letter == 'A') { digitalWrite(forward,HIGH); digitalWrite(left,LOW); digitalWrite(right,LOW); // digitalWrite(straight,HIGH); digitalWrite(light,LOW); digitalWrite(back,LOW); } //go right .. else if(letter == 'B') { digitalWrite(forward,HIGH); digitalWrite(left,LOW); digitalWrite(right,HIGH); digitalWrite(light,LOW); digitalWrite(back,LOW); } //go left .. else if(letter == 'C') { digitalWrite(forward,HIGH); digitalWrite(left,HIGH); digitalWrite(right,LOW); digitalWrite(light,LOW); digitalWrite(back,LOW); } //stop right else if(letter == 'D') { digitalWrite(right,HIGH); digitalWrite(left,LOW); digitalWrite(forward,LOW); digitalWrite(light,LOW); digitalWrite(back,LOW); } //stop left else if(letter == 'E') { digitalWrite(right,LOW); digitalWrite(left,HIGH); digitalWrite(forward,LOW); digitalWrite(light,LOW); digitalWrite(back,LOW); } //straight back else if(letter == 'F') { digitalWrite(forward,LOW); digitalWrite(left,LOW); digitalWrite(right,LOW); digitalWrite(light,LOW); digitalWrite(back,HIGH); } //back right else if(letter == 'G') { digitalWrite(forward,LOW); digitalWrite(left,LOW); digitalWrite(right,HIGH); digitalWrite(light,LOW); digitalWrite(back,HIGH); } //back left else if(letter == 'H') { digitalWrite(forward,LOW); digitalWrite(left,HIGH); digitalWrite(right,LOW); digitalWrite(light,LOW); digitalWrite(back,HIGH); } else if(letter == 'I') { letter = char(Serial.read()); if(letter == 'X'){ letter = char(Serial.read()); if(letter == 'D') digitalWrite(light,HIGH); } } }else { digitalWrite(forward,LOW); digitalWrite(left,LOW); digitalWrite(right,LOW); digitalWrite(light,LOW); digitalWrite(back,LOW); } delay(5); }
|
|
|
Post by RC Tractor Guy on Jun 22, 2015 8:02:40 GMT
Hi, what exactly is wrong with the code? I could be making a mistake here but your code seems to to be sending everything via UART and I don't see a problem with that. If you want to use the NRF24 radio module you need to use the radio commands for example in your controller code you are saying Serial.print("A"); but if you want to send it with the radio you would have to use radio.write("A");. Your recieve code is doesn't use the NRF24 either but if you look at the example in the post above you'll find the recieve code.
|
|
|
Post by ok , thank you on Jun 22, 2015 14:14:20 GMT
Hi, what exactly is wrong with the code? I could be making a mistake here but your code seems to to be sending everything via UART and I don't see a problem with that. If you want to use the NRF24 radio module you need to use the radio commands for example in your controller code you are saying Serial.print("A"); but if you want to send it with the radio you would have to use radio.write("A");. Your recieve code is doesn't use the NRF24 either but if you look at the example in the post above you'll find the recieve code.
|
|
need help with NRF24L01 code
Guest
|
Post by need help with NRF24L01 code on Jul 28, 2015 19:23:25 GMT
I have watched your videos on you tube about getting started with the NRF24L01 and am getting that to work but Im wanting to make a project with 3 or 4 motors that are controlled by joysticks and with speed control. has anyone got the arduino code written that would work I would very much appreciate it.
|
|