Hi community,
I'm trying to make a wireless communication link between my raspberry pi and MSP430G2553 launchpad using nRF24L01 modules.
I'm using RF24 library for raspberry pi and Enrf24 library for launchpad.
First thing I tried was to configure one of mu launchpad+nRF module as transmitter and other pair as a reciever( as in the sample comes with Enrf24 library ) and it works fine.
Now I want my raspberry pi to be the receiver. But Pi is not at all receiving the message.
These are the source files I'm using :
// For launchpad : MSP430G2553 as transmitter
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>
// For MSP430G2553
Enrf24 radio(P2_0, P2_1, P2_2); // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void setup() {
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
radio.begin(); // Defaults 1Mbps, channel 0, max TX power
radio.setTXaddress((void*)txaddr);
// set push button
// pinMode( P1_3, INPUT );
// set leds
pinMode( P1_0, OUTPUT );
// do some startup animation
for( int i = 0; i < 5; i++ ) {
digitalWrite( P1_0, HIGH );
delay( 250 );
digitalWrite( P1_0, LOW );
delay( 250 );
}
digitalWrite(P1_0, LOW);
}
void loop() {
digitalWrite( P1_0, LOW );
radio.print(str_on);
radio.flush(); // Force transmit (don't wait for any more data)
delay(250);
digitalWrite( P1_0, HIGH );
radio.print(str_off);
radio.flush(); //
delay(250);
}
// For raspberry pi, as receiver
#include <cstdlib>
#include <iostream>
#include <RF24/RF24.h>
using namespace std;
// Radio pipe addresses for the 2 nodes to communicate.
// First pipe is for writing, 2nd, 3rd, 4th, 5th & 6th is for reading...
const uint64_t pipes[6] =
{
0xDEADBEEF01LL,
0xDEADBEEF01LL,
0xDEADBEEF01LL,
0xDEADBEEF01LL,
0xDEADBEEF01LL,
0xDEADBEEF01LL
// 0x01EFBEADDELL,
// 0x01EFBEADDELL,
// 0x01EFBEADDELL,
// 0x01EFBEADDELL,
// 0x01EFBEADDELL,
// 0x01EFBEADDELL
};
// CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ);
int main(int argc, char** argv)
{
uint8_t len;
// Refer to RF24.h or nRF24L01 DS for settings
radio.begin();
radio.enableDynamicPayloads();
radio.setAutoAck(1);
radio.setRetries(15,15);
radio.setDataRate(RF24_1MBPS);
// radio.setPALevel(RF24_PA_MAX);
radio.setChannel(0);
radio.setCRCLength(RF24_CRC_16);
radio.openReadingPipe(0,pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.openReadingPipe(2,pipes[2]);
radio.openReadingPipe(3,pipes[3]);
radio.openReadingPipe(4,pipes[4]);
radio.openReadingPipe(5,pipes[5]);
// Start listening
radio.startListening();
// Dump the configuration of the rf unit for debugging
radio.printDetails();
printf("Output below : \n");
delay(1);
while(1)
{
char receivePayload[32];
uint8_t pipe = 1;
// Start listening
radio.startListening();
while ( radio.available(&pipe) )
{
len = radio.getDynamicPayloadSize();
radio.read( receivePayload, len );
// Display it on screen
printf("Recv: size=%i payload=%s pipe=%i\n",len,receivePayload,pipe);
pipe++;
// reset pipe to 0
if ( pipe > 6 )
pipe = 0;
}
delayMicroseconds(20);
}
return 0;
}
Can anybody please tell me what I'm doing wrong ??
I also tried to scan the spectrum using raspberry Pi in order to ensure that my connections are correct. I used this code :
// To report channel activity , running on raspberry pi
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <RF24/RF24.h>
using namespace std;
// CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate.
//const uint8_t pipes[][6] = {"1Node","2Node"};
// const uint8_t rxAddress[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const uint8_t rxAddress[] = { 0x01, 0xEF, 0xBE, 0xAD, 0xDE };
//const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
int main(int argc, char** argv){
printf("RF24 Test Program\n");
// Setup and configure rf radio
radio.begin();
// set channels to 0
radio.setChannel( 79 );
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
// Dump the configuration of the rf unit for debugging
radio.printDetails();
// start listening
printf( "Opening Address : " );
radio.openReadingPipe(1, rxAddress);
printf( " [COMPLETED]\n " );
printf( "Listening...\n" );
radio.startListening();
// Dump the configuration of the rf unit for debugging
radio.printDetails();
int16_t i, j;
uint8_t strength, chan=0, dumpbuf[33];
printf("nRF24L01+ Channel Activity Scan\n");
printf("-------------------------------\n");
// Sample channels 0 through 125.
for (chan=0; chan < 126; chan++) {
// Force RX off, change channel & force back on.
radio.startListening();
delay( 10 );
radio.stopListening();
delay( 10 );
radio.setChannel(chan);
radio.startListening();
delay(1); // Strawman delay to make sure the RF engine is fully spun-up on the new channel
/* Sample the RPD register (Receive Power Detect, >= -64dBm signal detected)
* 256 times, once every 4 milliseconds, incrementing the 'strength' variable each
* time it's detected. This will be used to produce a relative estimate of how
* strong the ambient noise/crosstalk is on this channel.
*/
strength = 0;
for (i=0; i<100; i++) {
if (radio.testRPD())
strength++;
delay(4);
}
/* Discover the highest bit set in our 'strength' variable; that will
* be the size of the bargraph we'll show for this channel.
*/
j = 0;
for (i=7; i >= 0; i--) {
if (strength & (1 << i)) {
j = i+1;
break;
}
}
/* Each channel represents a 1MHz bandwidth starting at 2400MHz, e.g.
* channel 125 is 2525MHz, channel 64 is 2464MHz.
*/
printf("\nChannel %d", chan);
printf(" ("); printf("%d", 2400+chan); printf("MHz): ");
for (i=0; i < j; i++) {
printf("*");
}
printf(" %d - %d", j, strength );
if (radio.available()) { /* Just in case some data got inadvertently received while
* we were doing our scan, clear it out.
*/
radio.read(dumpbuf, 33);
}
} // Loop to the next channel...
printf("\nChannel scan done; halting CPU. Hit RESET to do another scan.\n");
// Serial.flush();
// radio.deepsleep();
// while(1) ; // Permanently halt the CPU. Using while(1) is more portable e.g. to Stellaris LP.
return 0;
}
And I got this output :
Channel 0 (2400MHz): ******* 7 - 80 Channel 1 (2401MHz): 0 - 0 Channel 2 (2402MHz): 0 - 0 Channel 3 (2403MHz): 0 - 0 ...... Channel 54 (2454MHz): 0 - 0 Channel 55 (2455MHz): 0 - 0 Channel 56 (2456MHz): *** 3 - 4 Channel 57 (2457MHz): 0 - 0 Channel 58 (2458MHz): ** 2 - 3 Channel 59 (2459MHz): * 1 - 1 Channel 60 (2460MHz): ** 2 - 2 Channel 63 (2463MHz): *** 3 - 4 Channel 64 (2464MHz): *** 3 - 6 Channel 65 (2465MHz): *** 3 - 4 Channel 66 (2466MHz): *** 3 - 6 Channel 67 (2467MHz): ***** 5 - 16 Channel 68 (2468MHz): 0 - 0 Channel 69 (2469MHz): 0 - 0
( sorry for messing up the output, I don't know what is happening )
So now I'm sure that my transmitter is at channel0 and the activity around channel 60 may be due to my router.