I couldn't find an example of someone using the Raspberry Pi as a receiving hub for sensor nodes that use the spirilis nRF24L01+ library and a MSP430G2553. I thought I would give it a shot since I think this would be beneficial to the community. I found a C library for the Raspberry Pi and nRF24L01+: https://github.com/stanleyseow/RF24. Class reference is here: http://maniacbug.github.io/RF24/classRF24.html
There is also a newer python library but I haven’t tried that one yet(https://github.com/jpbarraca/pynrf24).
I have yet to get it working and hope you guys could help me.
I am using this basic TX code using the spirilis msprf24 library on my MSP430G2553 Launchpad(https://github.com/spirilis/msprf24):
#include <msp430.h>
#include "msprf24.h"
#include "nrf_userconfig.h"
#include "stdint.h"
volatile unsigned int user;
void main(){
char addr[5];
char buf[32];
WDTCTL = WDTHOLD | WDTPW;
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
BCSCTL2 = DIVS_1; // SMCLK = DCOCLK/2
// SPI (USCI) uses SMCLK, prefer SMCLK < 10MHz (SPI speed limit for nRF24 = 10MHz)
// Red used for status
P1DIR |=BIT0;
P1OUT &= ~BIT0;
user = 0xFE;
/* Initial values for nRF24L01+ library config variables */
rf_crc = RF24_EN_CRC | RF24_CRCO; // CRC enabled, 16-bit
rf_addr_width = 5;
rf_speed_power = RF24_SPEED_1MBPS | RF24_POWER_MAX;
rf_channel = 120;
msprf24_init(); // All RX pipes closed by default
msprf24_set_pipe_packetsize(0, 32);
msprf24_open_pipe(0, 1); // Open pipe#0 with Enhanced ShockBurst enabled for receiving Auto-ACKs
msprf24_standby();
user = msprf24_current_state();
addr[0] = 0xDE; addr[1] = 0xAD; addr[2] = 0xBE; addr[3] = 0xEF; addr[4] = 0x00;
w_tx_addr(addr);
w_rx_addr(0, addr); // Pipe 0 receives auto-ack's, autoacks are sent back to the TX addr so the PTX node
// needs to listen to the TX addr on pipe#0 to receive them.
while(1){
__delay_cycles(800000);
buf[0] = '1';
w_tx_payload(32, buf);
msprf24_activate_tx();
LPM4;
if (rf_irq & RF24_IRQ_FLAGGED) {
rf_irq &= ~RF24_IRQ_FLAGGED;
msprf24_get_irq_reason();
if (rf_irq & RF24_IRQ_TX){
P1OUT |= BIT0; // Red LED on
}
if (rf_irq & RF24_IRQ_TXFAILED){
P1OUT &= ~BIT0; // Red LED off
}
msprf24_irq_clear(rf_irq);
user = msprf24_get_last_retransmits();
}
}
}
I found this Raspberry Pi receiving hub code example (http://blog.the-jedi.co.uk/2013/10/07/nrf24l01-and-raspberry-pi/):
#include <cstdlib>
#include <iostream>
#include "../RF24.h"
using namespace std;
// spi device, spi speed, ce gpio pin
RF24 radio("/dev/spidev0.0",8000000,25);
void setup(void)
{
// init radio for reading
radio.begin();
radio.enableDynamicPayloads();
radio.setAutoAck(1);
radio.setRetries(15,15);
radio.setDataRate(RF24_1MBPS);
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(120);
radio.setCRCLength(RF24_CRC_16);
radio.openReadingPipe(0,0xDEADBEEF00LL);
radio.startListening();
}
void loop(void)
{
// 32 byte character array is max payload
char receivePayload[32];
while (radio.available())
{
// read from radio until payload size is reached
uint8_t len = radio.getDynamicPayloadSize();
radio.read(receivePayload, len);
// display payload
cout << receivePayload << endl;
}
}
int main(int argc, char** argv)
{
setup();
while(1)
loop();
return 0;
}
Which I compiled on the Raspberry Pi using:
g++ -Wall -Ofast -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -L../librf24/ -lrf24 pi_rf24ping_rx.cpp -o pi_rf24ping_rx
and ran on the Raspberry Pi using:
sudo /home/pi/gitwork/RF24/librf24-rpi/librf24/examples/pi_rf24ping_rx
I am sure that I am missing something obvious. I assume with the addressing and the pipes. I have been reading through the datasheet trying to get a better understanding of how the nRF24L01+ works but still haven't been able to get them talking. Any ideas?