Project

General

Profile

Resolved: Using RFM69CW with ATTiny84 for Tx AND Rx

Added by sanb about 1 year ago

Hi,

You might remember me from about 3 years ago when you all helped me (thanks!) in interfacing RFM69CW with ATTiny84 on a remote unit sending packets received by another RFM69CW on an Ardunio UNO. That system has been up and running flawlessly for the past 3 years. The ATT84/RFM69CW combo is programmed for only Tx. UNO/RFM69CW is programmed for only Rx.

The majority of my time for the past 3 years were devoted to getting my daughter from 0 to 3 yr of age :-).

I am now getting back to this kind of activity with a bit more ambition. I am now trying to build a remote controller for the sprinkler valve with a DC latching solenoid. I am thinking of this project as having "three sub-systems":

Sub-System 1: L9110S driver drive the DC latching solenoid. This works (after some issues with current load etc.). The 6V, 10ms pulse (with opposite polarity for ON and OFF) uses a 6xAA battery pack.
Sub-System 2: Command the L9110S from a MCU. I tested it first with UNO (worked) and then with a stand-alone ATTiny84 (that worked too).
Sub-System 3: Receive the ON/OFF command via a RFM69CW connected to the ATTiny84, which then commands the L9110S to turn the sprinkler valve.

Questions below are about interfacing ATTiny84 with RFM69CW and program the combo for both Rx and Tx (Sub-System 3 (SS3)).

Question 1: How should the ATTiny84 and RFM69CW be connected such that RFM69CW can be read by ATT84 when commands arrive and transmit some data back via RFM96CW?

                       For the remote nodes I am using right now, I have the following connections:

                                      ATT84             RFM69CW
                                         D1                      NSS
                                         D2                      DI00
                                   MOSI, D4              MISO
                                   MISO, D5              MOSI
                                   SCK, D6                 SCK

                         Will these same connection also work when ATT84 is programmed for both Rx and Tx?

Question 2: Will the same calls in the skectch that works for Rx currently on UNO/RFM69CW combo also work with ATT84/RFM69CW combo?

The UNO/RFM69CW combo that is working now for Rx can, I think, be easily modified for also Tx. I also plan to use that set up for testing.

I am aware that it might get tricky to pack everything in ATT84 memory, but I am hoping that since the Tx alone does work on ATT84, I will be able to pack the Rx, Tx code as well. My code on top of the RFM69CW library will be tiny.

Additional info.:

As a test, I put together a sketch which is pretty close to what I need for programming ATT84 for Rx-Tx using the RFM69CW module. All of the following calls to the JeeLib are in the sketch:

          rf12_initialize(), rf12_sleep(), rf12_canSend(), rf12_recvDone(), rf12_sendStart(), rf12_sendWait(), rf12_recvDone()

and the ArduinoIDE, when using the Board "ATtiny84 @8MHz (internal oscillator; BOD disabled" gives the following info:

          Sketch uses 4596 bytes (56%) of program storage space. Maximum is 8192 bytes.
          Global variables use 150 bytes (29%) of dynamic memory, leaving 362 bytes for local variables. Maximum is 512 bytes.

This looks hopeful to me.

Question 3: Am I correct in assuming that the RxTx sketch would fit in the ATT84 memory and 362 bytes would be sufficient for the stack (dynamic)?


Replies (5)

RE: Using RFM69CW with ATTiny84 for Tx AND Rx - Added by sanb 12 months ago

FYI just to close the loop here - I managed to answer my questions and make progress. (in retrospect, some of the questions were silly). I now have a working remote node (using the TinyTx design) the ATTiny84 on which has been successfully programmed for both Tx (send the sensor data in my case) and Rx (receive commands to control the L9110S).

The remote node has a RFM69CW connected to an ATTiny84. The sketch that works on the ATTiny84 takes about 60% of 8K memory and leaves a 352 bytes for local variables when linked with the JeeLib. I will shortly cleanup the code and post it on GitHub if anyone else is interested.

The node runs on 2xAA batteries and my current estimate is that the battery should last for at least an year or so.

Answering my own questions below:

sanb wrote:

Questions below are about interfacing ATTiny84 with RFM69CW and program the combo for both Rx and Tx (Sub-System 3 (SS3)).

Question 1: How should the ATTiny84 and RFM69CW be connected such that RFM69CW can be read by ATT84 when commands arrive and transmit some data back via RFM96CW?

                       For the remote nodes I am using right now, I have the following connections:

                                      ATT84              RFM69CW
                                       D1                  NSS
                                       D2                  DI00
                                   MOSI, D4                MISO
                                   MISO, D5                MOSI
                                   SCK, D6                 SCK

                         Will these same connection also work when ATT84 is programmed for both Rx and Tx?

The answer (obvious now) is yes. The same connections work for both Rx and Tx.

Question 2: Will the same calls in the skectch that works for Rx currently on UNO/RFM69CW combo also work with ATT84/RFM69CW combo?

Yes. The same calls work, but need some timing tuning. My sketch works only if I insert 100ms delay between switching RFM69 between Tx and Rx. Delay is probably somewhere between 10ms (which does not work) and 100ms.

Question 3: Am I correct in assuming that the RxTx sketch would fit in the ATT84 memory and 362 bytes would be sufficient for the stack (dynamic)?

The single data point I have on this is that with 60% utilization of the program storage space with 352 bytes left for dynamic memory works on ATTiny84.

RE: Resolved: Using RFM69CW with ATTiny84 for Tx AND Rx - Added by martynj 11 months ago

@sanb,

Yes - please post your code, I'm interested in why the delay is needed when switch from Tx to Rx mode.

RE: Resolved: Using RFM69CW with ATTiny84 for Tx AND Rx - Added by sanb 11 months ago

martynj
Thanks for offering to have a peek in my code to see if the 100ms delays currently in the code are really necessary.

Even if some delays are required (for whatever reason), using the minimum delay would be good (and if >10ms, converting
delay() to loseSomeTime()).

Here is the code: https://github.com/sanbee/Naarad/blob/FullCmdTO/Nodes/TinyL9110S/RFM69_RxTx/RFM69_RxTx.ino

The delays (of 100ms) in question are at line nos. 147 and 169. The logic in the code (and hence also the timing) is admittedly more complicated
than it ought to be, I think. The attempt is the following:

The sketch sends out a packet with sensor values every 60sec. 100ms after finishing sending, it switches RFM69 to Rx with a timeout of
3sec. A packet received in this Rx window is processed to see if (a) it was meant for this node (ID=15 sent in payLoad.supplyV), and (b) if
the sender was the server node (currently ID=5). If a valid packet was received, it is procssed and the RFM69 put to sleep. ATT84 goes to
low-power sleep for 60sec.

The Base Station code (on UNO) treats any packet from ID=15 as a ping and responds with either a command packet, if there is one from RPi in
its cache, or a self-generated command packet with the NOOP command. This ensures that the remote radio is in the Rx mode for the shortest
required time.

RE: Resolved: Using RFM69CW with ATTiny84 for Tx AND Rx - Added by sanb 10 months ago

martynj:

Inspired by your question (to paraphrase, "why are the delays in your sketch required?"), I cleaned up the code, and hence the logic. And find that the delays are indeed not required. The FullCmdTO branch on GitHub has been updated with the code that I am now using (the most important clean-up is in the function readRFM69() in file unoserver2.ino, in case you want to review it). I also now understand better why the delays were required earlier (it was due to more complexity than required in my code).

The code on the ATTiny84s on the remote nodes still has delays, but I think they also won't be required once I reprogram them too (soon).

Thanks. And apologies if you spent cycles looking at my earlier code.

RE: Resolved: Using RFM69CW with ATTiny84 for Tx AND Rx - Added by martynj 10 months ago

@sanb,

No problem - the new code looks much cleaner. Glad you are making progress.

    (1-5/5)