RF24
RF24 copied to clipboard
nrf24 between BananaPi and Arduino
Hi, I install fork of RF24 for BananaPi. It looks like all is fine (configuration at least). I run this code on BananaPi:
#!/usr/bin/python
from nrf24 import NRF24
import time
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24()
radio.begin(0, 0, 23, 24) # board GPIO.4 == GPIO 23 on 'gpio readall' as CE, board GPIO.5 == GPIO 24 on 'gpio readall' as IRQ
radio.setRetries(15,15)
radio.setPayloadSize(8)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_250KBPS)
radio.setPALevel(NRF24.PA_MAX)
radio.setAutoAck(1)
radio.openWritingPipe(pipes[0])
radio.openReadingPipe(1, pipes[1])
radio.startListening()
radio.stopListening()
radio.printDetails()
radio.startListening()
while True:
pipe = [0]
while not radio.available(pipe, True):
time.sleep(1000/1000000.0)
recv_buffer = []
radio.read(recv_buffer)
print recv_buffer
And on Arduino I have
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xE7E7E7E7E7, 0xC2C2C2C2C2 };
void setup(void)
{
Serial.begin(57600);
printf_begin();
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.setChannel(0x60);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1, pipes[0]);
radio.startListening();
radio.stopListening();
radio.printDetails();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1, pipes[0]);
}
void loop(void)
{
const char message[] = "PING";
radio.write(&message, sizeof(message));
delay(1000);
}
Communication dont work properly. This is what Arduino print:
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xc2c2c2c2c2 0xe7e7e7e7e7
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xc2c2c2c2c2
RX_PW_P0-6 = 0x08 0x08 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x60
RF_SETUP = 0x27
CONFIG = 0x0f
DYNPD/FEATURE = 0x00 0x00
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_HIGH
And what I see on BananaPi:
BAPI: revision(1)
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xe7e7e7e7e7 0xc2c2c2c2c2
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xe7e7e7e7e7
RX_PW_P0-6 = 0x08 0x08 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x60
RF_SETUP = 0x26
SETUP_AW = 0x03
OBSERVE_TX = 0x00
CONFIG = 0x0e
FIFO_STATUS = 0x11
DYNPD = 0x00
FEATURE = 0x00
Data Rate = 250KBPS
Model = nRF24l01+
CRC Length = 16 bits
PA Power = PA_MAX
[80, 73, 78, 71, 0, 0, 0, 0]
Last line ([80, 73, 78, 71, 0, 0, 0, 0]) is repeated after each reset of Arduino - this is text which I want to send - INT to ASCII gives "PING", but only once after reset. Any ideas?
EDIT Somehow adding
radio.startListening()
before
radio.write(&message, sizeof(message));
fix problem. But why it happens?