ErriezNRF24L01Iface
1.0.0
これは、SPIインターフェイスを使用してNRF24L01(+)レジスタを読み書きするための最適化された低レベルのArduinoライブラリです。より高いレベルの読み取り、書き込み、構成の機能を含む派生クラスと組み合わせて使用する必要があります。
NRF24L01(+)を、以下を含むArduinoボードに接続します。
NRF24L01をArduinoボードの3.3Vに直接接続すると、再送信または通信の損失が発生する場合があります。これは、多くのArduinoボードがNRF24L01チップに十分な電力を供給できないためです。これは、個別の電圧レギュレータ、またはNRF24L01電源アダプターで解くことができます。
Nordic 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 | モシ | MO | 11 | 51 | D7 |
| 7 | 味噌 | mi | 12 | 50 | D6 |
| 5 | SCK | SCK | 13 | 52 | D5 |
NRF24L01(+)インターフェイス| RegisterAccess
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);