Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Circuitpython RFM69 Gateway
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Circuitpython RFM69 Gateway

by smccamy1 on Fri Aug 07, 2020 4:56 pm

Hello,

I wanted to see if anyone has any comments on using the circuitpython rfm69 library as a gateway to read sensor data from several nodes? I have been using RFM69 radios for home automation sensors for while (Moteinos) but I am much better at coding in Python and want to do some of my new projects in Circuitpython. It looks like the rfm69 library is not compatible with the lowpowerlabs library I have been using and I will need to setup a new gateway. My setup would be around 20 nodes sending sensor data periodically or things like motion, doors, etc. I will just migrate everything over to the Radiohead library.

I purchased the rfm69 pi bonnet and that seems like a logical choice, but I read that the rfm69 library does not support interrupts. I could probably code the gateway using the arduino library from Radiohead but I prefer to use the circuitpython one.

I will probably just try it either way but, just wanted to see if anyone had tried something like this out and had any suggestions.

Thanks for any input.

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by jerryn on Fri Aug 07, 2020 5:32 pm

The CIrcuitPython rfm69 library does support multiple node addressing via the RadioHead compatible header.

jerryn
 
Posts: 1299
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython RFM69 Gateway

by smccamy1 on Sat Aug 08, 2020 3:15 pm

Thanks, yeah after messing around with the RadioHead and rfm69 Circuit Python libraries I think everything will work fine.

For some reason the rfm69 bonnet is getting terrible reception. I have the right size antenna on it and I tried on it a pi 4 and zero with similar results. I just used a feather M0 connected to the pi as a gateway for now. Not sure what's up with the bonnet. Bonnet starts dropping at about 50 feet with normal interior obstructions vs no dropping using the feather.

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by jerryn on Sat Aug 08, 2020 4:20 pm

Glad to hear it may be usable for you. I have not done any range testing of the RFM69 bonnet myself. I've mostly been using LoRa/RFM9x and have had decent results with the bonnet.

I hope do do some work on the RFM69 library to implement a few code-size reductions and to enable it to be "frozen" into the feather_m0_rfm69 build like the current work on the rfm9x https://github.com/adafruit/circuitpython/pull/3251

When I get to that, I'll try some range tests with a bonnet as well.

Are you just using a straight wire?

jerryn
 
Posts: 1299
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython RFM69 Gateway

by smccamy1 on Sat Aug 08, 2020 7:36 pm

Yeah, just a straight wire. I have an rfm69 breakout board I will hook up to the pi to compare and see if its any better.

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by smccamy1 on Sat Aug 08, 2020 8:29 pm

Derp, I soldered the antenna to one of the pads that hold the uFL connector. Has normal range now!

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by jerryn on Sat Aug 08, 2020 8:39 pm

Great news! Good luck with your projects.

jerryn
 
Posts: 1299
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython RFM69 Gateway

by smccamy1 on Mon Aug 10, 2020 11:45 am

So, trying to get ReliableDatagram working across Arduino/Circuitpython. I have a Feather M0 RFM69 running the Adafruit RadioHead Arduino library and another Feather M0 RFM69 running circuitpython. Should this work with acks? I just want to make sure its possible before I keep trying.

I am seeing packets from the circuitpython node to the arduino node but receive no ack.

Code: Select all | TOGGLE FULL SIZE
 if (rf69_manager.recvfromAck(buf, &len, &from)) {
      buf[len] = 0; // zero out remaining string
      Serial.print("Got packet from #"); Serial.print(from);


Code: Select all | TOGGLE FULL SIZE
while True:
    if not rfm69.send_with_ack(bytes("Hello","UTF-8")):
        print("no ack")


EDIT:

I am reading this as it can work but with limitations. I will keep messing with it but any help is appreciated.

Advanced RadioHead features like
address/node specific packets or "reliable datagram" delivery are supported however due to the
limitations noted, "reliable datagram" is still subject to missed packets but with it, the
sender is notified if a packe has potentially been missed.

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by jerryn on Mon Aug 10, 2020 9:34 pm

I have had problems sending from CircuitPython to Arduino (Radiohead). The problem is that the Radiohead code Acks too fast for the CircuitPython code to be able to receive the Ack. In the CP code I added an attribute ack_delay, to offer some control but the RadioHead code does not have such an attribute.

I hade some better success with some of the faster MCUs but I’m not sure what to do about it.

I suppose I could see if RadioHead would accept a change....

jerryn
 
Posts: 1299
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython RFM69 Gateway

by smccamy1 on Mon Aug 10, 2020 11:20 pm

That makes sense. Its not a big deal to just have a separate gateway for the arduino stuff. Any experience running circuitpython rfm69/9x nodes on battery for a long time? I have not checked yet but I think the feather m0 is going to burn a lot of juice compared to what I am used to. I noticed the itsyBitsy M0 and it seems pretty barebones and a possible candidate. Really liking the library and thanks for all your hard work on it!

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by jerryn on Tue Aug 11, 2020 7:21 am

Sorry. I have not done much testing of battery life. There has been a lot of work done recently to try to reduce the power usage with Circuitpython, but I have not tested it with the radios boards...yet. Please share any results you have.

If you are looking to move from the feather_m0_rfm69 to the itsybitsy_m0 ( I assume with the rfm69 breakout) you may want to consider the itsybity_m4_express. I don't know if the power is a deal breaker but the increase in resources on the M4 is huge when working with CircuitPython. You will be very constrained on an M0.

jerryn
 
Posts: 1299
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython RFM69 Gateway

by smccamy1 on Wed Aug 12, 2020 3:41 pm

So, started diving in on the battery stuff.

I have a Moteino M0 on the way to see if I can load CircuitPython on it. The hardware is well suited for lowpower but not sure any of the builds will work with it yet. I want to give it a try because it has an RFM69 on it, so no breakout.

Another potential option I already own is the Tinypico. Its an esp32 based board so no CircuitPython support but it is setup for very low power consumption and has Micropython on it. I started diving into the library to see if I can port it over to MP to work with this board and will try. I am stuck though. I can't for the life of me read the registers right on a chip regardless of what board I am using. I back tracked and figured I would try and just read them off of a Feather M0 using the CircuitPython code and I still can't get it to provide the expected result. I stripped down the code to just connect to SPI and write/read from the chip. Do you see anything wrong with this? If I can get over this hurdle I may try to build compatibility with the lowpowerlabs rfm69 library as well. Thanks

Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio
import adafruit_bus_device.spi_device as spidev
import time


_BUFFER=bytearray(4)
_REG_VERSION = const(0x10)

CS = digitalio.DigitalInOut(board.D5)
RESET = digitalio.DigitalInOut(board.D6)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
device = spidev.SPIDevice(spi, CS, baudrate=5000000, polarity=0, phase=0)

address = _REG_VERSION

RESET.switch_to_output(value=False)

RESET.value = True
time.sleep(0.0001)  # 100 us
RESET.value = False
time.sleep(0.005)  # 5 ms

_BUFFER[0] = address & 0x7F

with device:
    spi.write(_BUFFER, end=1)
    spi.readinto(_BUFFER, end=1)
print(_BUFFER[0])

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by jerryn on Wed Aug 12, 2020 4:11 pm

I made one change to add an import of "const" and ran this on a Raspberry Pi with an RFM69 Bonnet -- seems to work OK
Edited to add -- I also ran this on a feather_m4_express with rfm69 feather wing

Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio
import adafruit_bus_device.spi_device as spidev
import time
from micropython import const

_BUFFER=bytearray(4)
_REG_VERSION = const(0x10)

CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
device = spidev.SPIDevice(spi, CS, baudrate=5000000, polarity=0, phase=0)

address = _REG_VERSION

RESET.switch_to_output(value=False)

RESET.value = True
time.sleep(0.0001)  # 100 us
RESET.value = False
time.sleep(0.005)  # 5 ms

_BUFFER[0] = address & 0x7F

with device:
    spi.write(_BUFFER, end=1)
    spi.readinto(_BUFFER, end=1)
print(_BUFFER[0])




36 is the expected value 0x24

Code: Select all | TOGGLE FULL SIZE
pi@gjnpirfm69:~/projects/blinka $ python3 rfm69_reg.py
36



same code on feather_m4_express (different file name -- oops)
Code: Select all | TOGGLE FULL SIZE
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 6.0.0-alpha.2-216-gbbac68e77 on 2020-08-11; Adafruit Feather M4 Express with samd51j19
>>> import read_reg
36
>>>


jerryn
 
Posts: 1299
Joined: Sat Sep 14, 2013 9:05 am

Re: Circuitpython RFM69 Gateway

by smccamy1 on Wed Aug 12, 2020 4:34 pm

Ah, I had the wrong pin assignment. Thanks for testing!

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Re: Circuitpython RFM69 Gateway

by smccamy1 on Sun Aug 23, 2020 12:03 am

jerryn wrote:Sorry. I have not done much testing of battery life. There has been a lot of work done recently to try to reduce the power usage with Circuitpython, but I have not tested it with the radios boards...yet. Please share any results you have.

If you are looking to move from the feather_m0_rfm69 to the itsybitsy_m0 ( I assume with the rfm69 breakout) you may want to consider the itsybity_m4_express. I don't know if the power is a deal breaker but the increase in resources on the M4 is huge when working with CircuitPython. You will be very constrained on an M0.


Wanted to provide an update on this. From what I can tell, there are no native low power options yet for circuitpython except maybe the ESP32-S2. Someone did write a module to sleep the Itsy Bitsy m0 which I may test out to see what it gets down too. https://github.com/BitKnitting/wakey_circuitpython/wiki

The best option for low power with MP seems to be the esp32 and I have found a few dev boards that only consume ~9 micro amps in deep sleep. The wifi works fast and well but it eats a lot of power compared the radio modules. I was able to get the rfm9x library working 100% with MP and got very close with rfm69 (can send packets fine but when reading the FIFO on receive it does not get the header values). The rfm9x library seems to be working very well between a feather and a breakout board. The few test I did I didn't miss a single ack, so I may just go with that line of radio modules.

I also imagine there are going to be some low power options in the esp32-s2 that can run circuitpython in the next x months or so.

Very excited to get this working as I really want to be able to code all of my battery sensors and projects in python. Should be able to get some really good battery life. Example water leak sensors that last over a year or so before recharge.

smccamy1
 
Posts: 21
Joined: Tue May 17, 2016 8:57 pm

Please be positive and constructive with your questions and comments.