ErriezNRF24L01Iface
1.0.0
這是一個優化的低級Arduino庫,可使用SPI接口讀取和編寫NRF24L01(+)寄存器。它應與包含更高級別讀取,寫入和配置功能的派生類結合使用。
將NRF24L01(+)連接到任何包含的Arduino板:
將NRF24L01直接連接到Arduino董事會的3.3V時,可能會發生重傳或通信損失,因為許多Arduino董事會無法為NRF24L01芯片提供足夠的功率。可以使用單獨的電壓調節器或NRF24L01功率適配器來解決。
北歐NRF24L01或NRF24L01(+)2.4GHz無線收發器連接到帶有單獨的3.3V電壓調節器和100UF ELCO的Arduino Uno板:
為了提高通信可靠性,請使用單獨的3.3V電壓調節器使用NRF24L01電源適配器,例如:
| NRF24L01+ 別針 | NRF24L01+ 功能 | NRF24L01+ 適配器 | Arduino uno/mini | MEGA2560 | ESP8266 nodemcu |
|---|---|---|---|---|---|
| +3.3V | 直接3.3V | - | 3.3V | 3.3V | 3.3V |
| - | +5V通過適配器 | +5V | +5V | +5V | - |
| 1 | gnd | gnd | gnd | gnd | gnd |
| 3 | CE | CE | 7 | 7 | D0 |
| 4 | CSN | CSN | 8 | 8 | D8 |
| 6 | 莫西 | 莫 | 11 | 51 | D7 |
| 7 | 味o | mi | 12 | 50 | D6 |
| 5 | SCK | SCK | 13 | 52 | D5 |
NRF24L01(+)接口|寄存器
CE引腳應在派生類內部控制。
使用以下庫:
# include < nRF24L01Iface.h > class nRF24L01Example : nRF24L01Iface
{
public:
// Constructor, initialize base class with SPI clock and SPI chip-select
nRF24L01Example ( uint32_t spiClock, uint8_t cePin, uint8_t csnPin) :
nRF24L01Iface (spiClock, csnPin),
_cePin (cePin)
{
};
// Read status register
uint8_t readStatus () {
// Read status register
return readRegister (REG_STATUS);
}
// Read from config register
uint8_t readConfig () {
// Read config register
return readRegister (REG_CONFIG);
}
// Write to config register
void writeConfig ( uint8_t val) {
// Write to config register
writeRegister (REG_CONFIG, val);
}
// Write to TX pipe (0) registers
void openWritePipe0 ( const uint8_t *address) {
// Write 5 Bytes transmit pipe
// Now pipe 0 cannot be used for receive
writeRegister (REG_TX_ADDR, address, 5 );
}
// More functions such as read and write
// ...
private:
uint8_t _cePin;
}; // CE pin to enable RX and TX modes
# define CE_PIN 7
// SPI chip select pin
# define CSN_PIN 8
// Create object and initialize with SPI clock, CE pin and SPI chip-select pin
static nRF24L01Example radio (( uint32_t )10000000UL, CE_PIN, CSN_PIN); // Read status register
uint8_t status = radio.readStatus();
// Read from config register
uint8_t config = radio.readConfig();
// Write to config register
radio.writeConfig( 0x08 );
// Define an address pipe for transmit
const uint8_t pipeAddress[ 5 ] = { 0x55 , 0xa5 , 0x5a , 0xaa , 0x99 };
// Configure write pipe0
radio.openWritePipe0(pipeAddress);