Does anyone have any working code for the Semtech LoRa devices, RFM98, DRF1278F etc, on a Pyboard ?
In particular I would like to see SPI init, read and write register routines.
I have started with the basics, reading and writing registers over the SPI. I have this working on Raspberry Pi (Python) and Microbit, but I cannot get the SPI working correctly on Pyboard. My read register and write register routines appear to work, but the printed data, whilst consistent, is not correct.
I am very familiar with driving these native LoRa devices with Arduino, so I know what values should be present at each of the 128 register locations.
Semtech LoRa devices on Pyboard
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Semtech LoRa devices on Pyboard
You might like to look at some official existing code which uses SPI, such as the NRF24L01+ driver https://github.com/micropython/micropyt ... rf24l01.py. Or the SSD1306 driver which has an SPI option https://github.com/micropython/micropyt ... ssd1306.py.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 30
- Joined: Sat Feb 25, 2017 8:24 am
Re: Semtech LoRa devices on Pyboard
Thanks very useful.
I did get it working, in a crude way with;
def WriteReg(reg, data): #Write a register to a LoRa device
reg = reg | 0x80
ss.low()
SPI.send(reg)
SPI.send(data)
ss.high()
return
def ReadReg(reg): #Read a register from LoRa device
data = bytearray(1)
ss.low()
SPI.send(reg)
SPI.recv(data)
ss.high()
return data[0]
But now I see how readinto works I will try that.
I wanted it working so that I could try out the various options in the Python world, I used a 'test' routine that prints out all 128 LoRa device registers as a formated table in hex, I measured these times;
Arduino ESP32 and C\C++, 240Mhz 0.0034 Seconds
Arduino Pro Mini and C\C++ 8Mhz, 0.031 Seconds
Pyboard v1.1 and MicroPython 168Mhz, 0.083 Seconds
Pi 2 900Mhz and MMbasic, 0.19 Seconds
MicroBit and MicroPython 48Mhz, 0.3856 Seconds
Pi 2 900Mhz and Python, 7.44Seconds
So the Pyboard, is a very credible performer. Python on the Pi is dire.
I did get it working, in a crude way with;
def WriteReg(reg, data): #Write a register to a LoRa device
reg = reg | 0x80
ss.low()
SPI.send(reg)
SPI.send(data)
ss.high()
return
def ReadReg(reg): #Read a register from LoRa device
data = bytearray(1)
ss.low()
SPI.send(reg)
SPI.recv(data)
ss.high()
return data[0]
But now I see how readinto works I will try that.
I wanted it working so that I could try out the various options in the Python world, I used a 'test' routine that prints out all 128 LoRa device registers as a formated table in hex, I measured these times;
Arduino ESP32 and C\C++, 240Mhz 0.0034 Seconds
Arduino Pro Mini and C\C++ 8Mhz, 0.031 Seconds
Pyboard v1.1 and MicroPython 168Mhz, 0.083 Seconds
Pi 2 900Mhz and MMbasic, 0.19 Seconds
MicroBit and MicroPython 48Mhz, 0.3856 Seconds
Pi 2 900Mhz and Python, 7.44Seconds
So the Pyboard, is a very credible performer. Python on the Pi is dire.
Re: Semtech LoRa devices on Pyboard
Hi LoRaTracker, and others
That sounds interesting. I've been searching (for a long time now) for a solution for my use-case.
I want to use a microprocessor (preverable Micropython as an OS) in combination with LoRaWAN (class c) and Ethernet (for a telnet connection to control a buttonpanel via the RJ-45 port of this panel).
A LoPy unit (Pycom) sounds nice, but to write and implement a new ethernet library in the firmware is a real 'pain'... the Pyboard has this lib (firmware) allready available so that a reason the Pyboard was allways on my 'radar', but LoRa was still unavailable (at least i didn't see any good examples of LoRa shields/units hooked to the Pyboard). In your post I saw you did some experimenting.
Do you know if it feasable to buy a Pyboard, a WIZ820io ethernet module (spi 1) and a LoRa module (spi 2) for my use-case? I want LoRa to work with Class C (so more or less real-time)! In your experience, do you have any tips on this?
Any help is really appriciated.
With kind regards, Jeroen Wolf
That sounds interesting. I've been searching (for a long time now) for a solution for my use-case.
I want to use a microprocessor (preverable Micropython as an OS) in combination with LoRaWAN (class c) and Ethernet (for a telnet connection to control a buttonpanel via the RJ-45 port of this panel).
A LoPy unit (Pycom) sounds nice, but to write and implement a new ethernet library in the firmware is a real 'pain'... the Pyboard has this lib (firmware) allready available so that a reason the Pyboard was allways on my 'radar', but LoRa was still unavailable (at least i didn't see any good examples of LoRa shields/units hooked to the Pyboard). In your post I saw you did some experimenting.
Do you know if it feasable to buy a Pyboard, a WIZ820io ethernet module (spi 1) and a LoRa module (spi 2) for my use-case? I want LoRa to work with Class C (so more or less real-time)! In your experience, do you have any tips on this?
Any help is really appriciated.
With kind regards, Jeroen Wolf