Issue with simultaneous use of LoRa and a TFT screen on the Heltec Wireless Stick V3

Hello,

I am currently using the Heltec Wireless Stick V3 module for a project. This project requires both transmitting and receiving messages via LoRa, as well as using a TFT screen (model 2.0 TFT SPI ver1.1) that operates with the SPI protocol.

However, I have encountered a problem: the default configuration of the Heltec board reserves the pins used by the LoRa module, preventing me from properly connecting the pins of my TFT screen. To work around this, I used alternative pins to connect the screen and modified the SPI bus using the SPIClass class.

When I specify a new SPI bus with the command SPIClass mySPI1(2) , the TFT screen does not work, but the LoRa module functions correctly. Conversely, if I do not modify the SPI bus (i.e., I do not define SPIClass mySPI1(2) ), the TFT screen works properly, but the LoRa module stops functioning.

For this project, it is essential that I use both the LoRa module and the TFT screen, which share the SPI protocol. As I am new to Heltec boards, I would greatly appreciate your assistance in resolving this issue.

Thank you in advance for your help.

Code:
"#include “LoRaWan_APP.h”
#include “Arduino.h”
#include <Adafruit_GFX.h> // graphics library
#include <Adafruit_ST7789.h> // library for this display
#include <SPI.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>

////////////////////////////// LoRa variable init//////////////////////////////////////////////
#define RF_FREQUENCY 868E6 // Hz
#define TX_OUTPUT_POWER 14 // dBm
#define LORA_BANDWIDTH 0
#define LORA_SPREADING_FACTOR 7
#define LORA_CODINGRATE 1
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 30 // Define the payload size here
////////////////////////////// TFT variable init//////////////////////////////////////////////
#define TFT_CS 34 // CS pin
#define TFT_RST 47 // reset pin
#define TFT_DC 48 // data pin
#define TFT_SCK 36 // data pin
#define TFT_MISO 37 // data pin
#define TFT_MOSI 35 // data pin

#define ID “#04

////////////////////////////// TFT variable init//////////////////////////////////////////////
#define SHOCK_DIG 4
#define SHOCK_ANA 5

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

const String MES_ALERTE = “Z0Z04”;

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];
char vol[BUFFER_SIZE];
char volM[BUFFER_SIZE];
char volC[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

int16_t txNumber;

int16_t rssi,rxSize;

bool lora_idle = true;
bool stateDanger = false;
bool stateNew = false;

void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr);

void setup() {

Serial.begin(115200);

//Mcu.begin(WIRELESS_STICK_V3,SLOW_CLK_TPYE);

///////////////////////////////TFT///////////////////////////////////////////
SPIClass mySPI1(2); // Exemple : SPI secondaire
mySPI1.begin(TFT_SCK,TFT_MISO,TFT_MOSI,TFT_CS);   //(SCK, MISO, MOSI, SS)
tft.init(240, 320, SPI_MODE3); 
tft.setRotation(2);

pinMode(BUZZER, OUTPUT);

txNumber=0;
rssi=0;

//--------------------Initialisation of Lora------------------------//
RadioEvents.RxDone = OnRxDone;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

}

void loop(){

tft.fillScreen(ST77XX_BLACK); // fills the screen with black colour
tft.setCursor(10, 10); // starts to write text at y10 x10
tft.setTextColor(ST77XX_WHITE); // text colour to white you can use hex codes like 0xDAB420 too
tft.setTextSize(3); // sets font size
tft.setTextWrap(true);
tft.print(“HELLO WORLD!”);
delay(2000);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(10, 10);
tft.setTextSize(3); // sets font size
tft.setTextColor(ST77XX_RED);
tft.print(“TOTO!”);
delay(2000);
Serial.println(“ok”);

if(lora_idle)
{
lora_idle = false;
Serial.println(“into RX mode”);
Radio.Rx(0);
}
Radio.IrqProcess();
//Serial.println(rxpacket);

}

void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
rssi=rssi;
rxSize=size;
memcpy(rxpacket, payload, size );
rxpacket[size]=’\0’;
Radio.Sleep( );
Serial.printf("\r\nreceived packet “%s” with rssi %d , length %d\r\n",rxpacket,rssi,rxSize);
lora_idle = true;
strcpy(vol,rxpacket);
}
"

HSPI, VSPI, SPI1, SPI(2), there’s lots of different SPI stuff out there. I’d check if you can use the official SPI macros instead of a mySPI(2), e.g. mySPI(SPI2).
Otherwise - I’m not exactly sure how Heltec handles SPI under the hood. I’ve personally ditched their framework in favour of the ‘bare’ Arduino framework (didn’t think I’d call Arduino bare) with RadioLib for the radio stuff.

But most importantly: have you actually checked the schematic for your pin numbers? Because pins 36/37 aren’t exactly free…