sendWithRetry on ATTiny84

Started by amadeuspzs, November 16, 2020, 04:08:53 PM

amadeuspzs

Hello,

First up, I know ATTiny84 is not a supported chip to drive an RFM69, but I also know a few people are using them so here's hoping you may be able to help!

I've got a very simple use case: sensing whether a door is open or not via a reed switch. The sensor will be battery powered and run off an ATTiny84. The gateway is running on a Raspberry Pi and proxying requests via MQTT to Home Assistant.

I have the test Arduino send sketch working beautifully on an ATMega32U4, but the same sketch on the ATTiny84 with a modified RFM69 library is sending OK but not managing to receive any ACKs and is therefore (sometimes) sending multiple packets at once, which all get received.

Has anyone else come across this? I've tried increasing the memory available in case it's a memory issue but still no ACKs:

Debug via (software)serial:


Sketch uses 5914 bytes (72%) of program storage space. Maximum is 8192 bytes.
Global variables use 229 bytes (44%) of dynamic memory, leaving 283 bytes for local variables. Maximum is 512 bytes.


No debug:

Sketch uses 5332 bytes (65%) of program storage space. Maximum is 8192 bytes.
Global variables use 157 bytes (30%) of dynamic memory, leaving 355 bytes for local variables. Maximum is 512 bytes.


No ATC, no debug:

Sketch uses 4284 bytes (52%) 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.


I've trawled through the code as far as I can in one evening and can't see anything obvious. Even with a retryWaitTime of 255 (max) I'm not getting ACKs - is 8MHz too slow to do all of this?

If the answer is "don't use an ATTiny84" can anyone recommend an upgraded AVR chip that I can hand solder? I'm looking to make my own PCBs with this design when done and can't conceive of soldering the 32U4... I will find an ATMega328P to try next.

Cheers,

A

Felix

The real problem with attiny chips is they are .... tiny, in every respect. Maybe good to drive some christmas lights and impress grandma, but really ... they are completely impractical for more serious stuff.
I do still use attiny chips, most notably in the ATXRaspi board. But I'm looking forward to something better.
While I appreciate the cool factor of cramming everything into these tiny chips, because it's possible, and deal with flipping bits and allocating every byte of memory instead of using a proper library for doing anything more than blinking LEDs, IMO it's an art that should only be kept for reference in museums. In real practice you will run out of memory so fast that the 50cents saved is not exactly worth the effort. That is why I'm not excited about attiny, and also do not have the time to support attiny.

So yes please do yourself a favor and get a more common AVR like the atmega328 or 1284p both of which are supported by the library. It will save you a lot of time and this life is pretty short :'(

amadeuspzs

Thanks Felix.

While preparing to switch to an ATMega328P, I noticed that I was using PCINT0 on the ATTiny for IRQ, instead of INT0.

Switching to use INT0 now works!

So, again, minimal changes required but I'm getting really good ACKs at a distance from the other module.

I'll probably run into issues with sleep mode, interrupts and wake up, but sharing in case others find it useful.