reliable datagram RF22 library question

For my next project, which is a remote control and telemetry link to a very large robot, I want to have a safe wireless link with a range of at least 300meters. I can use a decent antenna at the control centre, and a dipole on the robot, so range should be no problem.

I have used the RFM22B modules before, but only in the basic simplex mode, I now have 2 of them hooked up on the bench and using the RF22 libraries “reliable datagram” example from Mikem , with 2 Duemilanova boards for now ( they will have embedded chip pcbs in the final units ).

It worked first time, and I have found how to simply read the temperature and signal strength etc.

Now I am looking at how to structure my data, ( which is joysticks and switch data going to the robot, and a few oil pressure, fuel guage, temperature , signal strength and GPS position data coming back )

I was planning to collect the data and put it in a buffer to send, all in the main loop as usual.

In Mikes example below, he has defined the data and datalength between the setup and loop sections ?
Is there significance to this ?
I guess thats the same as having them at the top with the definitions if they are not going to change ?

and I can find no reference to while (1) ? and why // Dont put this on the stack:

// rf22_reliable_datagram_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple addressed, reliable messaging client
// with the RF22ReliableDatagram class.
// It is designed to work with the other example rf22_reliable_datagram_server
#include <RF22ReliableDatagram.h>
#include <RF22.h>
#include <SPI.h>
// Singleton instance of the radio
RF22ReliableDatagram rf22(CLIENT_ADDRESS);
void setup()
if (!rf22.init())
Serial.println("RF22 init failed");
// Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
uint8_t data[] = "Hello World!";
// Dont put this on the stack:
uint8_t buf[RF22_MAX_MESSAGE_LEN];
void loop()
while (1)
Serial.println("Sending to rf22_datagram_server");
// Send a message to rf22_server
if (!rf22.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
Serial.println("sendtoWait failed");
// Now wait for a reply from the server
// Serial.println(rf22.lastRssi(), HEX); // of the ACK
uint8_t len = sizeof(buf);
uint8_t from;
if (rf22.recvfromAckTimeout(buf, &len, 2000, &from))
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println("No reply, is rf22_datagram_server running?");

Is there significance to this ?

No. Anything declared outside of a function is global. Whether that happens before the first function, between functions, or after the last function does not matter.

and I can find no reference to while (1) ?

It's running an infinite loop, inside an infinite loop, so it's silly. Get rid of it.

and why // Dont put this on the stack:

It's suggesting that the array should not be passed as an argument to a function. Passing arguments makes use of the stack. Of course, it would only out the address on the stack, and there is no problem with that, so the comment is useless.

Thanks Paul, I shall move on now then

On a different point, have you verified the RFM22s can communicate out to 300m? I would check this before going very far with the rest of it. What frequency are you using, 433 Mhz? BTW, I have the RFM12, 1 mW module, and got range to about 120 feet [36m] at 433. RFM22 will certainly be a lot farther.

How do you plan to connect antennas to the modules? They are made for those 1/4 whip antennas [ie, piece of wire soldered on]. Do you know if the modules will function properly with something else, like a soldered-on coax leading to a external antenna?

I have only got these modules hooked up accross the bench at the moment , but I want to test the range tomorrow.

I had over 150m range with the modules in the simplex mode ( I didn't check further as I was at the end of the road and only needed 100m ! )

Well, 150m sounds pretty darn good, :-). I tried the little nRF2401+ modules a couple of weeks ago, and got only about 10m range [1 mW, 2.4Ghz] - disappointing.

I am also wanting longer range for my largish 4WD robot, which is intended to go off across fields the size of baseball pitches, etc, so 150m sounds great. As the robot will actually be "autonomous", for fail-safe, I plan to have the base station continually pinging the robot, and if the signal drops out, then the robot will backtrack along its previous outgoing path until it's back in range.

Looks like we are on a similar course agaIn with this project.

I don't know how you were testing the RFM22B modules, but I have them hooked up to the 3.3v of the Arduino, and I found I need a 4700mFd cap on the 3v3 supply line to take the pulse when it transmits at full power.

I also want to monitor the SSR reading every second or so, at both ends, and display it on the LCD with a warning light if either drops below a certain level.

I am thinking of having the robot send its housekeeping data every second, so as to monitor the comms, and hold back when receiving " driving" data from the remote.

I am going to add a LED flash ( can't use pin13 as its SPI ) and take a walk with the one arduino on a battery tomorrow, I will try it with the 170mm whips both ends.

Have you got the RX and TX tied to the GPIO pins ?

I will post the range results tomorrow.

Forgot to mention, for my RFM12 range test, one node was inside the house and the other node on the street with me carrying, so inside to outside, rather than direct LOS. What I did was send an entire packet of 24 bytes or so from the host, and test for correct receipt at the remote, and then flash an Led. Also, 170 mm whips.

I have a couple of RFM22s, but not tested as yet. I was jury-rigging a lashup a couple of weeks ago, but one of the pads fell off the pcb from the soldering heat, and the tiny 6-mil trace snapped off. 6-mil traces, PITN.

Yesterday, I figured out I will stick the RFM22 to an XBee pcb using double-sided tape, and tack solder to the pads, then jumper the XBee socket pins on my Arduino test pcb over to the SPI pins, etc. Need some 2mm male headers. Another job in the queue.

Well the range test with the reliable datagram was hardly worth me putting some sandals on, it faded out at about 7m range !

I had looked at the data to the module, and it looked so fast compared to my normal projects.

I couldnt find a way to change the data rate, so I delved into the RF22 library cpp file, and changed the power to 17 dBm, and the baud rate to the one I used on the simplex mode. ( i have no idea what it means ! )

There is a spreadsheet to calculate the set up , but it doesn't work in openoffice :-( My changes :-

// setModemConfig(FSK_Rb2_4Fd36); setModemConfig(GFSK_Rb2Fd5); // setTxPower(RF22_TXPOW_8DBM); setTxPower(RF22_TXPOW_17DBM);/

I can now walk 50m to the end of my road with it still working, and I am going to take them out on a straight road to test. It did fade through 3 buildings, but my appication is in the open air...

Hmmm, not the range I was hoping for, I had a LED toggle on and off when a valid length message arrived ( sent every 500ms )

I got 150m solid signal, but after that it would skip a flash, but never actually stopped receiving even up to 250m, it just missed flashes more often.

OK I will be using a yagi at the TX, and perhaps a dipole at the RX, so it could work, but its got to be reliable.

The fact that it still received at over 250m seems to suggest that the RF strength isn't the problem, perhaps its a signal/noise bandwidth issue ( I hate RF , even when I was a radio ham 50 years ago ! )

The fact that the range went from 7 meters to 150 just with my library pot luck twiddles makes me think that perhaps I am a quarter of the way to the answer, but don't know enough about the software.

I used SIM20 modules last year on a project, but the documentation is atricious, so I dont think I can get that working in a semi-duplex mode. I got 500m range with them, also with a 170mm antenna wire.

These RFM22Bs are a third of the price, so I would like to get them going properly, and perhaps use the diversity combiner mode with 2 antennas to avoid dead spots.

I have just found this on a picaxe forum

"I was just doing some long range LOS tests with the 434Mhz tuned RRM22, I got 100% reception reliability at 4.3Km with 25mW output, 50% reliability at 12mW. This was using 5khz deviation and 250bps data rate with Manchester enabled. "

Anyone know how to set these parameters ( OK perhaps not that slow ) up with the RFM22B , there is a spreadsheet thing to calculate it, but as I said it doesn't work on my Openoffice :-

I basically want to send 10 bytes every half second, and receive similar from the robot, so its not a lot of data.

I don't know the ins and outs of setting all the module parameters. I did read the d/s for the RFM12, and it does have a huge amount of parameters that can be set. About the only thing I know is, you can increase the range by reducing the transmit RF data rate [not the baudrate between Arduino and module]. Also, many of the cheaper 433 devices use only 9600 bps RF transmit rate, and they seem to have a longer range.

I asked Bob [docedison] about soldering coax to the RFM22 teminals, he sent this [I thought he was gonna post it himself] ...

Were I you I'd advise him to use RG316 coax,It's 50 ohm teflon about the same size as RG174 and directly solderable. The receivers are matched to a 50 ohm load, standard for RF. The RG316 is the same size as 16 Ga THHN house wire. RG 174 is polyethylene and hard to solder unless you are familiar with the cable it also has about 3 DB loss @ 433 MHz with 4" of cable and it leaks like a sieve. Were it possible, and much better for him to find a board with a connector footprint there and put a connector in it.

4700mFd cap

BTW, I don't understand what that value is. 4700 micro-farads? A huge cap?

Thanks, and thanks to Bob re the coax, I will bear that in mind,
What I tend to do latlely is to mount the transceiver on the antenna, and use ribbon cable to the 328 board,

Yes the 4700uF is a huge cap that can allow a current surge from the 3.3v arduino line for the transmitter.

Excellent Idea, @ Boffin.. I might reccommend a separate 1117-3V3 regulator at the transceiver... and another 4700 uF cap although with your own regulator should work fine with 22uF. Good Luck In the Contest...


I am only using the 4700mFd while I am checking it out on the Arduino board, as the onboard 3v3 supply cant handle the rush, but I scoped the cap and it hardly dips at all.

The LP2985-3.3 is rated @ 150 mA. Perhaps that's OK for 2 wire pull-ups and some of the smaller sensors But IMO 100 mA is too low for a general purpose 3V3 supply But neither did the designers as the 'manual' for the Mega (I own 2 of them) Clearly states that there is a 50 mA limit on the current that can be drawn from that source. The Nordic and the others in that family don't draw a great deal of quiescent current but on transmit there is a lot going on very quickly or what would be called a high DI/DT or the change in current over the change in tine, current from 2 places one is the SPI bus in the transceiver and the other is the PA after the synthesizer... The problem and why the 4700 uF cap makes the radio's work is that it stores energy from the 3V3 source to 'help' out when there are any demands on the 3V3 source. The issue that makes this necessary is that the copper to the 3V3 pin is likely not very wide making a resistive connection to the 3V3 source pin and the by-pass in the 3V3 source on the Mega board is C13, A 1uF MLM ceramic cap this is the minimum value for stability. 2200 to 4700 uF at the end of 3 - 4 inches of breadboard is enough to make the issue go away. For higher power devices in the 40 to 80 mA class I would NOT recommend using the 3V3 source from the Mega Or for that matter at least the R3 Uno and I would expect the previous versions are the same or similar.. as is the Leonardo C14, 1uF MLM Ceramic). The implications are worse If you plan on using the RFM22-3B radios as they draw 80+ mA on transmit and more if the antenna isn't right. I use at least 3300uF and as much as 4700 uF when using a Mega board and either the Nordic or Hope RF RFM12-22/3 radios for test and a separate 3V3 regulator for the finished project. My one recommendation would be that If there is any doubt... Use a separate 3V3 regulator in your project. I do.


I am only using the 4700mFd while I am checking it out on the Arduino board, as the onboard 3v3 supply cant handle the rush, but I scoped the cap and it hardly dips at all.

That changes things a lot. I don’t think you mentioned which Arduino bd is being used,
some of them only provide 50 mA or so at 3.3V. I’m almost to the point of soldering up
my RFM22, and will see how a regular v.reg handles it. I’m using this,

I’ve been using the same layout and lashup with XBee Pro modules which draw 250+ mA
on transmit, and not seen any problems.

I have given up on these RFM22 modules, and dug out the SIM20 modules, which I am trying to use. I have just done a range check and ran out of road, with one unit on my bench ( with I have just noticed, only a 120mm antenna ! ) and me going walkabout. The furthest I could get was 170m away from my desk, through 4 houses and 3 walls, and it was still solid.

Tommorow I will fit correct antennas and do the open space test As this post no longer refers to the title, I have started a new post at,155930.0.html

Ok, I don't understand why you gave up on the RFM22s. You couldn't get enough range?

I thought the range would be better, but I am sure its that I dont now how to set them up, and there doesnt seem to be anyone who has tried ? They should have good performance with 18dbm Tx and 118dbm Rx sensitivity ..... but I was doing something wrong.