nRF24L01 is a work in the world-wide 2.4 ~ 2.5GHz ISM band single-chip wireless transceiver chip。Wireless transceiver comprising:Frequency generator、Enhanced SchockBurstTM Mode Controller、PA、Crystal Oscillator、Modulator、Demodulator。Set the output power and channel selection protocol can be set via the SPI interface。
Easy setup and low power consumption so that it is widely used in wireless mouse、Keyboard;Wireless Access、A variety of intelligent communications networking equipment, etc.。
Parameters
- Supply voltage:1.9 V~3.6V;
- Maximum transmit power:0 dBm;
- The maximum data transfer rate:2000 kbps;
- Transmit mode current consumption(0When dBm):11.3 but;
- Receive mode current consumption(2000kbps):12.3 but;
- Receive mode data transfer rate of 1000kbps under sensitivity:-85 dBm;
- Power-down mode current consumption:900 nA。
link
We borrow the forum is about wiring photos here:
- VCC <-> 3.3V
- GND <-> GND
- THIS <-> D9
- CSN <-> D10
- DAWDLE<-> D11
- MISO<-> D12
- SCK <-> D13
- IRQ <-> Do not take
experiment
Since nRF24L01 is full duplex communication module,Therefore, each module can do both the sender can do the receiving end。Here we goDownload Library Mirfspare。
The first is the initial configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
String code; void setup() { Serial.begin(9600); code = "A message from another B!!!";//准备要发送的字符串 Mirf.cePin = 9; //设置CE引脚为D9 Mirf.csnPin = 10; //设置CE引脚为D10 Mirf.spi = &MirfHardwareSpi; Mirf.init(); //初始化nRF24L01 Mirf.setTADDR((byte *)"A");//发送地址 A Mirf.setRADDR((byte *)"B");//接收地址 B Mirf.payload = 32;//窗口大小,最大32. 也就是一次收发的数组长度,两端需要一致 //发送通道,可以填0~128,收发必须一致。 Mirf.channel = 0; Mirf.config(); Serial.println("I'm Sender B..."); } |
Of course,This is the sender,Here is the receiving end of a similar,Just change the address to the corresponding:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
void setup() { Serial.begin(9600); Mirf.cePin = 9; //设置CE引脚为D9 Mirf.csnPin = 10; //设置CE引脚为D10 Mirf.spi = &MirfHardwareSpi; Mirf.init(); //初始化nRF24L01 Mirf.setRADDR((byte *)"A");//接收地址 A Mirf.setTADDR((byte *)"B");//发送地址 B Mirf.payload = 32;//窗口大小,最大32. 也就是一次收发的数组长度,两端需要一致 //发送通道,可以填0~128,收发必须一致。 Mirf.channel = 0; Mirf.config(); Serial.println("I'm Reciver A..."); } |
Mirfa.init()Once invoked,Front setting that is unchangeable,However, the name of the transmission and reception、Window size,Channel, etc. can all be changed in real time,Here we do not do code demonstrates,From now on,Let's write a simple echo - ie the sender to send our pre-written B string,A string immediately after receiving the content sent back to B。
Here, we first list what Mirf libraries commonly used method:
- Mirfa.isSending() It returns a boolean displays the current chip is sending information;
- Mirfa.send() Send a byte array,That string must be converted to send;
- Mirfa.getData() Get the information received from the chip,It is also a byte array;
- Mirfa.dataReady() To determine whether the chip has received information。
Since the transmission and reception of data you want to convert some complex data types directly rather than send strings,Here we package the two functions to perform this function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
String reciveDataString() {//从芯片里接收收到的信息 byte data[32];//缓存 String tmp; //字符串缓存 Mirf.getData(data); //接收数据到data数组 for (int i = 0; i < sizeof(data); ++i ) { //遍历data数组转换字符 tmp += char(data[i]); if(char(data[i]) == '\0')break;//拼接字符串直到完成 } return tmp; } void sendDataString(String str) {//发送数据,直接接受字符串形式参数 byte data[32]; //缓存 str.getBytes(data,32); //把字符串转换为byte数组,最大长度不超过32 //实际上这里应该手动实现超长字符串自动分片,但一般也用不到那么长吧…… Mirf.send(data);//调用类方法来发送数据 while(Mirf.isSending()) {}//判断是否发送完毕,如果还在发送就一直等待 } |
Such,This function will receive a good package,Now we come to realize the function,First, the sender:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void loop() { sendDataString(code); String tmp; if(Mirf.dataReady()) //等待接收数据准备好 { tmp = reciveDataString(); Serial.println(tmp); } delay(1000); } |
Then receiving (echo) end:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void loop() { String tmp; if(Mirf.dataReady()) //等待接收数据准备好 { tmp = reciveDataString(); Serial.println(tmp); Serial.println("start sending!"); sendDataString(tmp); Serial.println("sent!"); } delay(200); } |
Next is the code for these two different brush each in two different Arduino Development board,Energized simultaneously,You can see the result in the serial terminal!
characteristic
One thing we would like to mention here,The wireless module is supported nRF24L01Mixed Interconnectof,That is,It is one of those"Propaganda"mode,That multiple modules use the same receiver identifies no problem,If you do,They will each receive an identical message。As long as the window size is consistent with the same channel,Then the module will receive the corresponding address information without conflict。
It does not implement any function of the upper layer,In addition to the most basic bit transmission and reception outside,Any other advanced features you need to complete on their own (such as slicing、Retransmission and other similar TCP / IP functionality)。
Speaking transmission distance,Use module comes with a small antenna, then,Really not very far。
metaphysics
2017 year 11 moon 14 On the afternoon 2:13
The students are given a solution,But I have not tested conditions,I hope everyone has to help。 :)
Finally add,The execution order of code sends the address and the recipient address is not the same transceiver module,For example, this:
1 2 3 4 5 |
<del> Mirf.setRADDR((byte *)"A");//接收地址 A Mirf.setTADDR((byte *)"B");//发送地址 B ———————— Mirf.setRADDR((byte *)"B");//接收地址 B Mirf.setTADDR((byte *)"A");//发送地址 A</del> |
Then the final result is that the two modules can not communicate - you have to put them in order to change,Like this:
1 2 3 4 5 |
<del> Mirf.setRADDR((byte *)"A");//接收地址 A Mirf.setTADDR((byte *)"B");//发送地址 B ———————— Mirf.setTADDR((byte *)"A");//发送地址 A Mirf.setRADDR((byte *)"B");//接收地址 B</del> |
Original article written by LogStudio:R0uter's Blog » nRF24L01 wireless transceiver module Arduino
Reproduced Please keep the source and description link:https://www.logcg.com/archives/1823.html
Hello bloggers,I tried your code,About metaphysics section,In fact, the two issues that address the definition of a long name on the solution of the decision,And the receiving terminal may not necessarily be defined in the initialization address,As long as the receiving end address is defined before execution Functions,This can be done one to many communication
Thank you,But I do not have the equipment can not test,I added it to the body:)
What does this formula to compile programs written?
C++
Hello,Glad to see your blog,I am now a floating-point data transmission via arduino and nrf24l01,Will the floating-point data such as sending "21.23",I am using this floating-point data by sending after shaping into 100 21.23 or can be directly converted to a string sent?
Can,Theoretically float can also directly interchangeable with string,You can use C ++ try,If you can convert,You do not have to convert plastic。But one thing,If you really need to float a fixed format,The sub-string or handle it better。