Greetings, just getting to know arduino and I'm wiring up a basic project which involves data being received off a Dragino LoRa Shield transciever, before being displayed on a ST7920 LCD screen. My micro-controller of choice is the ESP32 Devkitc v4.
I want my receiver and LCD screen to be running constantly so if any message is picked up, it can be displayed almost instantaneously, and by my understanding, this means utilising both SPI buses on the ESP (VSPI & HSPI). Both the Dragino LoRa Shield and LCD screen work perfectly when connected to the default VSPI pins, however, whenever I try getting them to run simultaneously, the device connected to HSPI does not seem to work at all. Not sure if the 'LoRa.h' or 'U8g2lib.h' libraries have some code that require them to be used via the default VSPI. I am aware of the option to run both devices of the same SPI lines, albeit with different chip selects to toggle between each device, but I want each to always be running.
Below is some test code. I just want some basic function to run off both, for the Dragino to receive some packets off another ESP I have transmitting, and the LCD to display some example text. Any suggestions?
#include <U8g2lib.h>
#include <LoRa.h>
// VSPI CONNECTED VIA DEFAULT PINS
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18, /* data=*/ 23, /* CS=*/ 5, /* reset=*/ 22); // ESP32
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
//define the pins used by the transceiver module (HSPI CONNECTED)
#define ss 26
#define rst 16
#define dio0 17
//The Default HSPI Pins
#define HSPI_SCK 14
#define HSPI_MISO 12
#define HSPI_MOSI 13
#define HSPI_CS 15
//Via tutorial from
SPIClass *hspi = NULL;
void setup(void) {
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
hspi = new SPIClass(HSPI);
hspi->begin(HSPI_SCK, HSPI_MISO, HSPI_MOSI, HSPI_CS);
pinMode(hspi->pinSS(), OUTPUT);
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
while (!LoRa.begin(915E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop(void) {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
String LoRaData = LoRa.readString();
Serial.print(LoRaData);
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
u8g2.setFont(u8g2_font_unifont_t_chinese2); // use chinese2 for all the glyphs of "你好世界"
u8g2.setFontDirection(0);
u8g2.clearBuffer();
u8g2.setCursor(0, 15);
u8g2.print("Hello World!");
u8g2.setCursor(0, 40);
u8g2.print("你好世界"); // Chinese "Hello World"
u8g2.sendBuffer();
delay(1000);
}