LowPowerLab Forum

Hardware support => General topics => Topic started by: Eish on April 30, 2015, 07:56:18 AM

Title: RFM69 failure with Arduino Mega and Duemilanove
Post by: Eish on April 30, 2015, 07:56:18 AM
I have an Arduino Duemilanove(328P) clone and a Mega(2560)

I tried the two sketches provided on https://github.com/LowPowerLab/RFM69
https://github.com/LowPowerLab/RFM69/blob/master/Examples/Node/Node.ino
and
https://github.com/LowPowerLab/RFM69/blob/master/Examples/Gateway/Gateway.ino

Firstly I notice that the RGM69.h file does not allow for the Mega. When using this board the compile keeps failing on the "RF69_IRQ_PIN" not being defined.
QuoteC:\Program Files (x86)\arduino-1.6.1\libraries\RFM69-master/RFM69.h:82:116: error: 'RF69_IRQ_NUM' was not declared in this scope

I have tried adding the Mega as an extra processor board but it keeps failing.

defined(__AVR_ATmega2560__)

#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega2560__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          2
  #endif


But that did not work.

I also tried just defining the "RF69_IRQ_PIN" pin on it's own but still no luck.
#define RF69_IRQ_PIN                  2
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
//  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
//  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          2
  #endif


So, trying to use the Mega to test the software with is a bust   :(

BTW, why is the IRQ specified for pin 2? Can I change it to another pin? If so, do I have to edit the RGM69.h file every time or is there a way of passing it through the sketch. To me it seems to be hardcoded in the the .h file


Using the Duemilanove board, the code compiles and downloads, but it fails in the setup() on line radio.initialize(FREQUENCY,NODEID,NETWORKID);

I know this because I added these two lines to the sketch ...
  Serial.println("Before Init");
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  Serial.println("After Init");

but all I get on the Arduino IDE serial monitor is "Before Init" and there it stays.
I also noticed that the onboard LED (wired to D13) lights up the moment I activate the Serial Monitor. If reset the arduino by cycling the power that LED does not come on. Only when I want to debug using the Serial monitor  ???

I have double checked the wiring of the RFM69W transceiver.
I have it it as follow on the Duemilanove
RFM pin SCK   to Duemilanove pin 13 (D13 - SCK)
RFM pin MISO   to Duemilanove pin 12 (D12 - MISO)
RFM pin MOSI   to Duemilanove pin 11 (D11 - MOSI)
RFM pin SS   to Duemilanove pin 10 (D10 - SS)
RFM pin DIO0   to Duemilanove pin 2 (D2)
RFM pin Gnd   to Duemilanove pin Gnd
RFM pin 3V3   to Duemilanove pin 3V3

I have ordered 3 RFM69W and 4 RFM69WH (433Mhz) transceivers.

I have tried my application with nRF24L01 transceivers but they do not give me the range required. Line of sight up to about 20 meters is all I got out of the nRF24L01's. I need at least double the distance and I believe the RFM69's should be able to handle that. Now, if I can only get them going  :'(
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Felix on April 30, 2015, 10:49:42 AM
Please see this thread (https://lowpowerlab.com/forum/index.php/topic,229.0.html).
It's worth to do a search on the forum, sometimes the solution is already posted.
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Eish on May 01, 2015, 02:51:31 AM
Hi Felix,

Thank you for the reply (and a great website too)

Yes (Oops  :-[). I saw that thread a minute after I posted mine. It does explain the comms issue. I ordered Bi-Directional Level Shifters for that.

But may I still ask why my modification to the .h file did not work for the Mega? Or do I have finger trouble again?
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Felix on May 01, 2015, 07:47:57 AM
You're welcome.
In light of the other thread which offers a solution, I will just point you there to investigate since I don't know the answer without digging that thread myself. I have not used atmega2560.
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Robert on May 10, 2015, 01:55:38 PM
May I propose to add support for ATMEGA2560 (and ATMEGA1280) in the RFM69 Library.

These models are not currently defined, however a slight modification of the RFM69 library will make them usable.

In RFM69.h, replace the line:
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)

By
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)


Don't forget that the configuration SPI interface of the ATMEGA2560 is different, according to the:
/Applications/Arduino-1.xx.app/Contents/Resources/Java/hardware/arduino/avr/variants/mega/pins_arduino.h:

static const uint8_t SS   = 53;   
static const uint8_t MOSI = 51;
static const uint8_t MISO = 50;
static const uint8_t SCK  = 52;

Note that in this case the comment of the Slave Select definition could be modified as follow:

#define RF69_SPI_CS             SS // SS is the SPI slave select pin, for instance D10 on ATmega328 or 53 on Atmega2560


The INT0 is still associated to pin D2, see http://www.arduino.cc/en/Reference/AttachInterrupt.

The RFM69 module should be connected to these pins with the necessary voltage level drop resistors (5V to 3v3).

This configuration was tested only with an ATMEGA2560.

Regards,

Robert
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: TomWS on May 10, 2015, 04:28:02 PM
The only concern I would have is to make sure that the Wireless Programming Library flags a warning if this processor is used.  The memory size exceeds the program storage field in the FLX header (the ATmega1280 might as well).

Tom
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Robert on May 11, 2015, 04:14:59 AM
Tom,

The issue with the RFM69.h is that there is no default definition for:
RF69_IRQ_PIN         
RF69_IRQ_NUM

So when no processor matches the foreseen value, an error occurs at the compilation time.

If you don't want to see ATMEGA2560 or 1280, I propose just to add a default setting for RF69_IRQ_PIN  and RF69_IRQ_NUM

So that the  RMF69 class may be configured with all the parameters like:
RFM69 radio (49,21,true,2); // (SS on pin 49, Interrupt on pin 21, RFM69H, Interrupt number 2)
Note that this example has been test with a ATMEGA2560

This setting is not possible if no default definition in the header file.

The alternative is therefore:
// INT0 on AVRs should be connected to RFM69's DIO0 (ex on ATmega328 it's D2, on ATmega644/1284 it's D2)
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          2
#elif defined(__AVR_ATmega32U4__)
  #define RF69_IRQ_PIN          3
  #define RF69_IRQ_NUM          0
#else
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0 

#endif

I believe this is not a big change and it will allow to use the RFM69 as a standard library for any processor type and applications that requires more memory (knowing the SPI and Interrupt configuration of course).
Currently using a Ethernet Shield, is not possible with the MOTEINO MEGA (due to the SS pin conflict) without hardware changes

Robert 
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Felix on May 19, 2015, 02:16:18 PM
Quote from: Robert on May 11, 2015, 04:14:59 AM
#else
  #define RF69_IRQ_PIN          2
  #define RF69_IRQ_NUM          0
#endif


This has now been added.
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: TomWS on May 19, 2015, 05:11:00 PM
@Robert,
I had no issue with adding the conditional declaration using the larger memory processor, although I do like the proposal for the default values better. 

My issue was with the implication that these larger devices are supported by ALL Lowpower libraries, including the Wireless Programming library, which I don't believe can be supported without changes to both the bootloader and the WirelessHex libraries, hence my suggestion of adding a warning message if this device is used.  The warning message would properly be put in the WirelessHex69.h.

Tom
Title: Re: RFM69 failure with Arduino Mega and Duemilanove
Post by: Robert on May 29, 2015, 10:14:06 AM
Thanks for this change,
Robert