Does the RF24 library (from TMRh20) work on STM32F103?

anistor
Sat Jun 13, 2015 2:26 pm
Hi,

Did anyone try using this library https://github.com/TMRh20/RF24 (or its older version https://github.com/maniacbug/RF24) for nRF24L01 devices on the STM32F103?

It seems to compile without errors for this board but I do not have the device yet to actually test it. Also, by looking at the code I could not figure out if this library can work with the secondary SPI.

Thanks!
Adrian


ahull
Sat Jun 13, 2015 7:46 pm
Good question, I have a couple of those devices somewhere, I might get a chance to check later in the week. If anybody else feels like beating me to it, feel free to do so.

mrbwa1
Wed Jun 17, 2015 4:40 pm
It’s on my list to look at as well. I’m actually more used to the RF24Mesh from TMRh20. It’s really similar to the mysensors Arduino library. I would love to eventually get that one working, but it will probably take a while.

RF24Mesh and MySensors are nice because they take care of a lot of the setup stuff so you can just add and extend (MySensors is specific to adding sensors to various Home Automation solutions)


RogerClark
Mon Jul 06, 2015 9:46 pm
Do you mean, RF24L01 boards ?

If so, i have a few of these as well, but i never had much success with them, even on AVR.
The range seemed to be quite low, and would not go though many internal plasterboard walls.


pav2000
Tue Sep 29, 2015 2:06 pm
I worked with this library (TMRh20s links: http://tmrh20.blogspot.ru/ and https://github.com/TMRh20). Using maple mini. At the same time, I made a small change in the code:

1. Fixes module RF24.cpp for maple mini was in the function void RF24 :: csn (bool mode)
#if! defined (SOFTSPI)
_SPI.setBitOrder (MSBFIRST);
_SPI.setDataMode (SPI_MODE0);
_SPI.setClockDivider (SPI_CLOCK_DIV2); // Lower frequency !!!!!
#endif


stevech
Wed Sep 30, 2015 12:13 am
Much better to use sub-GHz radios, narrowband, than 2.4GHz. Laws of physics plus the Nordic NRf based boards are, well, too cheap (low power, etc.)

Here’s some links that might be new to you.

Radios – in the US, this is the main distributor – they do accommodate low quantity orders as a rule. HopeRF is a decent Asian board maker; they use radio chips from two US manufacturers.
http://anarduino.com/

This open source Arduino-compatible protocol stack is in C++. I and others have made a few simple changes to run it on STM32’s.
At the bottom of this protocol stack are drivers for most of HopeRF’s boards, and radio boards from other vendors too.
http://www.airspayce.com/mikem/arduino/RadioHead/

The RFM69HW module placed on an MCU board (H for high power) – I’ve used lots of these. No. America, use 902-928MHz band; in the EU and some other places, 868MHz. The 433MHz band exists in the US and elsewhere but the regulatory limits on transmitter duty cycle are severe.

As in any data radio, the range is governed by:

  • Channel width (narrow = better range)
  • Modulation rate (lower = better range, i.e., don’t try 50-100Kbps and expect longest range)
  • FM Modulation index (for these mostly FM/GFSK radios)
  • Transmitter power
  • Antenna gain(s) from choice of antennas – omni-directional or directional depending on topology of the network.
  • Terrain and other non-line-of-sight impairments.

For a line of sight path, we can easily calculate the achievable range (as a link budget). I have a spreadsheet I use do to that,.
For non-line of sight, experience tells one what to expect. As well as trials.

A pair of RFM69HWs (100mW) with say 30Kbps or so, conservative modulation index, dangling-wire antennas, elevated to about 6 ft., line of sight, will give a reasonable error rate at 100m. In any link design, you want 10+ dB of fade margin (excess received signal strength).

Radiohead’s stack includes an option for “reliable datagram” mode.. meaning there are CRC checks and retransmissions for error correction.
Other protocols include unreliable datagrams (like UDP), fixed routed network, and mesh-routed network.


zoomx
Wed Sep 30, 2015 1:05 pm
RF24L01 cheap modules can be powered from the 3.3V Arduino line, but I read that it is better to add a cap for better performance.

There are models with more transmit power and external antenna, you need separate power like an ESP8266. They claim to have a long range, but not long as an xbee. If you use directive antennas you can reach a very long range.

I have RF24L01 cheap modules and subGHz radio modules but never tested them for long distance.


mrburnette
Wed Sep 30, 2015 1:23 pm
zoomx wrote:
<…>
I have RF24L01 cheap modules and subGHz radio modules but never tested them for long distance.

mrbwa1
Wed Sep 30, 2015 4:37 pm
Ray,

thanks for the painful flashback…

when we remodeled last year, we found the bathroom was Drywall over plaster over metal lathe over more plaster (almost 1″ thick). It took a sawzall with a Diablo blade to get most of it out and many of the corners I had to attack with an angle grander because they used extra metal lathe as reinforcement.

As for the RF-24 library, I’m still working on getting my STM32s sorted and need to look at the library. I’m sure it’ll work with a few changes as others have gotten the NRF24’s working. I really want the mesh mode going because it’s the easiest for my to work with.

I haven’t really had distance issues within the house with the on-PCB antennal. There is a p version wit PA+LNA and an external antenna (http://www.elecfreaks.com/wiki/index.ph … PA_and_LNA). They are rated at 1000m @ 250 kbps in open air with a 2db antenna.


primateio
Fri Nov 13, 2015 2:49 pm
I ported over the RF24 library from https://github.com/maniacbug/RF24 and got it working for the most part. I had to make some crude hacks in it for the print functions because I couldn’t get them to actually work otherwise. I have it talking to an ATmega328p using the same library. I initially tried the TMRh20 library, but couldn’t get it working with my old code, it has some breaking changes from the maniacbug one.

The ping pair sketches work great. The only thing that is weird is, on the AVR chips, you can leave the sender on and it works fine. On my port, you have to call stopListening() before sending a packet and call startListening() after sending, even if you are not listening for anything. This may not always be required, but in my program, I am receiving an acknowledgement packet with data, and that is all I have tested other than the examples which do this anyway. I think it is something with the SPI ending a transaction or something, but I have not looked into it much. Otherwise, it hang up. It does not do this behavior on AVR.

I can post my modified version on github if you want. I am not planning on fixing the bug soon because I decided to go with a different sub ghz radio from hope RF because I need greater distance and more wall penetration for my project.


mrburnette
Fri Nov 13, 2015 4:10 pm
For what it is worth…

I have a friend that swears by: http://lowpowerlab.com/moteino/

I guess it really depends on what one intends to do at 2.4G… the ESP8266 is being utilized in my house (master GPS datagram transmitter is in the attic and the UDP receivers work anywhere in the house and basement and around the perimeter of the 1/3 acre lot. But, I really have not tried TCP to see what a more reliable form of communication would provide in the same space.
http://www.hackster.io/rayburne/tardis- … server-gps

Ray


primateio
Fri Nov 13, 2015 4:23 pm
mrburnette wrote:the ESP8266 is being utilized in my house (master GPS datagram transmitter is in the attic and the UDP receivers work anywhere in the house and basement and around the perimeter of the 1/3 acre lot.

mrburnette
Fri Nov 13, 2015 4:34 pm
primateio wrote:
<…>
Which module are you using? Just the standard trace antenna?

Just to be clear, you are not going through your router, just ESP8266 to ESP8266 correct?


martinayotte
Fri Nov 13, 2015 6:07 pm
mrburnette wrote:
Forum member Martin Ayotte (martinayotte on ESP8266.com) has some published peer-peer code. My UDP example which was linked earlier can also be TCP just by changing the protocol invocation.
http://www.esp8266.com/viewtopic.php?f=27&t=4080#p23577 (must be logged-in to download)

RogerClark
Fri Nov 13, 2015 7:49 pm
In my experience the range on 24L01 is much less than wifi, so I would definitely give wifi a try.

You may want to run a wifi scanner and find a channel that is not being used by other routers in the vacinity, as this can cause interferance and loss of range (but it doesnt seem to make much difference)

If you need longer range, you would have to use lower frequencies e.g. 433MHz or 915MHz etc, but using devices for those bands, e.g. nRf905 and RFM69 is much lower data rate etc etc


mrburnette
Fri Nov 13, 2015 10:10 pm
martinayotte wrote:
<…>
Those examples are now pretty old, but they still a good way to start … ;)

zmemw16
Sat Nov 14, 2015 12:24 am
stagnates surely :D

martinayotte
Sat Nov 14, 2015 2:15 pm
mrburnette wrote:Good working code ages like a fine wine…

zmemw16
Sat Nov 14, 2015 3:40 pm
with very slight secondary fermentation/sparkling on casking :D

sslobodyan
Tue Jan 26, 2016 5:57 pm
primateio wrote:I can post my modified version on github if you want

mrburnette
Tue Jan 26, 2016 6:24 pm
Maybe this is worth a view, I have not downloaded as yet.
https://github.com/LostGuard/RF24plus

Ray


zmemw16
Tue Jan 26, 2016 7:25 pm
it’s in SPL, good for a browse though

tiger762
Wed Jan 27, 2016 12:31 am
What would be great is if it were added to the Arduino_STM32 project

RogerClark
Wed Jan 27, 2016 5:03 am
Did you see this ?

https://maniacbug.wordpress.com/2011/12 … n-maple-3/


zmemw16
Wed Jan 27, 2016 4:10 pm
interesting, what’s nice is the details of the changes he made.
srp

primateio
Wed Jan 27, 2016 4:13 pm
RogerClark wrote:Did you see this ?

https://maniacbug.wordpress.com/2011/12 … n-maple-3/


primateio
Wed Jan 27, 2016 4:34 pm
Here is my modified version of the Maniacbug RF24 library that I got working with the STM32f103 on the STM32duino platform. I got it working, but the range wasn’t there for the project I needed it on, so I didn’t debug very much. Feel free to submit changes if you find any bugs. I am starting a new project that I will be using the nrf25l01, so I will probably be committing more changes in the weeks to come. But, it worked for me at the time I wrote it. If I remember right, the printf function in the examples and the library didn’t work, so I changed all the serial prints to just Serial.print and Serial.println in the library itself. You will probably have to do this in the examples as well.

https://github.com/jaretburkett/RF24-STM


mrburnette
Wed Jan 27, 2016 5:11 pm
@primateio

Last I remember, printf is not implemented but sprintf is implemented.

Ray


RogerClark
Wed Jan 27, 2016 7:14 pm
mrburnette wrote:@primateio

Last I remember, printf is not implemented but sprintf is implemented.

Ray


martinayotte
Wed Jan 27, 2016 10:24 pm
@Roger, maybe you didn’t remember, but you had started the job awhile ago, not in our github, but probably even before on leaflab github. ;)
https://github.com/rogerclarkmelbourne/ … .h#L66-L69

zmemw16
Wed Jan 27, 2016 10:34 pm
its either gotcha or any progress?

smiley supplied is just not big enough

stephen


RogerClark
Wed Jan 27, 2016 10:43 pm
Hi Martin

Unfortunately, I can’t even remember starting it ;-)

Well, actually a vague recall looking at this.

I think I had some issue redirecting the output of printf putc into the USB Serial.

It was probably a case of running out of time and having more pressing things I needed to do

If I get time (A big if), I will take a look at what the ESP8266 does and possibly be able to learn from that (albeit they are sending chars to the hardware via the SDK, not to the virtual serial buffer, but surely it must be very similar !)


martinayotte
Wed Jan 27, 2016 11:35 pm
Hi Roger,
I’ve actually looked at ESP version of printf, and then look at STM32 to get the actual discovery of the job was started.
It is a bit similar, but as you said, we need to figure out possible impact, and if none, then enabling that code by default.

On ESP, here how it looks (see that it is limited by MTU size 1460) :

size_t Print::printf(const char *format, ...) {
va_list arg;
va_start(arg, format);
char temp[1460];
size_t len = ets_vsnprintf(temp, 1460, format, arg);
len = print(temp);
va_end(arg);
return len;
}


RogerClark
Thu Jan 28, 2016 1:58 am
Hi Martin

Umm.

OK. That looks like a bit of a bodge.

I will need to see what

ets_vsnprintf() does

I’m sure I’ve read something about somehow redirecting the PutC output from vaprintf etc, so that it goes to whichever function you want

But I think that’s as far as I got.

Edit.

It looks like we’d need to define put_ch()

e.g. I think this link has some information

http://www.electro-tech-online.com/thre … ne.135005/


madias
Thu Mar 10, 2016 8:55 pm
Ok, I stumbled also across the TMh20 RF24 library (it’s the most recent NRF24 library and very convenient in contrast to other ones).
I think a possibility is to look again to the genius Paul Stoffregen and his teensy project and how he solved the “printf” “feature”:
https://github.com/PaulStoffregen/cores … /Print.cpp

Maybe I have some time to play with that…

>EDIT< Ok, it seems, like Roger did already take the teensy part for printf. Ok, didn’t got the library working (totally no response, but compiling is ok, how I hate that…). So at first, I’m going to check out the other nrf24 library (enrf or something from energia) to be sure, that the module is working well.


RogerClark
Thu Mar 10, 2016 9:04 pm
Thanks Matthias

It looks like Paul is calling vdprintf, which he is passing a pointer to the Print class, so that vdprintf would treat the Print class as some sort of File stream (But i may be wrong about how it works)

I presume vdfpintf calls the write function (again I’m not sure)

But it would definitely be worth investigating


madias
Thu Mar 10, 2016 9:25 pm
Roger, I edited my comment… looking further getting the device running.

Little offtopic:
A really MUST have little helper for the nrf24 modules (only 60 Cent (Euros)):
http://www.aliexpress.com/item/New-Sock … 27557.html
With this little guys (ok, ok can solder it easily by yourself, but for 60 cents…) all my problems with the modules are history (remember, that I’m working on many different MCU devices, so I cannot remember all max mA for 3.3V, I’m lazy and I’m a fan of voltage converters for every different module)).


RogerClark
Thu Mar 10, 2016 9:58 pm
Hi Matthias

I remember looking at it, over a year ago, but I can’t remember why it wasn’t working

I think possibly its something to do with some functions like putc() , or possibly its called putch() not being implemented
Or if they are implemented they don’t do whats required.

I don’t think I could work out how to setup the linkage to these character writing functions.

I’m sure its documented somewhere on the web e.g.

http://stackoverflow.com/questions/1827 … internally


madias
Thu Mar 10, 2016 11:06 pm
Ok, small status update: didn’t got the NRF24`s running even with enrf24 correctly (breaks, crashes…). Tried many things like external power. I think enrf24 isn’t really stable (got the blue fading led sometimes). So my question is: Has someone out here got the NRF24’s running stable? And if “yes” with which library? (Until I know that the devices won’t work probably, I see no sense digging into the TMRh20 library. cause I need a stable hardware setup at least)
small edit: The enrf24 scanner demo looks like working fine, but the rx/tx demo doesn’t. Won’t get any connection between two minis. (I think the RX demo code is the problem, hangs up)

jbforrer
Fri Mar 11, 2016 5:42 pm
@madias — I had good luck with the TMRh20 library (with few changes) using a Blue Pill module.
Attached a working example as used with my home sensor network.
Hope it helps.

Regards.
-JBF.


madias
Fri Mar 11, 2016 10:25 pm
Thank you very much I ll going to try it out on Monday!

madias
Sun Mar 13, 2016 2:13 pm
jbforrer wrote:@madias — I had good luck with the TMRh20 library (with few changes) using a Blue Pill module.
Attached a working example as used with my home sensor network.
Hope it helps.

Regards.
-JBF.


RogerClark
Sun Mar 13, 2016 9:42 pm
Thanks Matthias

Perhaps I should add it to the repo


madias
Mon Mar 14, 2016 10:52 am
Dear Roger,
I don’t think this library is ready for the main repo, I think in the main repo should be only libs they are 100% tested and proofed.
But (!):
Maybe it would be a good idea to make an folder on github for those “not 100% libs? So we can refer every time to this github link and we can collect all this “unfinished” but very useful libs out there in the forum and/or on different github accounts. Otherwise we would loose many potential codes over the time….
Maybe a good github name would be “User libraries [not verified]” or something. So the user can do a “pull request” and you can just accept it without thinking of compatibility issues or something. If a library is tested by several users it could be dragged into the main repo?

mrburnette
Mon Mar 14, 2016 12:01 pm
Of course, IMO, having the untested code on github is a two-edged sword.
Yes, it permits a holding grounds and archive, but
It also permits an area where the sources are unknown, the working state is unknown, and the quality unknown.

My fear is that traditional 8-bit to 32-bit porting efforts will wind-up in an incomplete state and just become a junkyard of digital goop.

We have always stressed on the forum that the person needing the library should manage their own port and engage the forum for specific issues. Thus, when the library is complete and is working satisfactory, a pull request can be issued to Roger. We now have working code and some issues that can be documented.

Just my thoughts,

Ray


konczakp
Mon Oct 03, 2016 10:07 am
@madias

Could You please add an example of two way communication like a ping-pong for tx and rx devices?

Thanks in advance


Manny
Mon Oct 03, 2016 5:20 pm
konczakp wrote:@madias

Could You please add an example of two way communication like a ping-pong for tx and rx devices?

Thanks in advance


konczakp
Tue Oct 04, 2016 11:25 am
Thanks a lot for that! :) Unfortunately I’m still having some problems with big amount of lost packets. I will have to check it out.

zoomx
Tue Oct 04, 2016 12:12 pm
It can be a power problem. Try to add a 100uF cap to the power pins.

Manny
Tue Oct 04, 2016 3:51 pm
You can also try lowering the PA level and see if it is a problem with the power supply.

radio.setPALevel(RF24_PA_LOW)


madias
Wed Oct 05, 2016 8:56 am
Basic communication demos works out of the box with this library. You can try out the “scanner demo” so you can test each module alone.
I always use this adapters:
https://www.aliexpress.com/item/10pcs-N … 18663.html
radio.setPALevel(RF24_PA_LOW)

41300895
Tue Oct 25, 2016 5:13 pm
Hey everybody, I found this code, which used TMRh20 RF24 library:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <DHT.h>

// The DHT data line is connected to pin 2 on the Arduino
#define DHTPIN 2

// Leave as is if you're using the DHT22. Change if not.
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

// PIR variables
byte pirPin = 9;
int pirCalibrationTime = 30;

// Photocell variable
byte photocellPin = A3;

// Magnetic Door Sensor variable
byte switchPin = 12;

// Radio with CE & CSN connected to pins 7 & 8
RF24 radio(7, 8);
RF24Network network(radio);

// Constants that identify this node and the node to send data to
const uint16_t this_node = 1;
const uint16_t parent_node = 0;

// Time between packets (in ms)
const unsigned long interval = 1000; // every sec

// Structure of our message
struct message_1 {
float temperature;
float humidity;
byte light;
bool motion;
bool dooropen;
};
message_1 message;

// The network header initialized for this node
RF24NetworkHeader header(parent_node);

void setup(void)
{
// Set up the Serial Monitor
Serial.begin(9600);

// Initialize all radio related modules
SPI.begin();
radio.begin();
delay(5);
network.begin(90, this_node);

// Initialize the DHT library
dht.begin();

// Activate the internal Pull-Up resistor for the door sensor
pinMode(switchPin, INPUT_PULLUP);

// Calibrate PIR
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
Serial.print("Calibrating PIR ");
for(int i = 0; i < pirCalibrationTime; i++)
{
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("PIR ACTIVE");
delay(50);
}

void loop() {

// Update network data
network.update();

// Read humidity (percent)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Read photocell
int p = analogRead(photocellPin);
// Testing revealed this value never goes below 50 or above 1000,
// so we're constraining it to that range and then mapping that range
// to 0-100 so it's like a percentage
p = constrain(p, 50, 1000);
p = map(p, 50, 1000, 0, 100);

// Read door sensor: HIGH means door is open (the magnet is far enough from the switch)
bool d = (digitalRead(switchPin) == HIGH);

// Read motion: HIGH means motion is detected
bool m = (digitalRead(pirPin) == HIGH);

// Headers will always be type 1 for this node
// We set it again each loop iteration because fragmentation of the messages might change this between loops
header.type = '1';

// Only send values if any of them are different enough from the last time we sent:
// 0.5 degree temp difference, 1% humdity or light difference, or different motion state
if (abs(f - message.temperature) > 0.5 ||
abs(h - message.humidity) > 1.0 ||
abs(p - message.light) > 1.0 ||
m != message.motion ||
d != message.dooropen) {
// Construct the message we'll send
message = (message_1){ f, h, p, m, d };

// Writing the message to the network means sending it
if (network.write(header, &message, sizeof(message))) {
Serial.print("Message sent\n");
} else {
Serial.print("Could not send message\n");
}
}

// Wait a bit before we start over again
delay(interval);
}


acronis
Thu Jul 27, 2017 6:24 am
Hello.
How and what kind of contacts (PIN) to connect the nrf24l01 to the Board STM32F407VET6 (black) to make it work ?

ChrisMicro
Thu Jul 27, 2017 8:58 am
You can simply plug it in:
Image

acronis
Thu Jul 27, 2017 9:13 am
Thank you.
Is there a working example to work on SPI3 with this Board ?

// Radio with CE & CSN connected to pins 7 & 8
RF24 radio(7, 8);

How to write for this Board this line ?
What pins should I write ?


JohnBoy
Wed Jan 17, 2018 3:16 pm
Hi there,

I am new on this site and posted a question about RF24 and Maple Mini.
I loaded the example of above and the added the libs to my PC and built the sender/receiver.
Everything seems okay (besides some warnings of redefinitions during compiling).
But the output of the receiver is totally rubish; even when I switch the sender of, the receiver produces the same random numbers
Could it be that the SPI or RF24 libraries have changed in the meantime or that I use the wrong ones?

thanks in advance

John


stevestrong
Wed Jan 17, 2018 4:40 pm
Without seeing the code is pretty hard to say what can be wrong.
Maybe a loose wire?
Power supply 5V <-> 3.3V issue?

zmemw16
Wed Jan 17, 2018 7:33 pm
one thing i keep seeing is too add a decently sized capacitor 10-50uF on the 3v3 at the the device.
mine are on the actual device pcb. i.e. moves with the device

stephen


JohnBoy
Wed Jan 17, 2018 11:02 pm
I will try the capacitor advice thx

Leave a Reply

Your email address will not be published. Required fields are marked *