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.")