Nano RF- Arduinoed again. Help declare this? RF Nano

I just got my RF Nanos, and there is only one example set.

Three programs total: transmit, receive one, receive more than one.
They all declare like this:
Nrf24l Mirf = Nrf24l(10, 9);

The library uses four parameters, so I added two pins.Same thing:
src\main.cpp:10:40: error: no matching function for call to ‘Nrf24l::Nrf24l(int, int, int, long int)’
Nrf24l Mirf = Nrf24l(10, 9, 13, 2000000);

This is another one that should work in Arduino IDE.

//Transmitter program

#include <SPI.h>
#include "Mirf.h"
#include "nRF24L01.h"
#include "MirfHardwareSpiDriver.h"
Nrf24l Mirf = Nrf24l(10, 9);
int value;

void setup()
{
  Serial.begin(9600);
  Mirf.spi = &MirfHardwareSpi;
  Mirf.init();
  //Set your own address (sender address) using 5 characters
  Mirf.setRADDR((byte *)"ABCDE");
  Mirf.payload = sizeof(value);
  Mirf.channel = 90;              //Set the channel used
  Mirf.config();
}

void loop()
{
  Mirf.setTADDR((byte *)"FGHIJ");           //Set the receiver address
  value = random(255);                      //0-255 random number
  Mirf.send((byte *)&value);                //Send instructions, send random number value
  Serial.print("Wait for sending.....");
  while (Mirf.isSending()) delay(1);        //Until you send successfully, exit the loop
  Serial.print("Send success:");
  Serial.println(value);
  delay(1000);
}

If you look inside Mirf.h, you will see this class definition:

class Nrf24l {
	public:
     Nrf24l(uint8_t cs_pin, uint8_t csn_pin);
    ...      
     }

The constructor takes two and only two parameters. Your code is calling the contructor with 4 parameters, so it barfs.

Nrf24l Mirf = Nrf24l(10, 9, 13, 2000000);

It would appear otherwise – it takes two.

Cheers,
Norm.

1 Like

It had two and it didn’t work, so I looked in a library and saw something with four arguments, different pins.

PIO is taking an issue with that declaration, which looks perfectly fine to me.
I want to fix it.

The compiler, not PIO, is taking issue. It was told – by the header file – to expect two parameters and thus will complain if you call it with fewer, none, or more than two.

The compiler doesn’t care what you want to do, it has rules to follow, and you too must follow the rules.

Two parameters only, you have no choice – unless you write your own library to take four.

Cheers,
Norm.

The two arguments fails.

I added the other two because the library had four arguments.

This is in the .h:
nRF24L01P(PinName mosi, PinName miso, PinName sck, PinName csn, long SPIFrequency = 2000000);

So which library is that? Where did you download it from? What is the name/link for it?

If you use the unmodified mirf library from GitHub - aaronds/arduino-nrf24l01: An Arduino port of the http://www.tinkerer.eu/AVRLib/nRF24L01 library., and looks at the samples there, i.e. ping_client you don’t put Nrf24l Mirf = Nrf24l(10, 9); in… you define the pins like so…

  Mirf.cePin = 7;
  Mirf.csnPin = 8;

just before

Mirf.init();

btw, if it is these ‘Nano RF’ boards, I don’t think that’s the right pin assignment anyway… I have some of them, and am pretty sure they worked with the RF24 getting examples without modification, meaning CE and CSN are 7 & 8.

https://www.aliexpress.com/item/4000467425667.html

That

nRF24L01P(PinName mosi, PinName miso, PinName sck, PinName csn, long SPIFrequency = 2000000);

… isn’t even setting the CE pin, what .h is it from?

btw, since you gave

Nrf24l Mirf = Nrf24l(10, 9, 13, 2000000);

and got a compile error of

src\main.cpp:10:40: error: no matching function for call to ‘Nrf24l::Nrf24l(int, int, int, long int)’

perhaps, you should look at what the fourth parameter is supposed to be, like the compiler is hinting? Should CSN really be 2000000? :wink: :crazy_face:

It is an RF Nano- the pins are here:

In the included library, 200000 is frequency. I copied 200000 from the library.

That’s ok… but wasn’t what I said to look at…

Assuming that this is valid:

nRF24L01P(PinName mosi, PinName miso, PinName sck, PinName csn, long SPIFrequency = 2000000);

Given

Nrf24l Mirf = Nrf24l(10, 9, 13, 2000000);

You have set

PinName mosi = 10
PinName miso = 9
PinName sck = 13
PinName csn = 2000000

So, just the compiler said: no matching function for call to ‘Nrf24l::Nrf24l(int, int, int, long int)’

If that’s the pin-out for the board you have, you should probably be using

Nrf24l Mirf = Nrf24l(11, 12, 13, 9); //MOSI, MISO, SCK, CSN, default SPIFrequency 

There is no need to specify the fifth parameter, SPIFrequency, if as if not specified the default value of 2000000 will be used (hence the long SPIFrequency = 2000000).

Also, note that there is a custom version of the library in the github code linked in the article… so you can’t use the example code with just any copy of MIRF, but the specific version bundled with it.

Aha, that’s a different library to the one I found. Apologies. However, I see your problem…

nRF24L01P(
    PinName mosi, 
    PinName miso, 
    PinName sck, 
    PinName csn, 
    long SPIFrequency = 2000000);

That’s 5 parameters, but the final one has a default. You need to supply 4 pin names and an optional frequency. You are passing 3 pins and a frequency.

Cheers,
Norm.

1 Like