🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Trying to get this LoRa Module working on Core2

    Modules
    2
    4
    133
    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.
    • H
      HappyUser
      last edited by HappyUser

      /*
      After some further trial and error and comparison of what works and what not works.
      In this piece of code :

         auto cfg = M5.config();
      
      
      cfg.serial_baudrate = 115200;
      cfg.output_power = true;
      
      M5.begin(cfg);
      M5.Power.begin();
      M5.Display.startWrite();
      
      

      The problem starts with M5.Display.startWrite(); If we remove that one, LoRa.begin(LORA_FREQ)) works fine.
      So I assume that there is some kind of SPI conflict.
      Then the next question is : i need to keep both the startwrite because i use M5Unified and I wnat to connect to the Lora module.

      Is this info a better pointer to find a solution?
      Thanks

      */

      Hi,
      We are trying to get this LoRa module : ```
      https://docs.m5stack.com/en/module/lora868

      working in a M5Core2. We realize that this module is no longer supported. But we have a lot of them operational in the field, and for several reasons we need to upgrade from M5Stack the grey on to M5Core2.
      I have included our testing code. We are using the M5_SX127X.h which works great with the M5Stack grey one.
      We also updated the pins to the Core2 (when the LoRa module is stcked on the Core 2.
      This piece of code tells us that SPI is started:
      
      if (SPI.begin(LORA_SCLK, LORA_MISO, LORA_MOSI,-1))  // SCK, MISO, MOSI, SS
       { Serial.println("Fine");} else {Serial.println("Not fine");}
      
      We are not sure about this one : LoRa.setSPIFrequency(300000); // Not sure , we tried different values
      also left this out, to no avail.
      
      The software hangs inside this call LoRa.begin(LORA_FREQ) , which looks like the SPI transmission with the LoRa device hangs. But we have no idea. Double checked the pin assignments, we beleive they are correct.
      
      Anyone a suggestion how to get this LoRa module working on an M5Core2?
      Thanks
      
      
      However, 
      

      #include <arduino.h>
      #include <M5Unified.h>
      #include <SPI.h>
      #include "M5_SX127X.h"

      #include <Wire.h> //The DHT12 uses I2C comunication.
      #include <WiFi.h>
      #include <WiFiClient.h>

      #include <WiFiMulti.h>
      #include <HTTPClient.h>

      #include <EEPROM.h>

      #define EEPROM_SIZE 1

      #include <OneWire.h>
      #include <DallasTemperature.h>
      #define ONE_WIRE_BUS GPIO_NUM_26 //9
      OneWire oneWire(ONE_WIRE_BUS);
      DallasTemperature sensors(&oneWire);

      // Module Connect Pins Config
      // Core
      /*
      #define CS_PIN 5
      #define RST_PIN 26 //13
      #define IRQ_PIN 36 //34

      #define LORA_MISO 19
      #define LORA_MOSI 23
      #define LORA_SCLK 18
      */
      // Core2
      #define CS_PIN 33 //5
      #define RST_PIN 25 //26 //13
      #define IRQ_PIN 36 //36 //36 //34

      #define LORA_MISO 38 //19
      #define LORA_MOSI 23 //23
      #define LORA_SCLK 18 //18

      // LoRa Parameters Config
      // #define LORA_FREQ 433E6
      #define LORA_FREQ 868E6
      #define LORA_SF 12
      #define LORA_BW 125E3
      #define LORA_TX_POWER 17

      /*
      // Module Connect Pins Config
      #define CS_PIN 5
      #define RST_PIN 13
      #define IRQ_PIN 34

      #define LORA_MISO 19
      #define LORA_MOSI 23
      #define LORA_SCLK 18

      // LoRa Parameters Config
      // #define LORA_FREQ 433E6
      #define LORA_FREQ 868E6
      #define LORA_SF 12
      #define LORA_BW 125E3
      #define LORA_TX_POWER 17
      */

      //**************************** LoRa

      int packetSize;

      int LoRa_Pulse_Count_Max=0; // Om de WindGust te bepalen
      int LoRa_Counter_Cumm=0;
      int LoRa_Windspeed_Counter=0;
      float LoRa_Windspeed_Avg=0;

      float LoRa_Outside_Temperature;
      int LoRa_Pulse_Count;
      float LoRa_Wind_Speed;
      float LoRa_WindGust;

      const int LoRa_Pulse_Array_size= 400; // inschatting
      int LoRa_Pulse_Array[LoRa_Pulse_Array_size];

      const long Ten_Minutes=600000;
      long Next_Ten_Minutes;

      typedef struct {
      int SecretCode;
      int Pulse_Count;
      int CallCounter;
      //float Current;
      //float Voltage;
      float tempC;

      } LoRa_Receive_struct;
      LoRa_Receive_struct LoRa_Receive_Data;

      //***************************** End of LoRa

      void setup() {
      Serial.begin(115200);
      //pinMode(CS_PIN,OUTPUT);
      //pinMode(RST_PIN,OUTPUT);
      Serial.println("LoRa Receiver");
      if (SPI.begin(LORA_SCLK, LORA_MISO, LORA_MOSI,-1)) // SCK, MISO, MOSI, SS
      { Serial.println("Fine");} else {Serial.println("Not fine");}
      LoRa.setSPI(&SPI);
      LoRa.setPins(CS_PIN, RST_PIN, IRQ_PIN); // set CS, reset, IRQ pin
      LoRa.setSPIFrequency(300000); // Not sure , we tried different values
      while (!LoRa.begin(LORA_FREQ)) {
      Serial.println("LoRa init fail.");
      delay(1000);
      }
      Serial.println("Seems okay");

      //LoRa.setTxPower(LORA_TX_POWER);
      //LoRa.setSignalBandwidth(LORA_BW);
      //LoRa.setSpreadingFactor(LORA_SF);
      

      }

      void loop() {
      // try to parse packet
      int packetSize = LoRa.parsePacket();
      if (packetSize) {
      // received a packet
      Serial.print("Received packet '");
      LoRa.readBytes((uint8_t *)&LoRa_Receive_Data, packetSize);
      if (LoRa_Receive_Data.SecretCode==5498)
      {

               Serial.print("LoRa :");
               Serial.print(LoRa_Receive_Data.tempC);
               Serial.print("  |  ");
               Serial.println(LoRa_Receive_Data.Pulse_Count);
            }
      

      /*
      // read packet
      while (LoRa.available()) {
      Serial.print((char)LoRa.read());
      }
      */
      // print RSSI of packet
      Serial.print("with RSSI ");
      Serial.println(LoRa.packetRssi());
      }
      }

      felmueF 1 Reply Last reply Reply Quote 0
      • felmueF
        felmue @HappyUser
        last edited by

        Hello @HappyUser

        I think you are missing the M5.begin() in setup(). Without that call, the 5 V isn't turned on, e.g. the LoRa module is not powered. (At least on my M5Core2 5 V is not present without the M5.begin() call.)

        And I think the RST_PIN should be GPIO 26 (as it hasn't changed from M5Core to M5Core2).

        Note: I do not have this LoRa module so I cannot test myself.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        H 1 Reply Last reply Reply Quote 0
        • H
          HappyUser @felmue
          last edited by

          @felmue Thank you.
          Pins are assigned correctly. Double checked.
          Not shown but this piece of code

             auto cfg = M5.config();
          
          
          cfg.serial_baudrate = 115200;
          cfg.output_power = true;
          cfg.led_brightness=180;
          M5.begin(cfg);
          M5.Power.begin();```
          
          Handles the power.
          Tested out : if we remove M5.Display.startWrite(); then Lora.begin works great. However, we need to startup the display also.
          So, I strongly beleive there is some interference with SPI and startWrite(). No idea how.
          Regards 
          
          Regards
          felmueF 1 Reply Last reply Reply Quote 0
          • felmueF
            felmue @HappyUser
            last edited by

            Hello @HappyUser

            you do not need to explicitly call M5.Power.begin() as it is already called from within M5.begin().

            Well, as soon as you call M5.Display.startWrite() it will assert the display CS line and occupy the SPI bus for the display until you call M5.Display.endWrite(). In other words, between those two calls the SPI bus can only be used for display updates.

            Question: why are you calling M5.Display.startWrite() explicitly at all? You should be able to write onto the display by calling M5.Display.println() or similar without first calling M5.Display.startWrite(). Doesn't that work for you?

            Thanks
            Felix

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            1 Reply Last reply Reply Quote 0
            • First post
              Last post