Interfacing LoRa SX1278 with STM32 – Sender & Receiver
Interfacing LoRa Module SX1278 with STM32 Microcontroller. SPI Connection with Ra-02 SX1278 & STM32F103C for Sender Receiver Code & library
- Suitable forB.Tech/Diploma LoRa/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Overview
In this tutorial, we will learn
Interfacing of LoRa Module SX1278 with STM32
Bluepill Microcontroller. The
Ra-02
module uses SX1278 IC and works on a
433MHz
frequency. Using the Frequency hopping, it gives the sweet balance of quality signal transmission—will cover a range of 420-450MHz. The LoRa SX1278 works with SPI communication protocol so it can be used with any microcontroller that supports
SPI
. The SX1278 module can be easily interfaced with the STM32F103 chip.
The tutorial consists of two examples. In the first example, we will send a simple “
Hello World
” message from LoRa Sender/Transmitter to Receiver. But in the second example, we will send the sensor data wirelessly. The
BME280
Barometric Pressure Sensor gives the information of Barometric Pressure, Temperature, Humidity & Approx. Altitude. The
STM32 LoRa Sender
will send the sensor data to the
STM32 LoRa Receiver
If you are reading this post from the North America region, then you can work with 915MHz LoRa Module
SX1276
Bill of Materials
All the components required for this tutorial are given below along with the purchase link.
S.N.
Components Name
Quantity
Purchase Links
STM32F103C Microcontroller
Amazon
AliExpress
LoRa Module SX1278
Amazon
AliExpress
BME280 Sensor
Amazon
AliExpress
5V Power Supply
Amazon
AliExpress
Connecting Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
LoRa Module SX1278
The
SX1278 Ra-02
Chip is manufactured by Semtech. The SX1278 RF module is mainly used for long-range spread spectrum communication. It can resist Minimize current consumption & has a high sensitivity of
-148 dBm
with a power output of
+20 dBm
. A long transmission distance with almost 5km can be achieved with high reliability. Thus SX1278 is great for
IoT applications
to send sensor data to the cloud over long ranges.
This module uses SX1278 IC from
SEMTECH
and works on a
433MHz frequency
. Frequency hopping—which gives you that sweet balance of quality signal transmission will cover a range of 420-450 MHz. This long-range wireless capability is packed into a small (17 x 16mm) package and delivered without an antenna.
SX1278 Pinout
Pin 1: ANT
– This pin is to attach to the antenna.
Pin 2, 9, 16: GND
– Ground pin of common ground with power supply and controllers.
Pin 3: 3.3V
– To power up the device pin 3 will help for power input.
Pin 4: RESET
– Pin 4 is to reset the module through an external signal.
Pin 5, 6, 7, 8, 10, 11: DIO0, DIO1, DIO2, DIO3, DIO4, DIO5
– To perform the general, I/O function through module the DIO pins will help. These pins is customizable as an interrupt pin.
Pin 12: SCK
– SCK pin is for the clock pulse during the SPI communication.
Pin 13: MISO
– MISO means Master in and Slave out that transfers data transfer from the Module to the Controller. The Master is a controller & SX1278 is Slave.
Pin 14: MOSI
– MOSI means Master out Slave In. So, this pin will receive the data from Controller.
Pin 15: NSS
– NSS is a chip select/enable pin will help to activate the slave.
LoRa Frequency Allocation
LoRa frequency is not legal everywhere. I am from India and here the unlicensed Frequency range is from 865MHz to 867MHz. So I am only allowed to use this frequency range. The SX1278 has a frequency of 433MHz so I am not allowed to use it for an extended time aside from for an academic purpose. Similarly, check the allowed Ranges in your country and confirm you’re allowed to use the actual frequency range. LoRa modules do are available different frequency ranges, the foremost common being the 433MHz, 915MHz, and 868MHz.
Interfacing LoRa SX1278 with STM32
Now let us interface LoRa Module SX1278 with STM32F103C Board and make a simple STM32 LoRa Sender Receiver Device. The connection between SX1278 & STM32F103 is as follows:
The schematic is given below. You can assemble the pair of the circuit on the breadboard. One of the circuits will act as a transmitter or sender and the other as a receiver.
LoRa Library for STM32
The Arduino LoRa Library is not supported by
STM32F103 Board
. That is why there is a modified library for STM32F103 Board for Arduino IDE. The STM32 LoRa library is used for sending and receiving data using
LoRa radios
This library exposes the LoRa radio directly and allows you to send data to any radios in range with the same radio parameters. All data is broadcasted and there is no addressing.
Download:
STM32 LoRa Library
Sender & Receiver Code
Sender Code
#include <SPI.h>
#include <LoRa_STM32.h>
#define SS PA4
#define RST PB0
#define DI0 PA1
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
int
counter
=
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
;
Serial
println
(
"LoRa Sender"
)
;
LoRa
setTxPower
(
TX_P
)
;
LoRa
setSyncWord
(
ENCRYPT
)
;
LoRa
setPins
(
SS
RST
DI0
)
;
if
(
!
LoRa
begin
(
BAND
)
)
{
Serial
println
(
"Starting LoRa failed!"
)
;
while
(
)
;
}
}
void
loop
(
)
{
Serial
(
"Sending packet: "
)
;
Serial
println
(
counter
)
;
// send packet
LoRa
beginPacket
(
)
;
LoRa
(
"hello "
)
;
LoRa
(
counter
)
;
LoRa
endPacket
(
)
;
counter
++
;
delay
(
5000
)
;
}
Receiver Code
#include <SPI.h>
#include <LoRa_STM32.h>
#define SS PA4
#define RST PB0
#define DI0 PA1
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
;
Serial
println
(
"LoRa Receiver"
)
;
LoRa
setTxPower
(
TX_P
)
;
LoRa
setSyncWord
(
ENCRYPT
)
;
LoRa
setPins
(
SS
RST
DI0
)
;
if
(
!
LoRa
begin
(
BAND
)
)
{
Serial
println
(
"Starting LoRa failed!"
)
;
while
(
)
;
}
}
void
loop
(
)
{
// try to parse packet
int
packetSize
=
LoRa
parsePacket
(
)
;
if
(
packetSize
)
{
// received a packet
Serial
(
"Received packet '"
)
;
// read packet
while
(
LoRa
available
(
)
)
{
Serial
(
(
char
)
LoRa
read
(
)
)
;
}
// print RSSI of packet
Serial
(
"' with RSSI "
)
;
Serial
println
(
LoRa
packetRssi
(
)
)
;
}
}
Result
Sending Sensor Data Wirelessly using LoRa Module
Let us go through the second example now. In this example, we will be Interfacing SX1278 with STM32 and BME280 sensor to the Sender Circuit. The BME280 is an integrated environmental sensor developed specifically for mobile applications that have high linearity & accuracy for pressure, humidity and temperature measurements.
The Sensor works on I2C Protocol so its I2C Pins, i.e SDA & SCL is connected to PB7 & PB6 respectively. We will send the BME280 Sensor reading wirelessly from STM32 LoRa Sender to STM32 LoRa Receiver.
Check the previous similar project here:
Send Sensor Data Wirelessly using LoRa & Arduino
Project PCB Gerber File & PCB Ordering Online
If you don’t want to assemble the circuit on breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for the STM32 LoRa SX1278 Sender & Receiver is designed using
EasyEDA
online Circuit Schematics & PCB designing tool. The image of the Sender PCB is given below.
Similarly the image of the Receiver PCB is given below.
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from
ALLPCB
at
1$
only.
Download Gerber File for Sender PCB:
Sender PCB
Download Gerber File for Receiver PCB:
Receiver PCB
You can use this Gerber file to order high quality PCB for this project. To do that visit the
ALLPCB
official website by clicking here:
https://www.allpcb.com/
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After
In this tutorial, we will learn
Interfacing of LoRa Module SX1278 with STM32
Bluepill Microcontroller. The
Ra-02
module uses SX1278 IC and works on a
433MHz
frequency. Using the Frequency hopping, it gives the sweet balance of quality signal transmission—will cover a range of 420-450MHz. The LoRa SX1278 works with SPI communication protocol so it can be used with any microcontroller that supports
SPI
. The SX1278 module can be easily interfaced with the STM32F103 chip.
The tutorial consists of two examples. In the first example, we will send a simple “
Hello World
” message from LoRa Sender/Transmitter to Receiver. But in the second example, we will send the sensor data wirelessly. The
BME280
Barometric Pressure Sensor gives the information of Barometric Pressure, Temperature, Humidity & Approx. Altitude. The
STM32 LoRa Sender
will send the sensor data to the
STM32 LoRa Receiver
If you are reading this post from the North America region, then you can work with 915MHz LoRa Module
SX1276
Bill of Materials
All the components required for this tutorial are given below along with the purchase link.
S.N.
Components Name
Quantity
Purchase Links
STM32F103C Microcontroller
Amazon
AliExpress
LoRa Module SX1278
Amazon
AliExpress
BME280 Sensor
Amazon
AliExpress
5V Power Supply
Amazon
AliExpress
Connecting Jumper Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
LoRa Module SX1278
The
SX1278 Ra-02
Chip is manufactured by Semtech. The SX1278 RF module is mainly used for long-range spread spectrum communication. It can resist Minimize current consumption & has a high sensitivity of
-148 dBm
with a power output of
+20 dBm
. A long transmission distance with almost 5km can be achieved with high reliability. Thus SX1278 is great for
IoT applications
to send sensor data to the cloud over long ranges.
This module uses SX1278 IC from
SEMTECH
and works on a
433MHz frequency
. Frequency hopping—which gives you that sweet balance of quality signal transmission will cover a range of 420-450 MHz. This long-range wireless capability is packed into a small (17 x 16mm) package and delivered without an antenna.
SX1278 Pinout
Pin 1: ANT
– This pin is to attach to the antenna.
Pin 2, 9, 16: GND
– Ground pin of common ground with power supply and controllers.
Pin 3: 3.3V
– To power up the device pin 3 will help for power input.
Pin 4: RESET
– Pin 4 is to reset the module through an external signal.
Pin 5, 6, 7, 8, 10, 11: DIO0, DIO1, DIO2, DIO3, DIO4, DIO5
– To perform the general, I/O function through module the DIO pins will help. These pins is customizable as an interrupt pin.
Pin 12: SCK
– SCK pin is for the clock pulse during the SPI communication.
Pin 13: MISO
– MISO means Master in and Slave out that transfers data transfer from the Module to the Controller. The Master is a controller & SX1278 is Slave.
Pin 14: MOSI
– MOSI means Master out Slave In. So, this pin will receive the data from Controller.
Pin 15: NSS
– NSS is a chip select/enable pin will help to activate the slave.
LoRa Frequency Allocation
LoRa frequency is not legal everywhere. I am from India and here the unlicensed Frequency range is from 865MHz to 867MHz. So I am only allowed to use this frequency range. The SX1278 has a frequency of 433MHz so I am not allowed to use it for an extended time aside from for an academic purpose. Similarly, check the allowed Ranges in your country and confirm you’re allowed to use the actual frequency range. LoRa modules do are available different frequency ranges, the foremost common being the 433MHz, 915MHz, and 868MHz.
Interfacing LoRa SX1278 with STM32
Now let us interface LoRa Module SX1278 with STM32F103C Board and make a simple STM32 LoRa Sender Receiver Device. The connection between SX1278 & STM32F103 is as follows:
The schematic is given below. You can assemble the pair of the circuit on the breadboard. One of the circuits will act as a transmitter or sender and the other as a receiver.
LoRa Library for STM32
The Arduino LoRa Library is not supported by
STM32F103 Board
. That is why there is a modified library for STM32F103 Board for Arduino IDE. The STM32 LoRa library is used for sending and receiving data using
LoRa radios
This library exposes the LoRa radio directly and allows you to send data to any radios in range with the same radio parameters. All data is broadcasted and there is no addressing.
Download:
STM32 LoRa Library
Sender & Receiver Code
Sender Code
#include <SPI.h>
#include <LoRa_STM32.h>
#define SS PA4
#define RST PB0
#define DI0 PA1
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
int
counter
=
;
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
;
Serial
println
(
"LoRa Sender"
)
;
LoRa
setTxPower
(
TX_P
)
;
LoRa
setSyncWord
(
ENCRYPT
)
;
LoRa
setPins
(
SS
RST
DI0
)
;
if
(
!
LoRa
begin
(
BAND
)
)
{
Serial
println
(
"Starting LoRa failed!"
)
;
while
(
)
;
}
}
void
loop
(
)
{
Serial
(
"Sending packet: "
)
;
Serial
println
(
counter
)
;
// send packet
LoRa
beginPacket
(
)
;
LoRa
(
"hello "
)
;
LoRa
(
counter
)
;
LoRa
endPacket
(
)
;
counter
++
;
delay
(
5000
)
;
}
Receiver Code
#include <SPI.h>
#include <LoRa_STM32.h>
#define SS PA4
#define RST PB0
#define DI0 PA1
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
void
setup
(
)
{
Serial
begin
(
115200
)
;
while
(
!
Serial
)
;
Serial
println
(
"LoRa Receiver"
)
;
LoRa
setTxPower
(
TX_P
)
;
LoRa
setSyncWord
(
ENCRYPT
)
;
LoRa
setPins
(
SS
RST
DI0
)
;
if
(
!
LoRa
begin
(
BAND
)
)
{
Serial
println
(
"Starting LoRa failed!"
)
;
while
(
)
;
}
}
void
loop
(
)
{
// try to parse packet
int
packetSize
=
LoRa
parsePacket
(
)
;
if
(
packetSize
)
{
// received a packet
Serial
(
"Received packet '"
)
;
// read packet
while
(
LoRa
available
(
)
)
{
Serial
(
(
char
)
LoRa
read
(
)
)
;
}
// print RSSI of packet
Serial
(
"' with RSSI "
)
;
Serial
println
(
LoRa
packetRssi
(
)
)
;
}
}
Result
Sending Sensor Data Wirelessly using LoRa Module
Let us go through the second example now. In this example, we will be Interfacing SX1278 with STM32 and BME280 sensor to the Sender Circuit. The BME280 is an integrated environmental sensor developed specifically for mobile applications that have high linearity & accuracy for pressure, humidity and temperature measurements.
The Sensor works on I2C Protocol so its I2C Pins, i.e SDA & SCL is connected to PB7 & PB6 respectively. We will send the BME280 Sensor reading wirelessly from STM32 LoRa Sender to STM32 LoRa Receiver.
Check the previous similar project here:
Send Sensor Data Wirelessly using LoRa & Arduino
Project PCB Gerber File & PCB Ordering Online
If you don’t want to assemble the circuit on breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for the STM32 LoRa SX1278 Sender & Receiver is designed using
EasyEDA
online Circuit Schematics & PCB designing tool. The image of the Sender PCB is given below.
Similarly the image of the Receiver PCB is given below.
The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from
ALLPCB
at
1$
only.
Download Gerber File for Sender PCB:
Sender PCB
Download Gerber File for Receiver PCB:
Receiver PCB
You can use this Gerber file to order high quality PCB for this project. To do that visit the
ALLPCB
official website by clicking here:
https://www.allpcb.com/
You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.
After
Technologies used
Hardware components
- Arduino
- STM32
- BME280
- LoRa SX1278
- SX1276
Software & tools
- Arduino IDE
- EasyEDA
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.