Pi Pico W LoRa sx1262 & other modules?

Hi all,

I’m hoping for some help here, I’m a bit of a novice, but I have managed to get this pico W going with VS Code, MicroPython, and the LoRa sx1262 - I have two, and they’ve successfully talked to each other (using the examples copied from LoRa P2P Wireless Gate Alarm - Tutorial Australia (which is a brilliant write-up btw., and I’m following it closely). So that’s the good news. In my quest to make things more complicated than they probably should be, I thought it would be nice to have some kind of display on the pico - so I got the 1.3" OLED module from Waveshare (OLED Display Module for Raspberry Pi Pico, 1.3inch, SPI/I2C (64×128) | Buy in Australia | WS-19376 | Waveshare | Core Electronics). I can get the OLED working without issue when the LoRa module isn’t connected. When it is connected however, the OLED just does not do anything.

I see there’s a conflict between “Key 1” on the OLED module, and LoRa reset on the LoRa one, but I’m not pressing keys (even though I want to - that’s a problem for later).

Sadly, I wanted to also get an RTC module in the mix (see comment above re complications) - again, without the LoRa - no issues. With LoRa, I do at least get an error message:

Traceback (most recent call last):
  File "<stdin>", line 78, in <module>
  File "<stdin>", line 48, in set_time
OSError: [Errno 110] ETIMEDOUT

The code for the RTC follows:

    rtc = ds3231(I2C_PORT,I2C_SCL,I2C_SDA)
    rtc.set_time('13:45:50,Monday,2021-05-24')
    rtc.read_time()
    #rtc.set_alarm_time('13:45:55,Monday,2021-05-24')

(that’s straight from the WaveShare examples)

The OLED (+ LoRa) code thus:

from sx1262 import SX1262
import time

# for OLED
import OLEDspi
OLED = OLEDspi.OLED_1inch3()

# for blink
from machine import Pin
from utime import sleep
led_pin = Pin("LED", Pin.OUT)


def cb(events):
    OLED.rect(0,22,128,20,OLED.white)

    led_pin.off()


    if events & SX1262.RX_DONE:
        msg, err = sx.recv()
        if msg == b'Ping':
            error = SX1262.STATUS[err]
            OLED.text(msg,1,27,OLED.white)
            print('Receive: {}, {}'.format(msg, error))
            sx.send(b'Pong')
    elif events & SX1262.TX_DONE:
        print('TX done.')
        OLED.text("TX done",1,44,OLED.white)
    OLED.show()

    led_pin.on()
    

# LoRa
sx = SX1262(spi_bus=1, clk=10, mosi=11, miso=12, cs=3, irq=20, rst=15, gpio=2)
sx.begin(freq=923, bw=500.0, sf=12, cr=8, syncWord=0x12,
         power=-5, currentLimit=60.0, preambleLength=8,
         implicit=False, implicitLen=0xFF,
         crcOn=True, txIq=False, rxIq=False,
         tcxoVoltage=1.7, useRegulatorLDO=False, blocking=True)

sx.setBlockingCallback(False, cb) # set callback function for non-blocking mode 

OLED.fill(0x0000) 
OLED.text("Waiting for tx",1,10,OLED.white)
OLED.show()

led_pin.on()

print("LED will flash while waiting, and blink when receiving.")
while True:
    try:
        led_pin.off()
        sleep(0.05)
        led_pin.on()
        sleep(1)
    except KeyboardInterrupt:
        break


led_pin.off()
OLED.fill(0x0000) 
OLED.text("stopped",1,10,OLED.white)
OLED.show()
sleep(0.25)
OLED.scroll(0,5)
OLED.show()
sleep(0.25)
print("Exited gracefully.")

Hi @Damian184098

Looking at both the products there would be some pin conflicts, the MISO pin (GPIO12) for the LoRa module is also the reset pin for the OLED. I would say that when the LoRa module is attempting to communicate it is also triggering the OLED to reset.

You may be able to use jumper wires to be able to change the pins that the are being use so that there isn’t any conflicts, otherwise you would have to look into using a different display.

Oh thanks Dan… I saw the reset conflict and imagined that was all… good grief. I don’t suppose you know which display will work with this LoRa board?

HI Damian,

I know that we have already discussed this, but so there is a record in the event that someone else wants to put together something similar to yourself, we have tested and confirmed that the PiicoDev OLED Display Module (128x64) SSD1306 will work with the SX1262 module.

Quick follow-up on this - I actually got this working, although obviously not in a stacked configuration. The offending pin was on GP12, which LoRa uses. I updated the OLED code to use GP22 for OLED_RST, and connected (DuPont-style) from GP22 on the Pico to GP12 on the OLED board. As the OLED uses SPI by default, as does the LoRa, I could then get the OLED updating along with the LoRa doing its business.

Now I need to get a PCB made :frowning:

1 Like

Hi @Damian184098

Great to hear that you managed to get it sorted, even if it wasn’t as plug and play as anticipated :slight_smile: