iwanders / plainRFM69

A library for the RFM69 radio module.
MIT License
32 stars 12 forks source link

Moteino #1

Closed bloever closed 9 years ago

bloever commented 9 years ago

Hello,

Thank you for a cleanly written library.

This is not an issue, but could not find somewhere else to reach out to you. Have you by any chance tested this on Moteino's?

Thanks!

iwanders commented 9 years ago

Hi,

Thank you for your interest. I haven't tested it on a Moteino. I have gotten it to work on an Arduino UNO and Arduino mini, but I've only tested it for a very short timespan. This testing resulted in c4a3fd483e81645d2d2bc52328856a1253d5891d, which solved an issue that is caused by the difference between the 32 bit Teensy chip and the 8 bit Atmega328 chip on the Arduino (and Moteino).

The only requirement on the software side is an SPI library which supports the transactions. (Judging by https://www.arduino.cc/en/Tutorial/SPITransaction this seems to be included in the standard SPI library these days.)

On the hardware side, if you want to use the recommended interrupt system you should connect DIO2 from the radio module to an interrupt capable pin. Looking at a photograph of the Moteino, it should only be a short wire on the bottom side of the device.

I'll leave this issue open for now, if you (or someone else reading this) do test it, please report back with your results. Others might be eager to hear whether it worked.

bloever commented 9 years ago

Thanks for getting back to me so quickly.

I'm doing some testing with a MoteinoR4 and a MoteinoMega. So far I have been able to get the Minimal Example to work, but it has some quirks, I suspect interrupt (DIO 2) has something to do with it. The MoteinoR4 comes with DIO 0 on (RFM69W/HW) soldered to PD2 (INT0)->D2 on the Atmega328 and the MoteinoMega has DIO 0 soldered to PB2 (INT2)->D2 on the Atmega1284.

Is there any way we can utilize DIO 0 instead of DIO 2 as it is pre-soldered on the Moteino's?

Edit:

Reading the documentation of the RFM69W/HW I see that this might be a completely different approach to sending/receiving packets than what you have implemented already.

I'll try to solder a wire as you suggested and see how things work then.

bloever commented 9 years ago

Just a quick update. I soldered a wire on DIO2 on both my MoteinoR4 units with RFM69HW attached on the back. I used INT1 (D3) on the Moteino's.

Config was like this:

define SLAVE_SELECT_PIN SS

define DIO2_PIN INT1

I'm running the MinimalInterrupt example. The sender seems to send. It outputs Flags1: 16 Flags2: 0 when debug is defined. The receiver however does not receive anything.

Any ideas?

iwanders commented 9 years ago

Thanks for getting back to me, I tried the MinimalInterrupt example on an Arduino UNO I had laying around. I encountered a few problems, here's what I encountered and what I did to fix them.

First of all, one problem is that I included WProgram.h and the Arduino IDE doesn't know that anymore since version 1.0 (I used arduino-1.6.5-r2). I had to change this to Arduino.h to get it to compile.

Secondly, on the Teensy 3.x a the pin number is also the number you have to pass to the attachInterrupt(...) function. However, on the Arduino this is not the case, you have a pin number and with that pin number (if it has interrupt capability) comes a seperate (different) interrupt number.

With these changes in place I successfully received data using an Arduino UNO. I have added a new example (and changed the header file) in ed13a033581db5aaab48907090e2e0444734a8d8. The MinimalInterruptUno example is what I actually used during testing.

One other thing I noticed which might cause problems: it did not work without the reset pin connected. I'm not sure why, as the radio should have the same register values after a reset or power on. So if it still does not work, also solder a wire to this pin.

I look forward to hearing your results with these changes.

bloever commented 9 years ago

Hello again.

I succesfully got it to work tonight. Seems like the real trick was the reset cable. I had to solder a wire there as well. Without it things just don't work.

Regarding the pins. It would seem that it's not needed to configure the pin as INPUT on Arduino. Looks like they are INPUT by default (https://www.arduino.cc/en/Tutorial/DigitalPins). I tried uncommenting the pinMode line and it makes no difference.

A strange thing I experienced was that it would make no visible difference (The minimalInterrupt example would run just fine) if I specified either interrupt 0 or 1. (The MoteinoR4 has two. INT0 (D2) and INT1 (D3). Any idea why it would work regardless of which interrupt specified?

I also did some testing with AES encryption. You might already know this but I was unable to get it to work unless I specified all the settings before rfm.setPacketType(); and also putting the RFM69 in standby first.

I used the following code to test AES encryption:

rfm.setRecommended(); // set recommended paramters in RFM69.

// Enable encryption
rfm.setMode(RFM69_MODE_STANDBY);
char* buf = { "sampleEncryptKey" };
rfm.setAesKey(buf, 16);
rfm.setAES(true);

rfm.setPacketType(false, false); // set the used packet type.

Thanks for your time looking into this.

iwanders commented 9 years ago

I'm not sure why the reset wire is required, the radio's register values should be the same as with power on reset.

Regarding the pins, on the Arduino they might be configured as INPUT by default, but that's not the case with all boards. Some boards initialize with the pins in a disabled state. Either of the two interrupts on the Moteino should work, but anything that calls the .poll() method frequent enough or at the right time should work.

You are right that the setup / initialization is order dependent, the setAES method only stores a boolean, which is read by the setPacketType method when the registers on the radio are set plainRFM69.cpp#L69. So be careful with the order and if in doubt check in plainRFM whether a method requires other values to be set already.

Good to hear that it's working now.