Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    LoRa communication lopy - rfm9x

    Scheduled Pinned Locked Moved LoPy
    lopy4rfm95lora
    9 Posts 4 Posters 821 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      melkoutch
      last edited by

      Hi,

      I'm using an "Adafruit RFM95W" (with a raspberry pi 3) and a lopy4. I want to send packets between them but it doesn't work.

      Here's the code I used on the lopy :

      from network import LoRa
      import socket
      import machine
      import time
      
      lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868,frequency=868000000)
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      
      while True:
      
           s.setblocking(True)
           s.send('Hello world !!')
           print("hello")
           time.sleep(5)
      
      

      And that's the rfm9x code :

      import board
      import busio
      import dogotalio
      import time
      import adafruit_rfm9x
      from digitalio import DigitalInOut, Direction
      
      CS = digitalio.DigitalInOut(board.D22)
      RESET = digitalio.DigitalInOut(board.D27)
      spi = busio.I2C(board.SCL,board.SDA)
      
      rfm9x = adafruit_rfm9x.RFM9X(spi,CS,RESET,868)
      while True :
          packet = rfm9x.receive()
          if packet is None :
              print("Listening again ...")
          else :
              print("Received : {0}".format(packet)) 
      

      It's really a simple hello world packet exchange in LoRa. After a random amount of time, the rfm9x finally received something which is unreadable and goes back to not receiving anything.

      I am in Europe so I'm using 868MHz on both devices and I checked the antenna connector.
      I tried to modify the parameters (spreading factor, coding rate, etc) but it doesn't change anything.

      For information, I posted a similar question but with a different technology : here

      Have anyone managed to get a lopy communicate with an rfm9x board ?

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @melkoutch
        last edited by robert-hh

        @melkoutch No clue why it does not work. This is similar to the simple LoPy-Lopy ping-pong example from the docs and library, which I tested now again between two LoPy4 devices, AND IT FAILS. It used to work.
        Edit 1: There is a RF transmission, but no data received.
        Edit 2: Just taking the example without setting the frequency works. The default is 868Mhz It has to be noted that when changing the parameters a HARD reset is required.
        Edit 3: Again tested, works now also with changed frequency ar 863MHz. One thing I did was to mis-align the antennas, because devices are very close on my desk. With one antenna vertical, and the other horizontal I have an rssi of about -50 dB, which is fine.

        M 1 Reply Last reply Reply Quote 0
        • M Offline
          melkoutch @robert-hh
          last edited by

          @robert-hh Thanks for trying. I removed the frequency from parameters and tried to ajust te antenna but no changes.

          Just for information, I posted the same question on the adafruit forum if anyone wants to check it out. I posted example of the output I got (which is weird).

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @melkoutch
            last edited by

            @melkoutch I still feel uncomfortable about it, since the test failed initially, and worked later on when returning to the initial set-up. So it still has the smell of a non-initialized-variable bug somewhere.

            1 Reply Last reply Reply Quote 0
            • E Offline
              Eric73
              last edited by

              Hi, i have a look at lora source code from pycom and adafruit( https://github.com/adafruit/Adafruit_CircuitPython_RFM9x/blob/master/adafruit_rfm9x.py ) , i'm don't very familiar with their coding style but in my humble opinion adafruit lib they don't do all init stuff for the lora chip (sx1276), and worst they doesn't allow fine grained frequency selection.

              In particular for your usage, they don't set a value for lora sync word, so sx1276 use it's reset value 0x12 (private lora), but it's seem that pycom init value is 0x34 (public lora aka lorawan).
              I suggest you to test on your pycom device with

              lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868,frequency=868000000,public=False)
              
              M 1 Reply Last reply Reply Quote 3
              • P Offline
                pkilcoyne
                last edited by

                @melkoutch I had a post similar to yours, I was able to rx data on the LoPy but it seemed to be in HEX, anyway my code might be of interest to you;

                https://forum.pycom.io/topic/4920/lopy-bytes-data-received-in-hex-convert-to-original-text

                Paul

                1 Reply Last reply Reply Quote 1
                • M Offline
                  melkoutch @Eric73
                  last edited by melkoutch

                  @Eric73 It worked !

                  However, it works fine when sending packets from lopy to rfm9x but when lopy is waiting for packets it receives the following :

                  b'\xff\xff\x00\x00ABC TEST !!!'
                  

                  (The packet sent was ABC TEST !!!)

                  I can always erase the first bytes but I hope this is just another parameter to change, if anybody has an idea ?

                  E 1 Reply Last reply Reply Quote 0
                  • E Offline
                    Eric73 @melkoutch
                    last edited by

                    @melkoutch Well, this is not a radio (sx127x) effect. If you look at adafruit lib (link in my previous post) it seem that this lib insert a 4 bytes header (line 649) before send a packet and line 697 you can se that you have to set with_header=False when you call rfm9x receive function to remove this 4 bytes header from your received data.

                    It seem there no similar way for send function so header will be always send by rfm9x library.
                    0xFF 0xFF 0x00 0x00 is broadcast header for RadioHead library, i suggest you to find and read this library specification if you plan to use it.

                    M 1 Reply Last reply Reply Quote 2
                    • M Offline
                      melkoutch @Eric73
                      last edited by

                      @Eric73 Great, thanks for your help !

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom