Displaying data on Heltec LoRa 32 V3

How do I modify this program to also display the data received in the packet on the OLED display? I can't seem to find the correct library for both LoRa communications and OLED display.

#include "LoRaWan_APP.h"
#include "Arduino.h"

#define RF_FREQUENCY 915000000  // Hz
#define TX_OUTPUT_POWER 14      // dBm
#define LORA_BANDWIDTH 0        // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz]
#define LORA_SPREADING_FACTOR 7 // [SF7..SF12]
#define LORA_CODINGRATE 1       // [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
#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

// Message structure with header
struct __attribute__((packed)) RadioMessage {
  uint32_t header;          // 4 byte header
  uint8_t state;            // 1 byte
  uint16_t batteryVoltage;  // 2 bytes
  uint8_t version;          // 1 byte
  uint8_t checksum;         // 1 byte
};                          // Total: 9 bytes

static RadioEvents_t RadioEvents;
RadioMessage receivedMsg;
int16_t rssi, rxSize;
bool lora_idle = true;

uint8_t rxpacket[BUFFER_SIZE];

void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssiValue, int8_t snr) {
    rssi = rssiValue;
    rxSize = size;
    
    Serial.printf("\nReceived packet size: %d bytes\n", size);
    Serial.printf("RadioMessage structure size: %d bytes\n", sizeof(RadioMessage));
    
    // Print raw bytes for debugging
    Serial.println("Raw received bytes (hex):");
    for(int i = 0; i < size; i++) {
        Serial.printf("0x%02X ", payload[i]);
    }
    Serial.println();
    
    if(size == sizeof(RadioMessage)) {
        memcpy(&receivedMsg, payload, sizeof(RadioMessage));
        
        Serial.println("\n----------------------------------------");
        Serial.println("Received LoRa Message:");
        Serial.printf("Header: 0x%08lX\n", receivedMsg.header);  // Print header as hex
        Serial.printf("State: %d\n", receivedMsg.state);
        Serial.printf("Battery Voltage: %d mV\n", receivedMsg.batteryVoltage);
        Serial.printf("Version: %d\n", receivedMsg.version);
        Serial.printf("Checksum: 0x%02X\n", receivedMsg.checksum);
        Serial.printf("RSSI: %d dBm\n", rssi);
        Serial.printf("SNR: %d dB\n", snr);
        Serial.println("----------------------------------------\n");

        // Optional: Print header bytes individually
        uint8_t* headerBytes = (uint8_t*)&receivedMsg.header;
        Serial.println("Header bytes individually:");
        for(int i = 0; i < 4; i++) {
            Serial.printf("Header byte %d: 0x%02X\n", i, headerBytes[i]);
        }
    } else {
        Serial.printf("Error: Received %d bytes, expected %d bytes\n", 
                     size, sizeof(RadioMessage));
    }
    
    Radio.Sleep();
    lora_idle = true;
}

void setup() {
    Serial.begin(115200);
    Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE);
    
    rssi = 0;
    
    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);
    
    Serial.printf("RadioMessage structure size: %d bytes\n", sizeof(RadioMessage));
    Serial.println("LoRa Receiver initialized");
}

void loop() {
    if(lora_idle) {
        lora_idle = false;
        Serial.println("into RX mode");
        Radio.Rx(0);
    }
    Radio.IrqProcess();
}

I have had the U8g2lib working just fine on the Heltec V3, no issues.

Download the U8g2lib library, get a basic sketch displaying stuff on the display and then add the bits of working code to your sketch.

have a look at helltec-esp32-v3-und-bmp180 which uses the HT_SSD1306Wire library

Thank you! The HT_SSD1306 library worked like a charm!

if the problem is solved click the Solution button at the bottom of the reply that answered the question - this helps others with a similar question

Been there. Done that.