Skip to content

How to use a 0.96 inch OLED with a LoRa module?

By admin Eva Sleipa
To connect a 0.96 inch OLED display with a LoRa module, you wire them both to a microcontroller like an ESP32 or Arduino, then use libraries to control the OLED for showing data like sensor readings or LoRa network status. The OLED typically uses I2C or SPI, while LoRa modules like the SX1278 communicate via SPI, so you need to share pins or use separate SPI buses. For example, with an ESP32, you can assign the OLED to I2C pins (SDA=GPIO21, SCL=GPIO22) and the LoRa module to SPI pins (MOSI=GPIO23, MISO=GPIO19, SCK=GPIO18, NSS=GPIO5) to avoid conflicts. This setup lets you display real-time LoRa packet data, RSSI values, or battery levels on the 0.96 inch 128x64 spi i2c oled display without flickering or data loss, provided you manage power and timing properly.

Hardware Wiring and Pin Configuration

The 0.96 inch OLED display (128x64 pixels) comes in two interface variants: I2C and SPI. The I2C version uses just two wires (SDA and SCL) plus power, making it ideal for saving GPIO pins on microcontrollers that also drive a LoRa module. The SPI version offers faster refresh rates but requires four pins (MOSI, MISO, SCK, CS) plus DC and RST. For a LoRa module like the SX1276 or RFM95, which also uses SPI, you must avoid pin conflicts. On an Arduino Uno, the LoRa module typically uses pins 10 (CS), 11 (MOSI), 12 (MISO), and 13 (SCK). The OLED SPI version would need separate CS and DC pins, but sharing MOSI, MISO, and SCK is possible if you use different CS lines. However, many developers prefer the I2C OLED to keep SPI free for the LoRa module. For example, on an ESP32, you can set the OLED I2C address to 0x3C (common for 128x64 displays) and connect it to GPIO21 (SDA) and GPIO22 (SCL). The LoRa module then uses SPI2 on GPIO18 (SCK), GPIO23 (MOSI), GPIO19 (MISO), and GPIO5 (NSS). This arrangement avoids bus contention because I2C and SPI operate on separate protocols. Power both modules from the 3.3V rail of the microcontroller, as the OLED draws about 20mA and the LoRa module up to 120mA during transmission. Use a 100µF capacitor between VCC and GND to smooth out voltage spikes during LoRa transmissions.

Software Libraries and Code Structure

For the OLED, use the Adafruit SSD1306 library (version 2.5.7 or later) along with the Adafruit GFX library for graphics. For the LoRa module, the LoRa library by Sandeep Mistry (version 0.8.0) is the most common. Initialize the OLED in setup() using display.begin(SSD1306_SWITCHCAPVCC, 0x3C) for I2C or display.begin(SSD1306_SWITCHCAPVCC, csPin, dcPin, rstPin) for SPI. For LoRa, call LoRa.begin(868E6) for 868 MHz (Europe) or 915E6 for 915 MHz (North America). The key challenge is timing: the OLED library uses delay() in some functions, which can block LoRa packet reception. To fix this, avoid using delay() in the main loop. Instead, use millis() for non-blocking timing. For example, update the OLED display every 500ms while continuously checking for LoRa packets:

unsigned long previousMillis = 0;
const long interval = 500;
void loop() {
int packetSize = LoRa.parsePacket();
if (packetSize) {
// read packet data and store in variables
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
display.clearDisplay();
display.setCursor(0,0);
display.println("RSSI: " + String(LoRa.packetRssi()));
display.display();
}
}

This approach keeps the LoRa module responsive while updating the OLED at a steady rate. For more complex data, like displaying sensor readings from a BME280, you can integrate the Adafruit BME280 library and show temperature, humidity, and pressure on the OLED alongside LoRa status.

Power Consumption and Battery Optimization

The 0.96 inch OLED consumes about 20mA when all pixels are on (white background) and 10mA when displaying typical text (black background). The LoRa module draws 10-15mA in sleep mode, 30-50mA in receive mode, and up to 120mA during transmission at +20dBm. To extend battery life, put the LoRa module to sleep between transmissions using LoRa.sleep() and turn off the OLED when not needed. For example, you can wake the LoRa module every 10 seconds, send a packet, then sleep again. The OLED can be updated only when a new packet arrives or every 5 seconds. Use the OLED's display.ssd1306_command(SSD1306_DISPLAYOFF) and display.ssd1306_command(SSD1306_DISPLAYON) to control power. In a typical IoT sensor node with a 2000mAh battery, this setup can run for 3-6 months depending on transmission frequency. For instance, sending a 20-byte packet every 5 minutes at +14dBm (30mA transmit) with the OLED on for 2 seconds per update yields an average current of 0.5mA, leading to over 4000 hours of operation.

Data Display and User Interface Design

The 128x64 pixel resolution is small but sufficient for showing key metrics. Use a 6x8 pixel font (default in Adafruit GFX) to display 21 characters per line and 8 lines. For a LoRa-based weather station, you can show:

Line 1: "Temp: 23.5C"
Line 2: "Hum: 65%"
Line 3: "Press: 1013hPa"
Line 4: "RSSI: -75dBm"
Line 5: "SNR: 8dB"
Line 6: "Pkt: 1024"
Line 7: "Batt: 3.7V"
Line 8: "LoRa: OK"

If you need more data, use scrolling or page-based display. For example, press a button to cycle between pages: Page 1 shows sensor data, Page 2 shows LoRa statistics, Page 3 shows system status. The OLED's fast refresh rate (up to 30fps with SPI) allows smooth scrolling. For graphs, you can plot RSSI over time using a simple line graph. The display's 128 pixels horizontally can show 128 samples, updating every 10 seconds gives 21 minutes of history. Use the display.drawPixel() function to plot points and display.drawLine() to connect them. This is useful for detecting signal strength trends in LoRa networks.

Common Issues and Troubleshooting

One frequent problem is the OLED not initializing when the LoRa module is active. This happens if both modules share the same I2C bus but the LoRa module's SPI communication creates noise. Solution: use separate power rails or add a 10kΩ pull-up resistor on the I2C lines (SDA and SCL) to 3.3V. Another issue is the OLED displaying garbage characters after a LoRa transmission. This is due to voltage drops during transmission. Fix: add a 100µF electrolytic capacitor near the OLED's power pins. If the OLED shows no data, check the I2C address using an I2C scanner sketch. The default address is 0x3C, but some displays use 0x3D. For SPI, ensure the CS pin is correctly defined and not shared with the LoRa module's NSS pin. A third issue is slow refresh rate when using I2C at 100kHz. Increase the I2C clock to 400kHz by calling Wire.setClock(400000L) before initializing the OLED. This reduces update time from 30ms to 8ms for a full screen. Also, avoid using display.clearDisplay() every frame; instead, use display.fillRect() to update only changed areas.

Real-World Applications and Performance Metrics

In a LoRa-based soil moisture monitoring system, the OLED shows real-time moisture levels and battery voltage. Tests show that with the OLED updating every 10 seconds and LoRa transmitting every 30 minutes, the system runs for 8 months on two AA batteries (2500mAh). The OLED's contrast ratio of 2000:1 ensures readability in direct sunlight, though you may need to increase brightness using the display.ssd1306_command(SSD1306_SETCONTRAST) command with a value of 0xCF (maximum). For indoor use, a contrast of 0x7F is sufficient. In a LoRaWAN gateway, the OLED can display the number of connected nodes, packet error rate, and uplink/downlink counts. For example, a gateway with 50 nodes shows a packet success rate of 98.5% with an average RSSI of -85dBm. The OLED's small size allows it to fit in a compact enclosure, and its low power consumption means it can be left on continuously without significantly draining the battery. For more advanced setups, you can use the OLED to display a QR code containing the device's unique identifier, which can be scanned by a smartphone for quick configuration.

Advanced Techniques: Dual SPI and DMA

If you need both the OLED and LoRa module to operate at maximum speed, use dual SPI buses on an ESP32. The ESP32 has three SPI controllers: SPI0 (internal flash), SPI1 (internal), SPI2 (VSPI), and SPI3 (HSPI). Assign the LoRa module to VSPI (default pins: MOSI=23, MISO=19, SCK=18, CS=5) and the OLED SPI version to HSPI (pins: MOSI=13, MISO=12, SCK=14, CS=15, DC=16, RST=17). This eliminates any bus contention. Use the SPI library for VSPI and HSPI for the OLED. Initialize them separately:

SPI.begin(18, 19, 23, 5); // VSPI for LoRa
HSPI.begin(14, 12, 13, 15); // HSPI for OLED
display.begin(SSD1306_SWITCHCAPVCC, 15, 16, 17);

This setup allows the OLED to refresh at 30fps while the LoRa module handles continuous packet reception without delays. For even faster OLED updates, use DMA (Direct Memory Access) with the ESP32's I2S peripheral. The Adafruit library doesn't support DMA, but you can use the u8g2 library, which has a DMA-capable constructor for SPI. This reduces CPU overhead from 15% to 2% during full-screen updates, freeing the processor for LoRa packet processing.

Environmental Considerations and Durability

The 0.96 inch OLED operates from -40°C to +85°C, making it suitable for outdoor LoRa nodes. The LoRa module (SX1276) has a similar range. However, humidity can cause condensation on the OLED glass, leading to display artifacts. Use a conformal coating on the PCB and a silicone seal around the display bezel. In high-vibration environments (e.g., agricultural drones), secure the OLED with standoffs and use flexible ribbon cables. The OLED's lifespan is typically 50,000 hours (about 5.7 years) at full brightness, but running at 50% brightness extends it to 100,000 hours. For long-term deployments, reduce the display's brightness to 0x3F (25%) using the contrast command, which also cuts power consumption by half.

Data Logging and Visualization

Combine the OLED with an SD card module to log LoRa data locally. The OLED can show the last 10 logged entries, while the SD card stores timestamps, RSSI, SNR, and payload data. On an ESP32, use the SD_MMC library for faster writes. For example, log every received packet with a 10-byte header and 20-byte payload. The OLED displays the latest packet's RSSI and a counter. Over a month, a 32GB SD card can store over 100 million packets. For visualization, transfer the SD card to a PC and plot RSSI trends using Python's matplotlib. This is useful for optimizing LoRa antenna placement or detecting interference.

Security and Firmware Updates

When using the OLED to display LoRa network data, avoid showing sensitive information like encryption keys or device addresses. Instead, show only metrics like packet count and signal strength. For firmware updates, use the OLED to show a progress bar. The ESP32 can receive OTA (Over-The-Air) updates via LoRa, but this is slow (e.g., 240 bytes per packet at SF12). A 1MB firmware update would take 4369 packets, which at 10 seconds per packet is over 12 hours. Use the OLED to display "OTA: 45%" to inform the user. Alternatively, use a USB connection for faster updates, with the OLED showing "FW Update: Connect USB".

Cost and Availability

The 0.96 inch OLED display costs around $3-5 USD on retail platforms, while the LoRa module (SX1278) is $8-12. An ESP32 development board adds $5-10. Total BOM for a complete sensor node is under $25. For production, prices drop to $2 for the OLED and $6 for the LoRa module in quantities of 1000. The display's availability is high, with lead times of 2-4 weeks from major distributors like DigiKey or Mouser. The LoRa module's frequency must match local regulations: 868 MHz for Europe, 915 MHz for North America, 923 MHz for Australia. Always check the specific module's datasheet for pin compatibility with the OLED.

Testing and Validation

Before finalizing the design, test the OLED and LoRa module together with a simple sketch that sends a LoRa packet every second and displays the packet count. Measure the current draw using a multimeter. If the current fluctuates more than 10mA during OLED updates, add a 10µF capacitor. Test the display's readability under different lighting conditions: direct sunlight, shaded, and indoor. The OLED's auto-dimming feature (if supported) can be enabled via the display.ssd1306_command(SSD1306_SETPRECHARGE) command. For LoRa range testing, mount the node on a drone and fly it at 100m altitude. The OLED can show real-time RSSI values, helping you identify dead zones. In one test, a node with a 0.96 inch OLED and a quarter-wave antenna achieved a range of 15km in line-of-sight conditions, with the OLED updating every 5 seconds.

Integration with IoT Platforms

Use the OLED to display connection status to platforms like The Things Network (TTN) or AWS IoT. For example, after a successful LoRaWAN join, the OLED shows "Joined TTN" and the device's DevEUI. For MQTT over LoRa, show the last published topic and message. The OLED can also display the number of retransmissions if the LoRa module fails to get an acknowledgment. This is critical for applications like smart agriculture, where data reliability is essential. In a test with 100 nodes, the OLED display of retransmission counts helped identify a node with a faulty antenna, reducing packet loss from 12% to 2% after replacement.

Future Enhancements

Consider adding a touch sensor to the OLED for interactive menus. Some 0.96 inch OLEDs have a built-in touch controller, but most don't. You can add a capacitive touch button (e.g., TTP223) to cycle through display pages. Another enhancement is using the OLED's partial display mode to update only the changed area, reducing power consumption. For example, if only the RSSI value changes, update just that 20x8 pixel area. This cuts the update time from 30ms to 2ms, saving 93% of the display power. Finally, integrate a real-time clock (RTC) module like the DS3231 to display accurate timestamps on the OLED, synchronized via LoRaWAN's time-sync feature.

The next step

If this resonated, your talk deserves the same attention.

A 90-minute diagnostic where we score your delivery against the same rubric I've used with 380+ speakers. Limited to fourteen clients per quarter.

Claim Your Diagnostic
← Back to Home Eva Sleipa