Go Down

Topic: RF24 Library: Driver for nRF24L01(+) 2.4GHz Wireless Transceiver (Read 236293 times) previous topic - next topic

haydent

not sure.

But im also wondering if anyone has the equipment to test the actual power output of the PA+LA models ?

chucky4444

Hello Stanley,

I am trying to compile that sketch to upload it to an attiny but it has 8.570 bytes. I have the jscrane libraries (SPI, RF24 and RF24Network from his website https://github.com/jscrane?tab=repositories) and there is no way to make the sketch smaller. Even leaving just the code for the PIR is more than 8k. I am using Arduino 1.0.5 and a Mac (not sure if that makes any difference).

How did you manage to fit it? thanks
Aura Communications: Arduino projects and electronic shop

chucky4444

Nevermind, I finally made it. Just had to compile choosing the Attiny board, I thought that didn't make any difference.
Aura Communications: Arduino projects and electronic shop

chucky4444

By the way, I still didn't managed to make it work on the Attiny85. I am using a simple sketch where at the moment just sends a 1 or a 0 to the base. Since I disconnected the PIR, I just want to see that it sends properly. This is the code, I can't see what I am doing wrong. I have the SPI, RF24 and RF24Network libraries of Jscrane.  Most of the code is commented as I just want to make it work for now. I don't have any compilation errors. On the Arduino Uno it works fine.

Code: [Select]
//#include <dht11.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

//#include <TinyDebugSerial.h>
//TinyDebugSerial mySerial = TinyDebugSerial(); // PB0 on attiny84

//dht11 DHT11;
//
//#define DHT11PIN 9
//#define PIRPIN 4

uint8_t pirstate = 0;
uint8_t val = 0;

RF24 radio(PB3,PB4);
//RF24 radio(9,10);
// Network uses that radio
RF24Network network(radio);

RF24NetworkHeader * myheader;

// Address of our node
const uint16_t this_node = 2;

// Address of the other node
const uint16_t other_node = 0;

unsigned int counter = 0;

unsigned long temp_timeout;
unsigned long pir_timeout;

unsigned long temp_delay = 1000;
unsigned long pir_delay = 500;

// Structure of our temp payload
//struct payload_th
//{
//  uint16_t counter;
//  int8_t temp;
//  int8_t humidity;
//};
// Structure of our pir payload
struct payload_pir
{
  uint16_t counter;
  uint8_t pir_state;
};

bool PIR_state;

int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

void setup(void)
{
  uint8_t rf_ch;
 
//  mySerial.begin(9600);
//  mySerial.println("Start");
// 
//  mySerial.print("start ram ");
//  mySerial.println(freeRam());
 
//  pinMode(PIRPIN, INPUT);
 
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
/* 
  rf_ch = radio.getChannel();
  mySerial.print("RF_CH :0x");
  mySerial.println(rf_ch,HEX); 
*/

//temp_timeout = millis();
pir_timeout = millis();

}

void loop(void)
{
// Pump the network regularly
  network.update();

// This method used to avoid millis() rollover issues

//  if ((unsigned long) millis() - temp_timeout >= temp_delay) {
//    checkTemp();
//    temp_timeout = temp_timeout + temp_delay;
//  }
  if ((unsigned long) millis() - pir_timeout >= pir_delay) {
    checkPIR();
    pir_timeout = pir_timeout + pir_delay;
  }
}

void sendPIR()
{

  counter++;

  payload_pir payload = { counter, pirstate };

//  mySerial.print("Sending PIR...");

  RF24NetworkHeader header(/*to node*/ other_node,/*message type*/ 3);
       
  bool ok = network.write(header,&payload,sizeof(payload));
//  if (ok)
//     mySerial.println("ok.");
//  else
//     mySerial.println("failed.");
//
}

//void sendTemp()
//{
//
//  counter++;
//
//  payload_th payload = { counter, DHT11.temperature, DHT11.humidity };
//
//  mySerial.print("Sending Temp ...");
// 
//  RF24NetworkHeader header(/*to node*/ other_node,/*message type*/ '2');
//       
//  bool ok = network.write(header,&payload,sizeof(payload));
//  if (ok)
//     mySerial.println("ok.");
//  else
//     mySerial.println("failed.");
// 
//}

void checkPIR()
{

// val = digitalRead(PIRPIN);

  if (val == HIGH)
  {
//    if (pirstate == 0)
//    {
//      mySerial.println("Mot");
      pirstate = 1;
//      sendPIR();
    }else (pirstate=0);
      sendPIR();

//  } else {
//    if (pirstate == 1)
//    {
////      mySerial.println("Mot s");
//      pirstate = 0;
//      sendPIR();
//    }
//  }

}

//void checkTemp()
//{
//
//  int chk = DHT11.read(DHT11PIN);
//
//  /*
//  mySerial.print("ram ");
//  mySerial.println(freeRam());
// 
//  mySerial.print("Humidity (%): ");
//  mySerial.println(DHT11.humidity);
// */
// 
//  sendTemp();
//
//}
Aura Communications: Arduino projects and electronic shop

mcnobby

#244
Aug 11, 2014, 09:53 pm Last Edit: Aug 11, 2014, 09:57 pm by mcnobby Reason: 1
Hi All, here is a question :

I have a project where I set a receive channel the same as the transmit channel, and set the pipe addresses the same too, set all the doo's and the daah's, the datarate, payload size the same etc etc...

The transmitter is a 328 with a nrf24l01 using RF24
The receiver is a 85 with a nrf24l01 using a modified SPI85 and RF24

I know I am getting a carrier signal on that channel...       if ( radio.testCarrier() ) { thumbsUp; }
If I get a carrier should that also mean I would get the data if I have matched everything ?

The only thing I can think of is the 328-RF24 and the 85-RF24 deal with the pipe-address differently
Both TX and RX use 0xF0F0F0F0E1LL as the pipe address

Any ideas anyone, before I pull the last of my greying hair out ?? :)

Thanks in advance

EDIT : Incidentally, the ONLY library that I could get anything to work with on 85 is this https://github.com/WSUEECSEE5851213Team12/haf/tree/master/ATtiny/libraries
I also used a hardware mod/hack to free up pins http://nerdralph.blogspot.co.uk/2014/01/nrf24l01-control-with-3-attiny85-pins.html
I have modified both so that the 85 controls CE, and the CSN comes from the hack, this works for me and leaves me with one pin on the 85 (rather than use the reset/1) which is all I need
http://www.youtube.com/user/Recovered
http://www.smartshow.lighting

stan001

My journey into making a nRF24L01 adapter for UNO with lots of pictures...

http://arduino-for-beginners.blogspot.com/2014/08/arduino-uno-nrf-adapter.html




xavbabe

Hi, nooby question here:
Which way round does the capacitor go across gnd and 3v3?
Thanks!

NikWing

hey all!

I've googled a lot today but didn't find a solution yet
I'm testing a 2.2" tft from china and the nrf24l01+ connected to an arduino uno
both devices work without the other connected
but the moment I start the radio (radio.begin();) it's impossible to display anything on the tft

from what I can tell: it must be software-related and probably the rf24/nrf24 part, tried different ports for cs/csn/reset (non-SPI related ports)
disconnected devices, different power sources etc etc
as soon as the radio.begin is called, the tft won't accept anything
no matter if I use ucglib or adafruit's lib

anyone ever had that problem before and knows how to fix it?

in the meantime (tomorrow) I'll try a new rf24 lib I've found a min ago, updated in Nov 2014.

doctor_t

Hi guys,

i undrestand that on this post you know much more than me about how to use the tranciever nRF24 and I would ask your help with my problem

thank you for your time

i wrote everything on this post

RF24 + Polar heartrate

grahamed

Hi

I hope I am posting correctly here....

I am using the ManiacBug library many times between many Arduinos with no problem except ....if I try to use the "payload in ack method" it does not work unless I dis CE from 9 and take it to VCC, on the "sender"  then all works OK. If I do this with any board using the normal transmit/turnaround method it stops working (as I would expect).

Am I missing something?

Thanks.

gregsie

First let me say thanks to maniacbug for the GREAT library!

I've playing around with these modules for a few weeks and decided to base my sensor xmitters on the pingpair_sleepy example.  I wanted to reduce power consumption as much as possible.

I came across a problem in the pingpair_sleepy example provided with RF24.  The ping out would only work once.

    // Power down the radio.  Note that the radio will get powered back up
    // on the next write() call.
    radio.powerDown();

When the radio was powered down, it would never come back.  Commenting out radio.powerDown(); OR adding radio.powerUp() before the radio.write call in the example works.

Maybe there's a bug that assumes a write will always powerup first.

I hope this helps someone!

My sensor works well now and draws ~20ma idle (4secs) and ~35ma (1sec) when sending data.

Thanks.


I think you might be on to something with the radio.powerUp/Down call. I've battled with the examples in the library for a day or so with no success. I decided to try this post instead:
http://shanes.net/another-nrf24l01-sketch-string-sendreceive/
and it worked like a charm. The devices I have are all nrf24l01+ so this might have something to do with it. Now I use a 1mS delay and the powerUp() and powerDown() calls after each tx and the receiver never drops a packet.
Happy days :)
ta
GregW

plamba

Hi. I got the joystick example working the way it's described here (http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo). However, I'm having issues trying to integrate it with another project (2WD robot). When I come back to the joystick example, I notice that this example doesn't seem to work for me unless I wire the green (pin 13), gray (pin A2), blue (pin 11) and violet (pin 12) cables, even though they don't appear to play any role in this example. Any idea why? Are these pins reserved pins for the RF24 library? Do all of the wires in the example have to be connected even though my example isn't using them? In particular, what I am seeing is that when I integrate the NRF24L01+  to my existing circuit, it seems to be pulling pins 10 and 11 high, thereby causing the existing project (robot) to malfunction. Thanks for your help.

UPDATE #1
If I connect the nRF24L01+ exactly as described in the example (same pins on the Arduino), I no longer get issues with the existing project that I'm trying to add the wireless module to. Yet, the wireless transmission doesn't work. Worth noting: I was using Nanos to prototype the joystick example. And I noticed that the Nano's 3v3 pin provides 3.36v. The existing project that I'm trying to integrate with the nRF24L01+ is on an Arduino Uno, whose 3v3 pin provides 3.29v. I might try switching my existing project to Nano unless I can think of a reason not to.

UPDATE #2
I used a 10k trimpot to create a voltage divider off the 5v Arduino pin, so as to supply exactly 3.36v to the nRF24L01+, as the Nano was doing. But, that still did not get the wireless communication working. Again, please note that I've confirmed that the nRF24L01+ modules are both working - by connecting them to Nanos and using the simple joystick example.

UPDATE #3
I finally got this working. Didn't have to do anything special. I did use the library's "Getting Started" example against the Uno. I don't know if that example somehow reset something on the Uno, but after that the nRF24L01+ integrated well with my 2WD robot and sent signal reliably to my receiver nRF connected to a Nano.

Your ideas, comments, observations are most welcome and highly appreciated.

elaerico

Hi. I got the joystick example working the way it's described here (http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo). However, I'm having issues trying to integrate it with another project. When I come back to the joystick example, I notice that this example doesn't seem to work for me unless I wire the green (pin 13), gray (pin A2), blue (pin 11) and violet (pin 12) cables, even though they don't appear to play any role in this example. Any idea why? Are these pins reserved pins for the RF24 library? Do all of the wires in the example have to be connected even though my example isn't using them? In particular, what I am seeing is that when I integrate the NRF24L01+  to my existing circuit, it seems to be pulling pins 10 and 11 high, thereby causing the existing project (robot) to malfunction. Thanks for your help.

UPDATE #1
If I connect the nRF24L01+ exactly as described in the example (same pins on the Arduino), I no longer get issues with the existing project that I'm trying to add the wireless module to. Yet, the wireless transmission doesn't work. Worth noting: I was using Nanos to prototype the joystick example. And I noticed that the Nano's 3v3 pin provides 3.36v. The existing project that I'm trying to integrate with the nRF24L01+ is on an Arduino Uno, whose 3v3 pin provides 3.29v. I might try switching my existing project to Nano unless I can think of a reason not to.

UPDATE #2
I used a 10k trimpot to create a voltage divider off the 5v Arduino pin, so as to supply exactly 3.36v to the nRF24L01+, as the Nano was doing. But, that still did not get the wireless communication working. Again, please note that I've confirmed that the nRF24L01+ modules are both working - by connecting them to Nanos and using the simple joystick example.

Your ideas, comments, observations are most welcome and highly appreciated.

Hi plamba. As you can see in the example, the pin 10 and 11 are used for the SPI interface, the 10 for CSN and the 11 for MOSI. The pin 10 is configurable, you can use any free gpio pin of your arduino for CE and CSN, and is setted when you create an instance of RF24 object (RF24 radio(A0,A1); //CE,CSN)  in example.
Hope this works!

elaerico

Hi, I'm starting to use this modules for controlling a model helicopter.
I have a MEGA and a UNO. Put one module on each, and try the PINGPAIR example from the maniacbug library, and worked like a charm. Then I tried to work on my own code. One master(UNO), sending a number each cicle bigger, and in the slave(MEGA), receive the number, and if its odd, turn on a led, else, turn it off.
So I was trying it, but the communication gets incredible unreliable, and the led stops blinking for 2 seconds in random intervals, often each 2 or 3 seconds.
This is very rare becouse with the pingpair example works excellent, never miss a data, even when the delay sending the new data is far more fast than in my own code.
Can you give me a hand on this? I put the code, and thanks!!

Here is the master:

Code: [Select]

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10

RF24 radio(8,10);  //CE, CSN


const uint64_t pipe = 0xF0F0F0F0E1LL;

unsigned long led_state;


void setup() {
  Serial.begin(115200);
  
  radio.begin();
  //radio.setPayloadSize(8);
  radio.openWritingPipe(pipe);
  led_state = 0;
  

}

void loop() {
    
  
  radio.write(&led_state,sizeof(unsigned long));
  led_state++;
  delay(100);

  Serial.println(led_state);

}


And the Slave:

Code: [Select]

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"


RF24 radio(A0,A1);  //CE, CSN


// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipe = 0xF0F0F0F0E1LL;

unsigned long led_state;


void setup() {
    Serial.begin(115200);
    
    pinMode(2,OUTPUT);
    digitalWrite(2,HIGH);
    radio.begin();

    //radio.setPayloadSize(8);
    radio.openReadingPipe(1,pipe);

    
    radio.startListening();
    


}



void loop() {
    if (radio.available()){
        bool done = false;
        while(!done) {
      
        done = radio.read(&led_state,sizeof(unsigned long));
        
        Serial.println(led_state);
        
         }
    
    }
    if (led_state%2) digitalWrite(2,LOW);
    
    else digitalWrite(2,HIGH);
    
    
      
}



Again, thanks a lot!!

Juupke1981

Hi All,

I'm trying to read out my Philips TV remote with a  nRF24L01(+). I found out that the channel is 25 but I can't find the pipe adress. I used the Nordic Fob code to scan for the pipeaddress:

Code: [Select]
/*
 Copyright (C) 2012 J. Coliz <maniacbug@ymail.com>

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */

/**
 * Example Nordic FOB Receiver
 *
 * This is an example of how to use the RF24 class to receive signals from the
 * Sparkfun Nordic FOB.  Thanks to Kirk Mower for providing test hardware.
 *
 * See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/
 */

#include <SPI.h>
#include <RF24.h>
#include "nRF24L01.h"
#include "printf.h"

//
// Hardware configuration
//

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10

RF24 radio(9,10);


struct payload_t
{
  uint8_t b1;
  uint8_t b2;
  uint8_t b3;
  uint8_t b4;
};

//
// Setup
//

void setup(void)
{
  //
  // Print preamble
  //

  Serial.begin(57600);
  printf_begin();
  printf("\r\nRF24/examples/nordic_fob/\r\n");

  //
  // Setup and configure rf radio according to the built-in parameters
  // of the FOB.
  //

  radio.begin();
  radio.setAutoAck(false);
  radio.setChannel(25);
  radio.setPayloadSize(8);

  radio.setCRCLength(RF24_CRC_16);
 // radio.openReadingPipe(6,0xF0F0F0F0AALL);
 // radio.openReadingPipe(5,0xF0F0F0F0BBLL);
 // radio.openReadingPipe(4,0xF0F0F0F0CCLL);
 // radio.openReadingPipe(3,0xF0F0F0F0DDLL);
 // radio.openReadingPipe(2,0xF0F0F0F0EELL);
 // radio.openReadingPipe(1,0xF0F0F0F0FFLL);
radio.openReadingPipe(0,0xF0F0F0F011LL);

  //
  // Start listening
  //
  radio.startListening();

  //
  // Dump the configuration of the rf unit for debugging
  //

  Serial.println("DETAILS");
  radio.printDetails();
}

//
// Loop
//
unsigned long tmp = 0;
bool found = false;


void loop(void)
{
  //
  // Receive each packet, dump it out
  //
radio.stopListening();
radio.openReadingPipe(0,tmp);
radio.startListening();

if ( radio.testCarrier() ){
  Serial.print(tmp);
  Serial.print(" : ");
  Serial.println("Carrier!");
  if (found == false) tmp++;
 

 
    // if there is data ready
    if ( radio.available() )
    {
      Serial.println("Payload Available");
      found = true;
      // Get the packet from the radio
      payload_t payload;
      radio.read( &payload, sizeof(payload) );

      // Print the ID of this message.  Note that the message
      // is sent 'big-endian', so we have to flip it.
      //printf("#%05u Buttons ",flip_endian(payload.id));

      Serial.println("payload len:");
      Serial.println(sizeof(payload));

      //printf("\r\n");
    }
}
}



// vim:cin:ai:sts=2 sw=2 ft=cpp





It is modified to increment the pipe address until it finds an address with a package available. So far i have scanned until 100000 but this takes a lot of time.
Code: [Select]
100050 : Carrier!
100051 : Carrier!
100052 : Carrier!
100053 : Carrier!
100054 : Carrier!
100055 : Carrier!
100056 : Carrier!
100057 : Carrier!
100058 : Carrier!
100059 : Carrier!
100060 : Carrier!
100061 : Carrier!
100062 : Carrier!
100063 : Carrier!
100064 : Carrier!
100065 : Carrier!
100066 : Carrier!
100067 : Carrier!
100068 : Carrier!
100069 : Carrier!
100070 : Carrier!
100071 : Carrier!
100072 : Carrier!
100073 : Carrier!


Is there an easier way to find the right address or am I doing something wrong?

Thanks,

Peter

Go Up