راه اندازی ماژول وایرلس nRF24L01 و سروموتور با اردوینو
ShahBaz | سه شنبه, ۲۷ مرداد ۱۳۹۴، ۱۱:۵۶ ق.ظ
دانلود آموزش فارسی راه اندازی ماژول وایرلس NRF24L01
+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک
y...es posible controlar 4 servos con potenciometros con este modulo.... yo no puedo hacerlo ya realize los codigos de TX y RX y solo funciona para dos!!! tal vez mi codigo este malo... alguien podria ayudarme a solucionarlo? gracias dejo los dos codigod para que los vean.
TX
#include <SPI.h>
#include <nRF24L01.h>
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int potpin_1 = A0;
int val_1;
int potpin_2 = A1;
int val_2;
int potpin_3= A2;
int val_3;
int potpin_4= A3;
int val_4;
void setup(void)
{
radio.begin();
radio.openWritingPipe(pipe);
Serial.begin(9600);
}
void loop()
{
val_1 = analogRead(potpin_1);
val_1 = map(val_1, 0, 1023, 0, 127);
msg[0] = val_1;
radio.write(msg, 1);
Serial.print("Valor Val_1:");
Serial.println(val_1);
delay(300);
val_2 = analogRead(potpin_2);
val_2 = map(val_2, 0, 1023, 128, 255);
msg[0] = val_2;
radio.write(msg, 1);
Serial.print("Valor Val_2:");
Serial.println(val_2);
delay(300);
val_3 = analogRead(potpin_3);
val_3 = map(val_3, 0, 1023, 0, 127);
msg[0] = val_3;
radio.write(msg, 1);
Serial.print("Valor Val_3:");
Serial.println(val_3);
delay(300);
val_4 = analogRead(potpin_4);
val_4 = map(val_4, 0, 1023, 0, 127);
msg[0] = val_4;
radio.write(msg, 1);
Serial.print("Valor Val_4:");
Serial.println(val_4);
delay(300);
}
RX
#include <SPI.h>
#include <RH_RF24.h>
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int data;
int pos1;
int pos2;
int pos3;
int pos4;
void setup()
{
servo1.attach(3);
servo2.attach(7);
servo3.attach(5);
servo4.attach(6);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop()
{
if (radio.available())radio.read(msg, 1);
if (msg[0] <128 && msg[0] >-1)data = msg[0], pos1 = map(data, 10, 254, 7, 177),servo1.write(pos1);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos2 = map(data, 10, 254, 9, 177),servo2.write(pos2);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos3 = map(data, 10, 254, 9, 177),servo3.write(pos3);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos4 = map(data, 10, 254, 9, 177),servo4.write(pos4);
}
TX
#include <SPI.h>
#include <nRF24L01.h>
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int potpin_1 = A0;
int val_1;
int potpin_2 = A1;
int val_2;
int potpin_3= A2;
int val_3;
int potpin_4= A3;
int val_4;
void setup(void)
{
radio.begin();
radio.openWritingPipe(pipe);
Serial.begin(9600);
}
void loop()
{
val_1 = analogRead(potpin_1);
val_1 = map(val_1, 0, 1023, 0, 127);
msg[0] = val_1;
radio.write(msg, 1);
Serial.print("Valor Val_1:");
Serial.println(val_1);
delay(300);
val_2 = analogRead(potpin_2);
val_2 = map(val_2, 0, 1023, 128, 255);
msg[0] = val_2;
radio.write(msg, 1);
Serial.print("Valor Val_2:");
Serial.println(val_2);
delay(300);
val_3 = analogRead(potpin_3);
val_3 = map(val_3, 0, 1023, 0, 127);
msg[0] = val_3;
radio.write(msg, 1);
Serial.print("Valor Val_3:");
Serial.println(val_3);
delay(300);
val_4 = analogRead(potpin_4);
val_4 = map(val_4, 0, 1023, 0, 127);
msg[0] = val_4;
radio.write(msg, 1);
Serial.print("Valor Val_4:");
Serial.println(val_4);
delay(300);
}
RX
#include <SPI.h>
#include <RH_RF24.h>
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
int data;
int pos1;
int pos2;
int pos3;
int pos4;
void setup()
{
servo1.attach(3);
servo2.attach(7);
servo3.attach(5);
servo4.attach(6);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop()
{
if (radio.available())radio.read(msg, 1);
if (msg[0] <128 && msg[0] >-1)data = msg[0], pos1 = map(data, 10, 254, 7, 177),servo1.write(pos1);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos2 = map(data, 10, 254, 9, 177),servo2.write(pos2);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos3 = map(data, 10, 254, 9, 177),servo3.write(pos3);
if (msg[0] >127 && msg[0] <255)data = msg[0], pos4 = map(data, 10, 254, 9, 177),servo4.write(pos4);
}
دانلود آموزش فارسی راه اندازی ماژول وایرلس NRF24L01
+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک
- ۱ نظر
- ۲۷ مرداد ۹۴ ، ۱۱:۵۶
nRF24L01 2.4GHz Radio/Wireless Transceivers How-To
Having two or more Arduinos be able to communicate with each other wirelessly over a distance opens lots of possibilities:
These are a series of 2.4 GHz Radio modules that are all based on the Nordic Semiconductor nRF24L01+ chip. (Details) The Nordic nRF24L01+ integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic including the Enhanced ShockBurst™ hardware protocol accelerator supporting a high-speed SPI interface for the application controller. The low-power short-range (200 feet or so)Transceiver is available on a board with Arduino interface and built-in Antenna for less than $3! See it here.
See: EXAMPLE SOFTWARE SKETCHES AT END OF PAGE:
See: NEW EXAMPLE: Radio link transmitting Joystick positions to a receive unit controlling X,Y Servos that follow the remote Joystick. Uses the RadioHead Library.
NOTE! Power Problems:
Many users have had trouble getting the nRF24L01 modules to work. Many times the problem is that the 3.3V Power to the module does not have enough current capability, or current surges cause problems. Here are suggestions:Range??
Range is very dependent on the situation and is much more with clear line of sight outdoors than indoors with effects of walls and materials. The usual distance quoted by different suppliers for the low-power version module with the single chip is 200 Feet or 100 Meters. This is for open space between units operating at 250KHz. Indoors the range will be less due to walls etc...
We suggest you test two units at your actual locations before making a decision. There are units with an Antenna Preamplifier for the receiver and transmitter power amplifier and external antenna. The range between that type unit and several low-power units will be better than between two low-power units. Every situation is a little different and difficult to get an exact number without actual tests.
Link to nRF24L01+ Data Sheet. You don't have to, but if you want to understand more about what you can do with this "little" radio, download the data sheet. In particular you may want to read pages 7-8-9 ( For Overview and Features), and page 39 (MultiCeiver, which allows 6 Arduinos to talk to a Primary Arduino in an organized manner). Fortunately the board-level products we have take care of many of the physical and electrical details and Antenna Impedance Matching etc., and this library takes care of lots of register initialization and operational details.
There are additional modules which add Transmitter power amplifiers and Receiver preamplifiers for longer distances.. up to 1 Km (3000 feet). See them all here. These modules use an external antenna which can be a simple directly-attached one or a cable-connected antenna with more gain or directivity. Here's what some of these look like:
دانلود آموزش فارسی راه اندازی ماژول وایرلس NRF24L01
+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک
در قالب یک پروژه کاملا عملی
On the left is the low-power version, with it's built-in zig-zag antenna. On the right you can see the pins sticking down (up in this photo) that connect to Arduino. Later we will show the pinout.
Above is the version with Transmit Power amplifier and Receive Preamplifier. Our low-cost antenna is on the unit shown on the right. The same 8 pins connect to Arduino and the same software is used.
Here's a link to a Home-Brew antenna design:
These transceivers use the 2.4 GHz unlicensed band like many WiFi routers, some cordless phones etc.
Transceivers like these both send and receive data in 'packets' of several bytes at a time. There is built-in error correction and resending, and it is possible to have one unit communicate with up to 6 other similar units at the same time.
These amazing low-cost units have a lot of internal complexity but some talented people have written Arduino libraries that make them easy to us. We have other pages that show examples and point to the free software libraries you may need. They all use the same pinout as shown in the following diagram, which is a TOP VIEW (Correction!):
Signal
RF Module
COLOR
Arduino pin for
RF24 Library
Arduino pin for
Mirf Library
MEGA2560 pin
RF24 Library
Arduino Pin for
RH_NRF24
RadioHead Library
MEGA2560 Pin for
RH_NRF24
RadioHead Library
GND
1
Brown
GND *
GND
GND *
GND *
GND *
VCC
2
Red
3.3V *
3.3V
3.3V *
3.3V *
3.3V *
CE
3
Orange
9
8
9
8
8
CSN
4
Yellow
10
7
53
10
53
SCK
5
Green
13
13
52
13
52
MOSI
6
Blue
11
11
51
11
51
MISO
7
Violet
12
12
50
12
50
IRQ
8
Gray
2 *
per library
N/C
N/C
The COLOR is for optional color-coded flat cable such as THIS. We'll add some photos soon showing easiest ways to cable these...
NOTE: These units VCC connection must go to 3.3V not 5.0V, although the Arduino itself may run at 5.0V and the signals will be OK. The NRF24L01+ IC is a 3.3V device, but its I/O pins are 5 V tolerant , which makes it easier to interface to Arduino/YourDuino.
Arduino UNO and earlier versions have a 3.3V output that can run the low-power version of these modules (See Power Problems at the top of this page!), but the high-power versions must have a separate 3.3V supply. The YourDuinoRobo1 has a higher power 3.3V regulator and can be used to run the high-power Power Amplifier type module without a separate 3.3V regulator.
nRF24L01 SOFTWARE AND LIBRARIES:
We will show an example of transmit and receive software below, and there are many examples on the RF24 Library download page. You will need a library of software to run the nRF24L01 radios. There are lots of details but you can ignore many of them that the library will take care of.
Get Maniacbug's excellent RF24 Library:
Download it HERE: (Click "Download ZIP" on the lower right of the page)
Once you have downloaded the ZIP, you should see a folder called RF24-master.ZIP. Change the name of this file to just RF24.ZIP. Double click on the ZIP and you should see a non-ZIP folder also called
RF24-master. Rename this to just RF24 as well.
Then see our page about installing libraries HERE:
When you have the library installed, you can run the examples below.
دانلود آموزش فارسی راه اندازی ماژول وایرلس NRF24L01
+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک
در قالب یک پروژه کاملا عملی
More Information on these pages:
RF24 Library and Examples: Many good details and more features like error correction and Networking.RF24 Network System information: A many-node network under development
ManiacBug's Blog entry and discussion of the Network
RadioHead: A very full-featured Library with support for may different radios, not just nRF24L01:
http://www.airspayce.com/mikem/arduino/RadioHead/index.htmlMirf Library Example: A simpler demonstration
EXAMPLE ARDUINO SKETCHES:
Example: Transmit the position of a Joystick X and Y with one nRF24L01 to another nRF24L01 that will receive and display the Joystick position.
There are two sketches that you can cut and paste into a blank Arduino IDE windows and then save. Upload one to the Arduino that has an nRF24L01 connected, and the joystick or Potentiometers connected. Upload the other into an Arduino with an nRf24L01.
YD_nRF24L01_Transmit_JoyStick
YD_nRF24L01_Receive_JoyStick
Another interesting example: Chat between radios:
https://github.com/stanleyseow/RF24/tree/master/examples
---------------------( COPY: Post for people having nRF24L01 Problems )---------------------
nRF24L01 Intermittent / No operation.
ALWAYS check 3.3V power. Many times intermittent operation is due to power supply regulation issues. Even though the average current may be less than 15ma, apparently there are quick transients when each transmit burst happens.
I used to have nRF24L01 problems. Worked one day / one minute, failed the next. Now I put a 1uf to 10uf capacitor right from GND to 3.3V pins on the modules, and things are MUCH better.
These modules are designed to plug into a baseboard that usually has significant bypass capacitors. If you have them on the end of jumper wires you need extra bypass capacitors.
Try it and let us know here!
-----------------( END COPY )----------------------
دانلود آموزش فارسی راه اندازی ماژول وایرلس NRF24L01
+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک
در قالب یک پروژه کاملا عملی