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());
}
}