برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی

برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی و

برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی

برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی و

داده هایی در مورد برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی و

تبلیغات
آخرین نظرات

۱ مطلب با کلمه‌ی کلیدی «ماژول Nrf2401» ثبت شده است

راه اندازی ماژول Nrf2401 با اردوینو

ShahBaz | شنبه, ۲۴ مرداد ۱۳۹۴، ۱۱:۱۴ ب.ظ

Simple nrf24L01 with Arduino Sketch and Setup

دانلود آموزش فارسی  راه اندازی ماژول وایرلس NRF24L01

+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک 

در قالب یک پروژه کاملا عملی

nrf24L01

I have been working with the 2.4Ghz nrf24L01 modules on a few projects. These modules are very inexpensive (about US $1.25 ea. when bought in quantities of 2 or more on eBay), and they seem to work well for short range, small payload data transmittal. This walk-through will show you how to wire them up, and then will demonstrate a pair of very basic sketches (one for the sender, and one for the receiver) used to verify that data is being sent wirelessly.

You will need (hardware):
(2) nrf24L01 2.4ghz wireless transcievers
(2) Arduino Uno (or compatible)
(2) LEDs: Red and Green (or whatever you have)
Recommended: male-female jumpers for connecting nrf24L01 modules to Arduino

You will need (software):
Arduino IDE
RF24 libraries by maniacbug (https://github.com/maniacbug/RF24)

The image below shows the view of the nrf24L01 from the top.  Note: the pins are on the bottom-side.  The image shows the top-side.

nrf24l01_draw

This drawing shows the basic connections from nrf24L01 to Arduino.  For this sketch, the only difference between the sender and the receiver will be that two LEDs will need to be added on pins 3 and 5 (or whichever you choose, really).
nrfFritzingBasic

closeup of nrf24l01 to arduino connections
closeup of nrf24l01 to arduino connections
The send and receive Arduino setups.  Pay no attention to the LEDs without resistors.
The send and receive Arduino setups. Pay no attention to the LEDs without resistors.

Once you have the sender and receiver wired up, you will need to upload sketches to each.  All the sender sketch does is send values 0 to 255 to the receiver, repeatedly.

On the receiver side, the sketch just reads the sent data and compares it to the last value received.  If the value received is equal to the last value plus one, the green LED will light.  If it is not, the red LED will light.  This works pretty well to visually display how reliable the signal is.  If you see lots of red, you know you are dropping packets.  Note, though, that this sketch will blink the red LED once each cycle to indicate that a complete 0-255 cycle has taken place.

Again, the idea behind these two simple sketches is to get down to the most basic possible setup for use with nrf24L01.  I hope this helps someone trying out the nrf24L01 transceivers for the first time.  The video embedded below shows the behavior of the receiver when it experiences lost wireless packets.

Sketch for the sender:Sketch for the receiver:

Sketch for the sender:

  #include <nRF24L01.h>
  #include <RF24.h>
  #include <RF24_config.h>
  #include <SPI.h>
  int msg[1];
  RF24 radio(9,10);
  const uint64_t pipe = 0xE8E8F0F0E1LL;
  /*
  this is the most basic sketch I can think of to transmit data from an nrf24l01.
  It loops over the numbers 0-255 continuously and sends each number to the receiving
  unit. I have used this pattern as a test to check for drops in the signal by
  checking the receiving end for gaps between numbers. It's not sophisticated,
  but it seems to work.
  */
   
  void setup(void){
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);}
   
  void loop(void){
   
  for (int x=0;x<255;x++){
  msg[0] = x;
  radio.write(msg, 1);
  }
  }
view rawnrf24l01_basicSend hosted with ❤ by GitHub
Sketch for the receiver:

  #include <nRF24L01.h>
  #include <RF24.h>
  #include <RF24_config.h>
  #include <SPI.h>
  /*
  This is the corresponding sketch to the 'basicSend' sketch.
  the nrf24l01 will listen for numbers 0-255, and light the red LED
  whenever a number in the sequence is missed. Otherwise,
  it lights the green LED
  */
  int msg[1];
  RF24 radio(9,10);
  const uint64_t pipe = 0xE8E8F0F0E1LL;
  int red = 3;
  int green = 5;
  int redNeg = 4;
  int greenNeg = 6;
  int lastmsg = 1;
   
  void setup(void){
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(redNeg, OUTPUT);
  pinMode(greenNeg, OUTPUT);
  digitalWrite(greenNeg, LOW);
  digitalWrite(redNeg, LOW);
  }
   
  void loop(void){
  if (radio.available()){
  bool done = false;
   
  while (!done){
  done = radio.read(msg, 2);
  if (msg[0] != lastmsg +1){
  digitalWrite(red, HIGH);
  digitalWrite(green,LOW);
  }
  else {
  digitalWrite(red,LOW);
  digitalWrite(green,HIGH);
  }
  lastmsg = msg[0];
  Serial.println(msg[0]);
  }
  }
  else {
  digitalWrite(red, HIGH);
  digitalWrite(green,LOW);
  }
  }



 دانلود آموزش فارسی  راه اندازی ماژول وایرلس NRF24L01

+کدهای گیرنده و فرستنده+کتابخانه+پاورپوینت توضیحات و شماتیک 

در قالب یک پروژه کاملا عملی

 

  • ShahBaz