nRF24L01 Module Demo for Arduino

  • A+
所属分类:lcx

From: http://www.elecfreaks.com/203.html


2028_thumb1

First of all, if you have any problem, please feel free to let us kown, and the code do not use Arduino’s SPI library, but softwore imitate SPI, maybe you can modified and complete it.

The nRF24L01 module can be controlled in many ways, one of which is Arduino. We tried and tested it, then made a demo. Let’s see how it works with Arduino.

First of all, of course, you need two Arduino boards and at least two RF modules, one to transmit and the other to receive. If you don’t have, you can get them in our store in a very low cost. (Order nRF24L01 module)

If you use a standard Arduino board, you should use the Arduino board’s 3.3V pin(VDD3V3) to provide power. Beacuse the nRF24L01 module is worked at 1.9-3.6V voltage level. Please note, do not use 5V pin(VDD5V) to provide power, which may destroy it.

The Demo pins to Arduino as below:

GND – GND, VCC – 3.3V, CS – D8, CSN – D9, SCK – D10, MOSI – D11, MISO – D12, IRQ – D13

Download the code below into the TX Arduino (transmit) — This code will drive the nRF24L01 module to send out data form 0×00 to 0xFF .

Note, between the write TX_FIFO and clear RX_DR or TX_DS or MAX_RT interrupt flag, would better not serial print anything, which maybe case ACK failed.

void setup()
{
  SPI_DIR = ( CE + SCK + CSN + MOSI);
  SPI_DIR &=~ ( IRQ + MISO);
  //  attachInterrupt(1, _ISR, LOW);// interrupt enable
  Serial.begin(9600);
  init_io();                        // Initialize IO port
  unsigned char status=SPI_Read(STATUS);
  Serial.print("status = ");
  Serial.println(status,HEX);      // read the mode’s status register, the default value should be ‘E’
  Serial.println("*******************TX_Mode Start****************************");
  TX_Mode();                       // set TX mode
}
void loop()
{
  int k = 0;
  for(;;)
  {
    for(int i=0; i

Download the code below into the RX Arduino (receive) – This code will drive the nFR24L01 module to receive the data that transmit form the TX module and print it to serial port.

Note, clear RX_FIFO must bellow Read_FIFO

void setup()
{
  SPI_DIR = ( CE + SCK + CSN + MOSI);
  SPI_DIR &=~ ( IRQ + MISO);
  //  attachInterrupt(1, _ISR, LOW); // interrupt enable
  Serial.begin(9600);
  init_io();                        // Initialize IO port
  unsigned char status=SPI_Read(STATUS);
  Serial.print("status = ");
  Serial.println(status,HEX);      // read the mode’s status register, the default value should be ‘E’
  Serial.println("*****************RX_Mode start******************************R");
  RX_Mode();                        // set RX mode
}
void loop()
{
  for(;;)
  {
    unsigned char status = SPI_Read(STATUS);                // read register STATUS's value
    if(status&RX_DR)                                        // if receive data ready (TX_DS) interrupt
    {
      SPI_Read_Buf(RD_RX_PLOAD, rx_buf, TX_PLOAD_WIDTH);    // read playload to rx_buf
      SPI_RW_Reg(FLUSH_RX,0);                               // clear RX_FIFO
      for(int i=0; i

Now power on both Arduino , and connect the RX one to PC via USB. Open the IDE serial port monitor , change the baud rate to 9600 bps , and you can see the data that received.

If you want to change Arduino pin connecting to module , just modify the define on the NRF24L01.h .

All the project here(include API.h and NRF24L01.h)

Download nRF24L01_Demo_For_Arduino.

Download nRF24L01_Demo_For_Arduino_v1.1.

Download NRF24L01_module.

nRF24L01 with Arduinio’s SPI Library

文章来源于lcx.cc:nRF24L01 Module Demo for Arduino

相关推荐: 比特币吐槽:这货就是鸡毛!

故事大概是这样的:我养了一只鸡。 这可是一只天下独一无二的鸡!因为它的DNA序列和其他的鸡是不同的。 这只鸡它会长毛。一身鸡毛。所以它可以作为一种得天独厚的货币资源进行开发,一种有限的,独一无二的,不可复制的货币资源。 每根鸡毛都是一个单位的货币。每个人都可以…

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: