Author Topic: RMF69W RFM69HW and Arduino MEGA, ATMega2560, 2560  (Read 25256 times)

sntlewis

  • NewMember
  • *
  • Posts: 17
RMF69W RFM69HW and Arduino MEGA, ATMega2560, 2560
« on: December 10, 2013, 11:07:32 AM »
I am pretty new to this forum and I am excited to find the Moteino/RFM69W...

I am trying to hookup the RMF69W on an Arduino Mega2560.  The Mega2560 will run a graphic/touch LCD and act as a controller on a network of Moteino's (glad I found them).

I want to double check the issues before I run into problems.

1) Mega2560 outputs to the RMF69W will need to run through a 4.7k/10K voltage divider on the RMF69W's NSS, SCK, and MOSI.  The rest are outputs from the RFM69W back to the Mega2560 and do not need to run through a divider

2) tap v3.3 and gnd off of the Mega to run the RMF69W

3) Connect as follows

Mega2560 pin D21 to RMF69W DIO0 
Mega2560 pin D53 to RMF69W NSS
Mega2560 pin D52 to RMF69W SCK
Mega2560 pin D50 to RMF69W MISO
Mega2560 pin D51 to RMF69W MOSI

I feel good about all except the DIO0 connection.  As best as I can tell, the library is looking for INT0 which is mapped to D21 on the Mega2560.  Is this a correct assumption? Or do I connect it to the Mega2560 D2 (which is OC3B/INT4)?

Lastly, I use I2C on the Mega2560 as well and the D21 is the Mega2560's SCL line.  Is this going to mess up I2C?  The I2C on the Mega2560 runs a RTC.
« Last Edit: April 30, 2015, 10:58:38 AM by Felix »
Stan

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #1 on: December 10, 2013, 11:11:19 AM »
I forgot to add that I would need to override the compiler RF69_IRQ_PIN with 21 instead of the default 2?
Stan

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #2 on: December 10, 2013, 07:44:21 PM »
1), 2), 3) I would say YES you are spot on.

For the DIO0 .. that's the interrupt INPUT. So if you plan to wire it to the SCL then that might be an issue since SCL is a clock .. which is an OUTPUT. So I'd say that won't work.
Pin D2 in atmega328 is tied to hardware interrupt "0". So when you attach an interrupt you have to pass 0 or 1 for atmega328. In my case the argument is 0 - corresponding to INT0 or D2. The other definition for D2 is for setting up that pin. So for mega2560 you'd have to probably move to another interrupt and there are many available. Just choose one that does't look very common, get the digital pin # and the interrupt # and replace them in the library.

Let us know how it goes...

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #3 on: December 11, 2013, 09:49:15 AM »
Well no joy yet...  Running the Gateway code on the Moteino and Node code on the Mega2560 (figured to test this way as a the Moteino will act more as a receiver in the main project).

Hooked up with 4.7K/10K divider no joy.  Radio temp readings are not valid...

Hooked up with 1K/2.2K divider some joy.  I can get radio temps to respond (on Mega2560).  Packets are sent, but not acknowledged (INT0 issue most likely), BUT.

I get the initial packet sent and acknowledged, then Mega2560/Node hangs (if I use the INT0-D21)....

If I let the Gateway run in "promiscuous" mode I see the packets come across but IDs (both sender and receiver ids) and Data are "damaged" after the first one/two (possibly spurious packets).  Changed baud rate to 4800, no joy....

still working... maybe a level shifter such as the 74HC4050 (reading the NXP AN10441 Level shifting App Note now...)

Stan
Stan

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #4 on: December 11, 2013, 01:02:37 PM »
More updates and more joy (still more joy to be found  :-\ )

1) use Arduino Mega2560 D2 to DIO0 and the 1k/2.2K divider
2) modified "Node" code example to use "send" instead of "sendwithretry"  still working on this one.  And set transmission time to 2000 ms.

Works almost without failure (at least on breadboard).  Some packets are dropped..

looking into why "send" works but not "sendwithretry"...
Stan

camdenl

  • NewMember
  • *
  • Posts: 13
Re: RMF69W and Arduino ATMega2560
« Reply #5 on: December 19, 2013, 03:14:03 PM »
Just wanted to say thanks for posting this.  Attaching to the mega's hardware spi and using D2 as the interrupt works just fine for me using the struct_send/receive sketches.  I have no luck with the gateway/node sketches however. 


sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #6 on: December 19, 2013, 08:33:55 PM »
no joy either with gateway/node sketches either... will try level shifters as soon as they get here...  I will look into the structure receive/send.

Did you use any level shifters/voltage dividers?
Stan

camdenl

  • NewMember
  • *
  • Posts: 13
Re: RMF69W and Arduino ATMega2560
« Reply #7 on: December 19, 2013, 09:59:19 PM »
Used a 2.2/1k voltage divider.  I have a bi-directional level shifter but the voltage divider actually worked better. 


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #8 on: December 20, 2013, 08:52:49 AM »
I always used 10K-4.7K to divide the signals, never had an issue.

camdenl

  • NewMember
  • *
  • Posts: 13
Re: RMF69W and Arduino ATMega2560
« Reply #9 on: December 20, 2013, 10:23:50 AM »
@Felix did you use a voltage divider for the interrupt pin as well?  If I don't have a voltage divider my board resets every time a message is received.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #10 on: December 20, 2013, 12:52:49 PM »
No. It's an input to the Arduino so no need to do that. Only the input to the transceiver should be divided.

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #11 on: December 20, 2013, 07:03:58 PM »
It doesn't seem that the RFM69 attached to the Mega2560 is getting the interrupt.  Maybe the 3V3 is too close on my Mega2560 for an input.  I tried two different RFM69s, both work same.

I did get the Node (on Mega2560) to Gateway (on Moteino) working (somewhat) by using "Send" instead of "SendWithRetry" and ignore the ACK back to the Mega2560.  It gets sent by the Moteino but the Mega2560 side never gets it.  Which is why I am suspecting interrupt level issues.  When I load the Gateway code on the Mega2560 and Node (on Moteino and using "send"), it does not work at all as the Mega2560 is largely in "receive mode," which again points a finger (at least in my line of reasoning) towards the interrupt signal on the Mega2560.

I suppose the line itself could be dead, really shouldn't be but I've seen crazier things....

I'm still hunting...  I could not get the 4.7K/10K divider to give any results which is why I switched to the 1K/2.2K divider..

I'm working on some other aspects of my coding endeavor (remote control of LED lights on reef/saltwater fish tank), while waiting for my level shifters to come in.

Stan

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #12 on: December 20, 2013, 07:13:28 PM »
Your reasoning is reasonable, the 3.3V might be just below the mega's logic "1" limit.
Maybe a bidirectional voltage shifter could solve the issue...

camdenl

  • NewMember
  • *
  • Posts: 13
Re: RMF69W and Arduino ATMega2560
« Reply #13 on: December 22, 2013, 10:22:22 AM »
Are you using the default interrupt pin or did you change your library config?

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #14 on: December 22, 2013, 07:56:14 PM »
Now I must admit that the interrupt pin issue is not yet resolved in my mind (it wont be until it all works).  But according to the arduino AttachInterrupt documentation Digital Pin 2 is "magically" attached to INT0 even though the pin out of the ATMega2560 chip shows it going to the D21 (iirc).

And so my dilemma.   I have tried moving the electrical connection to D21 but without success.  Still hunting....

The level shifters came in yesterday, but I've been too busy to try them out (maybe tomorrow).

Stan
Stan

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #15 on: December 22, 2013, 08:22:04 PM »
Haven't played with atmega2560 but it sounds like you have to first identify the INT0 and move from there. I'd probably setup a basic sketch where you read the interrupt (attach a button) and flash the LED or something like that.

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #16 on: December 23, 2013, 03:13:39 PM »
**** IT WORKS ****

Now for the specifics. 

1) Running vanilla Gateway/Node code except for frequency declaration.
2) one end is a Moteino (no hookup, circuit issues here)!  This end ran NODE code
3) one end is a Genuine Arduino Mega2560.  This end ran GATEWAY code.
4) circuit hookup as follows.

RFM69W pin --> Mega2560 Pin

NSS <-- D53 (SS) using voltage divider (see notes below)
SCK <-- D52 (SCK) using voltage divider
MISO --> D50 (MISO) straight thru
MOSI <-- D51 (MOSI) using voltage divider
DIO0 --> D2 (INT0) tried voltage divider, no worky

Notes on voltage divider...

I tried the 4.7K/10K divider and got nothing....
I tried the 1K/2.2K divider and got some joy.  Mega2560/Gateway doesn't get the interrupt properly..

Moved to next level of testing..

Tried level shifter from Adafruit on ALL lines  ---> MUCH joy works without issues
Moved back to voltage divider on ALL lines EXCEPT DIO0 (used level shifter here)  --> MUCH joy, works without issues....

Conclusion:  voltage divider works OK for everything except interrupt line.  Need level shifter on interrupt!

Now that I've got it working... Time to break it  8)
Stan

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #17 on: December 23, 2013, 03:59:52 PM »
Quote
Moved back to voltage divider on ALL lines EXCEPT DIO0 (used level shifter here)  --> MUCH joy, works without issues....

Ummm .. i think that is the correct way to wire it, I fully expect it to work like that. If the MISO line works, then the DIO-to-D2 straight through should also work.
So I think if you keep doing that then you don't even need the level shifter, just the resistors. Can you try again or confirm this is true?

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #18 on: December 23, 2013, 09:25:22 PM »
The straight through DIO0 to D2 doesn't work, though the MISO line works.  That was the way I had it wired up in the beginning and tried again after verifying that the level shifter on DIO0 worked. 

If I use the resistors on MOSI, NSS, and SCK, straight through on MISO, and the level shifter on DIO0 then it works...  And of course level shifter on all 5 lines works as well.
Stan

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #19 on: December 23, 2013, 11:47:07 PM »
Oh interesting... why would MISO work and not DIO0...
Anyway at least there's a resolution. Thanks for pulling through and taking the time to document and share this ;)

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #20 on: December 24, 2013, 04:24:23 PM »
yeah, my thoughts followed the same reasoning for MOSI and DIO0.  I would have expected both to work/fail.  Not MOSI work and DIO0 fail.

Now someone needs to create a small breakout board with necessary supporting chips (maybe even an 3v3 LDO regulator) to run the RFM69W on 5V.
Stan

NixHydra

  • NewMember
  • *
  • Posts: 41
Re: RMF69W and Arduino ATMega2560
« Reply #21 on: December 24, 2013, 08:43:20 PM »
Hi Stan,

   Curious stuff concerning the 2560 and RFM69W. I cobbled together an Arduino footprint RFM69W/HW shield recently and have tested it on an Arduino clone (Freetronics Kit Ten) , it works flawlessly. The design deliberately avoids using voltage dividers but handles 5 volt/3.3 volt logic level conversion, via a 74HC4050 hex buffer. Anyway, maybe you might find the following of some interest ... maybe not?

http://jeelabs.net/boards/6/topics/2934

   Merry Christmas!!



   

sntlewis

  • NewMember
  • *
  • Posts: 17
Re: RMF69W and Arduino ATMega2560
« Reply #22 on: December 27, 2013, 08:12:26 PM »
NixHydra, I saw that some time ago (I think I found the Moteino while looking at the Jeelabs stuff).  Still puzzled as to why I have to have the level shifter on the DIO0 line.  I noticed that yours did not have anything on the DIO0 line..

And now since the overall project prevents me from using D2 (on the Mega2560), I will look at moving the interrupt pin.  Boy this was confusing because looking at INT0 on the Mega schematic puts it on D21 but that doesn't work.  I found the attachInterrupt documentation but that confused me more.

Then I found this post http://www.gammon.com.au/forum/?id=11488&reply=8#reply8 and some others....

Then I realized that if one wants to use INT0 (vector table) then D21 is the pin BUT attachInterrupt(0, isr, RISING) is mapped to D2 on the Mega just like the UNO....

So in theory I can move the interrupt to say D19 by changing two lines in the code.....

attachInterrupt (4, RFM69::ISR0, RISING) (in .cpp) and #define RF69_IRQ_PIN  19 (in .h)

I will try this when I have some more time....

Stan
Stan

camdenl

  • NewMember
  • *
  • Posts: 13
Re: RMF69W and Arduino ATMega2560
« Reply #23 on: January 06, 2014, 04:51:34 PM »
Kind of forgot about this thread over the holidays...

Anyways just wanted to say that I had no problem changing the default interrupt on the Mega and using the rfm's, and the two lines of code you posted should work.

Also wanted to add that straight through on the MISO line worked for me but I needed a voltage divider onr the interrupt pin as well.
« Last Edit: January 06, 2014, 04:54:31 PM by camdenl »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: RMF69W and Arduino ATMega2560
« Reply #24 on: January 06, 2014, 05:24:31 PM »
So this pretty much confirms that the MISO does not need level shifting while the interrupt needs it (ie level up to 5V).
Without digging in the datasheets or doing some scope captures for answers it's hard to guesstimate why this is happening but perhaps there's a difference in voltage when logic 1 is present on the two outputs of the RFM transceiver (ie DIO is lower logic 1 voltage than MISO). If this is true then the level-up shifting solves the problem by putting that voltage above the logic-1 threshold of 5V.

shakeycal

  • NewMember
  • *
  • Posts: 1
Re: RMF69W and Arduino ATMega2560
« Reply #25 on: January 09, 2014, 11:30:09 AM »
Hi, I've just started playing around with my moteino, and was having issues running an Uno + RFM69HW as a basestation. After reading through a few threads and trying to find a super simple + cheap way to raise the level, can confirm that incorporating the following for DIO0 --> D2 has solved the problem:

 

(Borrowed from http://electronics.stackexchange.com/questions/81580/step-up-3-3v-to-5v-for-digital-i-o)

Cal




chalupien

  • NewMember
  • *
  • Posts: 21
Re: RMF69W and Arduino ATMega2560
« Reply #26 on: March 20, 2014, 01:39:27 AM »
No. It's an input to the Arduino so no need to do that. Only the input to the transceiver should be divided.


So only one divider is needed on the MISO (input) what about Output and the Select pins?

chalupien

  • NewMember
  • *
  • Posts: 21
Re: RMF69W and Arduino ATMega2560
« Reply #27 on: March 20, 2014, 01:47:56 AM »
Reading this post

RFM69W pin --> Uno Pin

NSS <-- D13 (SS) using voltage divider
SCK <-- D12 (SCK) using voltage divider
MISO --> D10 (MISO) straight thru
MOSI <-- D11 (MOSI) using voltage divider
DIO0 --> D2 (INT0) straight thru

Does this seem to be the consensus for communicating to the RFM via the UNO's 5V pins 11,12,13?