Hey all, I'm attempting to display some data (a string) I receive from my Dragino LoRa Shield on my ST7920 LCD screen but I'm having some trouble. Microcontroller used is an ESP-32 Devkitc V4.
The LCD screen uses the U8g2 library for all its graphical capabilities and I've read on other posts that it is a pain to get it to print string variables. I've gotten int and float variables to print, but not a string. Is there something in the LoRa.h or U8g2lib.h libraries to work around this?
Furthermore, I get a error:
90 | u8g2.drawString(0, 50, LoRaData); //write String from LoRa
| ^~~~~~~~
exit status 1
Compilation error: 'LoRaData' was not declared in this scope
Here is my code so far anyway:
#include <U8g2lib.h>
#include <LoRa.h>
//Define which LCD module we are using and the respective pins
U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 17, /* data=*/ 4, /* CS=*/ 15, /* reset=*/ 22); // ESP32 defaults are 18, 23, 5, arbitrary 22
// Statements to determine if LCD is running in I2C or SPI mode
#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
#define cs 5
#define rst 14
#define dio0 2
//#define LCD_CS 16
#define LORA_CS 5
//LCD HSPI pins
#define HSPI_SCK 17
#define HSPI_MISO 16
#define HSPI_MOSI 4
#define LCD_SS 15
SPIClass *hspi = NULL;
String name = "Garbage"; //in SRAM
void setup(void) {
// Enbale LCD functions
hspi = new SPIClass(HSPI);
hspi->begin(HSPI_SCK, HSPI_MISO, HSPI_MOSI, LCD_SS);
pinMode(hspi->pinSS(), OUTPUT);
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
//setup LoRa transceiver module
LoRa.setPins(cs, 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());
}
digitalWrite(hspi->pinSS(), LOW); //enable to write
// Display Data recieved via LoRa
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");
u8g2.drawUTF8(0, 50, LoRaData); //write String
u8g2.sendBuffer();
digitalWrite(hspi->pinSS(), HIGH); //disable
delay(1000);
}