LiLigo ESP32 OLED tip for LoRa and SD card

Hi

For my LiLigo ESP32 OLED v T3 V1.6.1 I have learned SPI the hard way, now I like to share the solution.

I need to use SPI.h for LoRa and a different SPI setting for SD card.

Global:
#include "SD.h"
#include "SPI.h" // the lora device is SPI based so load the SPI library
SPIClass sdSPI(HSPI); // the SD card reader

When reading LORA I use:
SPI.begin();

When reading SD I use:

void spiSDstart() {
  uint8_t cardType;
  sdSPI.begin(SDSCK, SDMISO, SDMOSI, SDCS);   //LiLigo SD ikke standard gpio? derfor må det startes for hver skriving/lesing
  if (!SD.begin(SDCS, sdSPI))
  {
    Serial.println("    SD Card Mount Failed");
    while (1);
  }
  Serial.println("    SD Card Mount OK");
  //while (1);
}

For lora I use:

SPI.begin();

So in void loop I switch them on according to what the code does

Here is my LoRa and SD settings (incl GPIOs):


//LORA
// LoRa GPIOs
#define NSS 18                                   //select pin on LoRa device
#define NRESET 14                                //reset pin on LoRa device
#define LED1 -1                                 //on board LED, high for on
#define DIO0 26                                //DIO0 pin on LoRa device, used for RX and TX done 
#define DIO1 -1                                 //DIO1 pin on LoRa device, normally not used so set to -1 
#define DIO2 -1                                 //DIO2 pin on LoRa device, normally not used so set to -1
#define BUZZER -1  //4                                //pin for buzzer, on when logic high
#define LORA_DEVICE DEVICE_SX1278    //we need to define the device we are using

//*******  Setup LoRa Parameters Here ! ***************
//LoRa Modem Parameters
const uint32_t Frequency = 868000000;           //NORWAY frequency of transmissions in hertz
const uint32_t Offset = 0;                      //offset frequency for calibration purposes
const uint8_t Bandwidth = LORA_BW_125;          //LoRa bandwidth
const uint8_t SpreadingFactor = LORA_SF7;       //LoRa spreading factor
const uint8_t CodeRate = LORA_CR_4_5;           //LoRa coding rate
const uint8_t Optimisation = LDRO_AUTO;         //low data rate optimisation setting, normally set to auto
const int8_t TXpower = 2;                       //LoRa transmit power in dBm
//const uint16_t packet_delay = 1000;             //mS delay between packets
#define RXBUFFER_SIZE  50 //32                        //RX buffer size  

// SD Card GPIOs
#define SDSCK 14
#define SDMOSI 15
#define SDMISO 2
#define SDCS 13
const int chipSelect = 13;                       // Chip select pin for the SD card module

Hope it helps!
This works, serial:

SD Card Mount OK
KubeNr random: 3
Data written to SD card.
Data red from SD card:
3

M

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.