Hi everyone,
I am currently working on a project involving a Raspberry Pi Pico and a LoRa SX1262 module. The goal is to establish communication between the Pico and the LoRa module using C++.
Here’s what I’ve done so far:
- Setup and Development Environment:
- I am using the Pico SDK with CMake for building the project.
- The code compiles and builds successfully without any errors. A .uf2 file is generated as expected.
- Uploading the Code:
- I copy the .uf2 file to the Pico by entering bootloader mode.
- After uploading, the Pico disconnects and re-enumerates.
- Issues:
- When I open the serial monitor using the screen command on my Linux terminal, I see no output from the program.
- The test program works perfectly, so I know the cable, power, and serial setup are not the issue.
- MicroPython Test Results:
- I previously tested communication between the Pico and SX1262 module using MicroPython, and it worked as expected. Meaning the hardware connections and the module are functional.
Test code that works as expected
#include <pico/stdlib.h>
#include <stdio.h>
int main() {
stdio_init_all(); // Initialize stdio (USB)
while (true) {
printf("Hello, World!\n");
sleep_ms(1000);
}
return 0;
}
Test code that doesn’t work
// define pins to be used
#define SPI_PORT spi0
#define SPI_MISO 12
#define SPI_MOSI 11
#define SPI_SCK 10
#define RFM_NSS 3
#define RFM_RST 15
#define RFM_DIO0 20
#define RFM_DIO1 21
#include <pico/stdlib.h>
// include the library
#include <RadioLib.h>
// include the hardware abstraction layer
#include "hal/RPiPico/PicoHal.h"
// create a new instance of the HAL class
PicoHal* hal = new PicoHal(SPI_PORT, SPI_MISO, SPI_MOSI, SPI_SCK);
// now we can create the radio module
// NSS pin: 26
// DIO0 pin: 14
// RESET pin: 22
// DIO1 pin: 15
SX1276 radio = new Module(hal, RFM_NSS, RFM_DIO0, RFM_RST, RFM_DIO1);
int main() {
spi_init(SPI_PORT, 1000*1000);
gpio_set_function(SPI_MISO, GPIO_FUNC_SPI);
gpio_set_function(SPI_MOSI, GPIO_FUNC_SPI);
gpio_set_function(SPI_SCK, GPIO_FUNC_SPI);
// initialize just like with Arduino
printf("[SX1276] Initializing ... ");
int state = radio.begin();
if (state != RADIOLIB_ERR_NONE) {
printf("failed, code %d\n", state);
return(1);
}
printf("success!\n");
// loop forever
for(;;) {
// send a packet
printf("[SX1276] Transmitting packet ... ");
state = radio.transmit("Hello World!");
if(state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
printf("success!\n");
// wait for a second before transmitting again
hal->delay(500);
} else {
printf("failed, code %d\n", state);
}
}
return(0);
}
What I Need Help With:
- How can I debug this issue further?
- Are there common pitfalls when using RadioLib with the SX1262 module that I might have overlooked?
- Is there a way to verify that the SX1262 module is being initialized properly in my code?
- If anyone has working demo code for this setup, that would be incredibly helpful!
The Pinout diagram of the LoRa module, found here.