MySensors, RFM69 and ATTiny841

I want to design a wireless light switch that works for years without charging and doesn’t require mains connection and provides complete flexibility over the set of devices it controls. The actual switching would happen through relays in the home electricity distribution board.

The MySensors project provides software libraries for sensors and gateways that integrate well with the Home Assistant automation platform which in turn works with the Apple Home. It supports all of the popular wireless radios such as RFM69, NRF24L01+ and ESP8266 attached to most of the popular microcontrollers such as Atmel AVR, STM32 and the BCM in Raspberry Pi.

The Prototype

So I designed a single device that could be used both as a standalone sensor/switch transmitter and as a receiver when attached to the Raspberry Pi. Here is the very first prototype PCB with just the required wiring (and no passives) for connecting the radio module to both the Raspberry Pi and the ATTiny841 microcontroller via the SPI bus:

RFM69CW Radio Connected to ATTiny841 and Raspberry Pi via SPI

First prototype of the sensor module with RFM69CW radio connected to both ATTiny841 and Raspberry Pi via SPI

It was a nice surprise when the MySensors gateway on Raspberry Pi could detect the RFM69CW radio module right away.

Reset Trouble

The next step was to get the ATTiny841 talking to the RFM69CW radio and that took me days because it would just fail uploading the firmware as soon as I soldered the radio to the PCB. Turns out the reset pins of both ATTiny841 and RFM69CW were connected which caused the radio module to toggle the MISO and MOSI lines and interfere with the programming. Cutting the reset line to the radio fixed the issue ?.

ATTiny841 External Interrupt

Using the ATTinyCore Arduino core from Spence Konde and the RFM69 library from Felix Rusu I was able to successfully communicate with the RFM69CW radio. An important thing to note is that ATTinyCore only supports pin PB1 of ATTiny841 as the Arduino external interrupt pin so D100 on RFM69 must be connected to PB1 for it to initialize the radio and register the incoming data.

MySensors and RFM69

There are dozens of ways to configure the RFM69 radio so it is important that both the transmitter and receiver use the same data encoding and encryption. At first the MySensors gateway on Raspberry Pi wouldn’t pick up any radio transmission from the ATTiny841 sensor so I spent hours finding differences in the register setup for MySensors and the RFM69 library.

Here are the changes necessary to the RFM69 library for it to talk to the MySensors on Raspberry Pi. Note that the MySensors radio packets include two additional bytes in the packet header for the packet “version” and the “sequence number”.

Finally, everything works ?

ATTiny841 Sending Temperature Data to MySensors on Raspberry Pi via RFM69CW

Next Steps

The prototype module is now transmitting the internal RFM69 temperature data to another module attached to the Raspberry Pi and running the MySensors gateway. In the next few weeks I plan to publish the Arduino sketch and work on the updated PCB.

Leave a Reply