RFM12B and arduino mega

Hi guys,

I'm trying to hook up my arduino mega with a RFM12B, but unfortunately still having issues :0

On a breadboard, to me everything seems fine - I'm using the jeelib library - when I switch to "group 0" I see a lot of incoming packets (various lengths with some data).

When I tried soldering it to a perfboard, I also see lot of incoming packets, but they're all "empty" - the RFM12B demo from jeelib just shows "? G0 0" in a loop, so I guess the receiver works somehow, but it seems more like it's just some noise or I connected something wrongly.

I guess the problem is, that I didn't solder on any capacitors on the board - does anyone have a fritzing layout that is working for him and I could try to reproduce it first on a protoboard to be sure I got it right this time? To be honest, I don't know where to put the capacitors and what sizes they should be, I guess one cap between VCC (3.3V output from Arduino) and GND should be enough
(I've seen the jeelabs rfm12 board uses three capacitors but to be honest I don't understand what are they used for)

There have been dozens of previous threads on using the RFM12. Try the lowpower lab RFM12 library. I never could get jeelib to work properly.

The Send and Receive examples seem work 100% of the time without any wasteful muckaround.

thanks, will try with that one

Since the lowpower labs library works out of the box, so to speak, try that first.

Then, try adding more caps. You should always have a 100nF cap on the Vcc pin of the RF module for general noise/transient filtering, and possibly an electrolytic, eg 22-100uF. Some people find they need the electrolytic, it seems, largely because the 3.3V voltage regulators being used are a little deficient, eg only supplying 50mA or so. But the RFM12 is low current draw, so the v.reg capability shouldn't be a big problem.

hi there, still no luck even with the lowpowerlab library :frowning:

I modified the examples a bit, so now I have two-way nodes (each is sending and receiving), but I always get "BAD-CRC" on both ends, otherwise the radios look ok (i.e. everytime the 1st sends data, the 2nd receives a packet and returns BAD-CRC)

what could be the reason for this? can I use the same instance of the RFM12B to send and receive? doesn't it mess-up the crc somehow?

Maybe it's time to show/tell us how you have it wired to your Mega.
From the LPL library it's expecting this...

RFM_IRQ = Pin 2
SS = Pin 53
MOSI = Pin 51
MISO = Pin 50
SCK = Pin 52

that's what I have (and I'm assuming it's correct, since it seems to "work" - i.e. when I disconnect one of the nodes, the second keeps getting the "BAD-CRC", and when I connect it back it receives again)

i'm a noob when it comes to electronics unfortunately - i.e. could for example too long connection cables be a problem? I'm doing it on a breadboard + the module I have is the DIP package, so I have quite long cables (20 cm) from the module to the breadboard, and also about 10 cm from breadboard to arduino (I can't connect it directly, I have the voltage divider on the breadboard)

Do you have more details and links to the RFM12B modules your using.
Also some details on your voltage divider (resistor values) and how it's all connected to the Mega.
Long breadboard wires won't help.
Also having the miss matched antenna (how long is yours) or putting the two transceivers to close together (how close) will cause problems.
Are the two+ transceiver modules connected to separate Mega's or are you trying to send/receive both on the one Mega?

hi,
the modules are: RFM12B 868D HOPE MICROELECTRONICS - Module: RF | FM transceiver; FSK; 868MHz; SPI; -105dBm; 2.2÷3.8VDC; RFM12B/868D | TME - Electronic components (WFS)

resistor values are 10k and 4.7k, I checked the voltages and I'm getting around 3.41V

antenna was supplied with the modules, but it's approx. 162mm (I'm running the library with "RF12_868MHZ"), the distance between transceivers is approx. 30cm

each module is on a separate arduino, but have them both connected on one breadboard (but it's the one with separate power buses)

I'm just guessing it's the cables - that somehow they're creating interferences in each other

I'm attaching the diagram how I have it connected (only the DIP package layout, when I have the "3.3V !!!" note, it's connected to the divider, otherwise directly to breadboard)

Antenna length is good.

Voltage divider is good.

Connection is not so good if your drawing is correct.
MOSI = SDO = Pin 51
MISO = SDI = Pin 50

Hello tang, it's late here and time for sleep. However, I have something for you to try. First off, I believe your SPI pins are OK. MOSI is slave in, and SDO is slave out, so I believe Riva has it backwards. Also at 868, your antenna should actually be 86mm for a whip, not 162, but I don't think that will matter much.

Secondly, I have been wrestling with the RFM12 library a lot, since the original posts here. It works OK for the 328 chip, but otherwise has a lot of problems. Among other things, the library forces use of INT0, which appears to be on pin 21 of the Mega2560 board. So go into the library, and change RFM_IRQ to 21 in the mega2560 section, and see it if works.

EDIT: note - this latter info is wrong, as discussed in reply #13.

oric_dan:
Hello tang, it's late here and time for sleep. However, I have something for you to try. First off, I believe your SPI pins are OK. MOSI is slave in, and SDO is slave out, so I believe Riva has it backwards. Also at 868, your antenna should actually be 86mm for a whip, not 162, but I don't think that will matter much.

You may be right about SDI/SDO the reference I looked at (wikipedia) says

Alternative naming conventions are also widely used:

SCLK: SCK, CLK: serial clock (output from master)
MOSI: SIMO, SDO, DO, DOUT, SO, MTSR: serial data out; data out, serial out, master transmit slave receive
MISO: SOMI, SDI, DI, DIN, SI, MRST: serial data in; data in, serial in, master receive slave transmit
SS: nCS, CS, CSB, CSN, nSS, STE: chip select, slave transmit enable (active low, output from master)

Antenna length is fine with either it's just 1/4 wave - 1/2 wave

There is always a little problem in regards those signal conventions. But the RFM12 module is labelled in regards its own self, not in regards the master device.

Also, these modules usually use a 1/4 wave whip, in which case it should actually be 86mm. My 433Mhz modules use a 173mm whip. However, I'm 99% sure antenna length is not tang's problem. Wrong antenna length will probably only affect usable range to some degree.

Unfortunately, the info I gave previously in reply #10 was bad.

I now discover that INT0 is indeed on Arduino header pin D2 on the Mega2560 board after all. It happens to be shown wired to D21 on the Mega2560 schematic, which was the source of my previous confusion, but it turns out that it's re-mapped in software [duh, some days!]. So, INT0 = D2. Wire the RFM12 that way.

Do you use an Atmega2560 with your breadboard?
I have tried for some time ago to use a RFM12B with the Arduino Mega 2560, but also without success. I'm not sure if there is something wrong with the JeeLabs library, but you can find some more threads with problems.

I use the RFM12B with an ATtiny84 and I use only a small capacitor (10pF) at the ATtiny and one at the RFM12B module (nearly at Vcc pins). If I see it correct, the JeeNode uses for the voltage regulator two caps with 0.1 µF and one electrolytic with 10 µF, but I don't think that this is the problem.

yeah, I'm using an mega2560 - to me it also looks like an issue with the arduino :frowning:

will try to get a different arduino - anyone have it working with a uno?

Spexx, I have no experience with the tiny84 or 44. Can you tell me what pins you use for SPI and SS? Is there a standard boot loader, Arduino Dx pin assignment, or a pins_arduino.h file somewhere?

Ok, I've just tried the lowpower library with both Mega2560 and UNO boards, and it works fine with both boards. Tang, I really don't think the Arduino board is the problem, you likely have something not hooked correctly. That's my best guess.

You need 7 wires from the Arduino to the RFM12 module, and it's easy to get something crossed. You also need voltage-dividers on at least 3 pins, SCK,MISO,SS. I would recheck the connections at the RFM module, as those pins are easier to mistake than the Arduino pins.

The library is correct for the pin assignments, although it's written in a confusing manner. Eg, in the following for 2560, the 1st line means Arduino D2, the next three are Port.pins on the chip, and the last four are Arduino pins again, D50..D53. The code forces use of INT0, which is the D2 pin.

#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
  #define RFM_IRQ     2
  #define SS_DDR      DDRB
  #define SS_PORT     PORTB
  #define SS_BIT      0
  #define SPI_SS      53    // PB0, pin 19
  #define SPI_MOSI    51    // PB2, pin 21
  #define SPI_MISO    50    // PB3, pin 22
  #define SPI_SCK     52    // PB1, pin 20
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RFM_IRQ     10
  #define SS_DDR      DDRB
  #define SS_PORT     PORTB
  #define SS_BIT      4
  #define SPI_SS      4
  #define SPI_MOSI    5
  #define SPI_MISO    6
  #define SPI_SCK     7
#elif defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
  #define RFM_IRQ     2
  #define SS_DDR      DDRB
  #define SS_PORT     PORTB
  #define SS_BIT      1
  #define SPI_SS      1     // PB1, pin 3
  #define SPI_MISO    4     // PA6, pin 7
  #define SPI_MOSI    5     // PA5, pin 8
  #define SPI_SCK     6     // PA4, pin 9
#elif defined(__AVR_ATmega32U4__) //Arduino Leonardo, MoteinoLeo
  #define RFM_IRQ     0	    // PD0, INT0, Digital3 
  #define SS_DDR      DDRB
  #define SS_PORT     PORTB
  //OLD from Jeelib: #define SS_BIT      6	    // Dig10, PB6
  #define SS_BIT      0	    // Dig17, PB0
  #define SPI_SS      17    // PB0, pin 8, Digital17
  #define SPI_MISO    14    // PB3, pin 11, Digital14
  #define SPI_MOSI    16    // PB2, pin 10, Digital16
  #define SPI_SCK     15    // PB1, pin 9, Digital15
#else
  // ATmega168, ATmega328, etc.
  #define RFM_IRQ     2
  #define SS_DDR      DDRB
  #define SS_PORT     PORTB
  #define SS_BIT      2     // for PORTB: 2 = d.10, 1 = d.9, 0 = d.8
  #define SPI_SS      10    // PB2, pin 16
  #define SPI_MOSI    11    // PB3, pin 17
  #define SPI_MISO    12    // PB4, pin 18
  #define SPI_SCK     13    // PB5, pin 19
#endif

Also, if you look at the 328 assignment at the end, the SPI pins are pretty clear, D10..D13. It's just written in a confusing manner. For better clarity, it would say something more like

#define SPI_SS 10 // Arduino D10, PB2
#define SPI_MOSI 11 // Arduino D11, PB3

I have tried to connect the RFM12B to a Mega + Ethernet Shield, I don't remember if it was only a problem with the Shield or also with the Mega... At the moment I use a JeeNode (like an UNO) with the RFM12B module which is connected to the Mega via I2C :slight_smile:

@oric_dan
I use some "TinyTX" sensors with an ATtiny84 like here: http://nathan.chantrell.net/tinytx-wireless-sensor/
The connecting of the RFM12B module you will find in the attached schematic.

Thanks for the info on the Tiny. Also, you should be able to get the RFM12 working side by side with the Ethernet shield. You just need to be sure not to use D10 for the RFM12 CS, and be sure D10 is HIGH when accessing the RFM12, so the Ethernet is disabled.

On my ATMega1284 board, I have Ethernet, RFM12, SD, and ColorLCD all using the SPI port, and it all works.