Heltec lora example

Heltec lora example DEFAULT

Introduction: Introduction to ESP32 WiFi LoRa

Let's go to the second video of our "Introduction" playlist. This time, we’ll talk about the "ESP32 WiFi LoRa." This one is very special because it has 3 wireless features: Bluetooth 4.2, WiFi 802.11, and the LoRa, which is a type of network with the reach of 3.6 km through a simple antenna. All of this can be used at the same time, which makes it magnificent. We will then introduce the Heltec WiFi LoRa 32, using the Arduino IDE, and then we’ll present a practical example to perform a digital reading and digital performance.

Step 1: Resources Used

1 Heltec WiFi LoRa 32

1 push-button type switch

1 10k ohm resistor

1 relay module

1 Protoboard

Step 2: What Exactly Is the Heltec WiFi LoRa 32?

It is a development board that integrates a SoC ESP32-D0WDQ6.

It has a W25Q32FV Serial Flash Memory (SPI / QPI) chip with approximately 32 megabits (4 megabytes) of storage.

A SX1278 LoRa chip is controlled by ESP32.

The USB-Serial interface uses a CP2102 from Silicon Labs.

In addition to an MCP73831 / 2, it comes with a Lithium Ion (Li-Ion) or Lithium Polymer (Li-Po) battery charge controller.

And it features a regulator AP2112-3.3 to provide 3.3V and a minimum of 600mA.

The board has two crystals, one from 26MHz to the ESP32, and another from 32MHz to the SX1278.

It has a 0.96" OLED display, also controlled by the ESP32.

Step 3: Wiring Diagram of the Heltec WiFi LoRa 32

This same wiring diagram serves both the Heltec chip and the TTGO.

Step 4: Pinout of Heltec WiFi LoRa 32 Card

I point out that if you take the traditional ESP32, unlike this image, it will not have the display and the SX1278, which is the Semtech chip.

Step 5: TTGO X Heltec

Step 6: Circuit

In this circuit, we will detect the push of a button through the GPIO34 (pin 34 of the board), and we will drive the relays of the module through the GPIO22 and 23 (pins 22 and 23), respectively.

Step 7: Plate Installation

Step 8: Source Code


When you're referring to the ESP32 pin, what matters is the GPIO. In this step, therefore, we point out that the pin that is connected to the button, as well as the ones that are connected in the relay module. We also have the variable to store the state of the second relay.

//Pino ligado no botão
int btn1 = 34; //Pinos que são ligados no módulo de relés int rele1 = 22; int rele2 = 23; //variável para guardar o estado do segundo relé boolean rele2_Ativo = false;

Setup ()

The setup () function must be run once before the loop. We set the pins of the buttons as input, relays as output, and we open the serial port, setting the data rate to 9600 bps.

//A função setup() é executada uma vez antes do loop
void setup() { //Seta os pinos dos botões como entrada pinMode(btn1, INPUT); //Seta os pinos dos relés como saída pinMode(rele1, OUTPUT); pinMode(rele2, OUTPUT); //Abre a porta serial, definindo a taxa de dados para 9600 bps Serial.begin(9600); }

Loop ()

As for the loop () function, it executes after setup and is repeated continuously. Check if the button was pressed and, if so, we will print this status on the screen. We then turn on relay 1, invert the state of variable relay2_Active, and then we change the state of relay 2. We wait for 1 second and turn off relay 1.

//A função loop() é executada após o setup e é repetida continuamente
void loop() { if (digitalRead(btn1) == HIGH) //Caso o botão 1 foi pressionado { //Exibe no monitor serial a mensagem entre aspas Serial.println("Botão pressionado"); //Ligamos o relé 1 digitalWrite(rele1, HIGH); //Invertemos o estado da variável rele2_Ativo rele2_Ativo = !rele2_Ativo; //Mudamos o estado do relé 2 digitalWrite(rele2, rele2_Ativo ); //Aguardamos 1 segundo (1000 ms) delay(1000); //Desligamos o relé 1 digitalWrite(rele1, LOW); } }

Step 9: Doing the UpLoad of Code

With the IDE open, open the file with the source code by double-clicking the .ino file or through the File menu.

With Heltec connected to USB, select the menu Tools => Card: "Heltec_WIFI_LoRa_32"

Still in the Tools menu, select the COM port on which the Heltec is connected.

Click the UPLOAD button...

... And wait for the conclusion:

Step 10: Verifying Execution

After recording, we check the execution, click the button to open the Serial Monitor, and then we set the baud rate to 9600.

Press the button, in addition to activating the relays. The following message should appear on the Serial Monitor.

Step 11: Files

Download the files:



Be the First to Share

Did you make this project? Share it with us!


  • 3D Printed Student Design Challenge

    3D Printed Student Design Challenge
  • Lamps and Lighting Contest

    Lamps and Lighting Contest
  • Plastic Challenge

    Plastic Challenge
Sours: https://www.instructables.com/Introduction-to-ESP32-WiFi-LoRa/

Creating a node on The Things Network with a Heltec LoRa 32 using the Arduino IDE

The Heltec Lora 32 is an ESP32 module with an SX1276 chip and a little 0.96″ OLED screen. These are available from the Heltec store on AliExpress. Be careful to buy the new version (V2) to get the new functionality like deep sleep, upgraded FLASH and better LoRa signal.

Heltec Lora 32 v2 in Packet

If you don’t already have the ESP32 boards set up in the Arduino IDE then connect the LoRa antenna and then follow the steps Setting Up the Arduino IDE for the ESP32 Range in this post.

Registering the Device at The Things Network

Sign up for an account here: https://account.thethingsnetwork.org/register
First a new Application has to be created at The Things Network: https://console.thethingsnetwork.org/applications, An example of an application could be a remote greenhouse monitoring system with several sensors that send readings to a gateway.

When the application is setup you need to register a device. On the Application Overview page for your new Application, click ‘register device’

New Device

In the page that opens, type a Device ID, click the arrows icon  on the left of the Device EUI field to automatically create the EUI and then click Register.

In the Device Overview section click the <> symbols next to the  Device EUI, Application EUI and App Key to see data you will use later.

Things Device Overview

Installing the Heltec Development Framework

Heltec have created a ‘framework’ to support their boards within the Arduino IDE. Follow the instructions in Step 1 in the page linked below to install it. Optionally install the Heltec ESP32 Library (Step 2) and test with the Example Sketches.


Installing the LoRaWAN Library

The ESP32_LoRaWAN library can be installed using the Arduino Library manager Sketch >  Include Library > Manage Libraries and search for ESP32_LoRaWAN

Previously the settings for The Things Network were stored in the library files but these are now found in the Sketches themselves. For example

The OTAA.ino example:

/* OTAA para*/
uint8_t DevEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x02 };
uint8_t AppEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t AppKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 };

The band for your region is now chosen using the Tools Menu. This will only appear if you have installed the Heltec Framework mentioned above.

Region Settings


The Lora32 device needs a license key for this library. To get the key, paste the following into a new Sketch (file > new):

uint64_t chipid; void setup() { Serial.begin(115200); } void loop() { chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes). Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes Serial.printf("%08X\n",(uint32_t)chipid);//print Low 4bytes. delay(3000); }

Before you power the module, connect the antenna. The unit can be damaged if you try to transmitted data without an antenna. When the Lora32 is connected to power or USB it starts a demo which includes transmitting LoRa packets so connect an antenna first!

Once connected to USB, upload the sketch above to the board and open the serial monitor. You’ll see something like this:

Chip ID
Copy the Chip ID and paste it into the form here to get a license key: http://www.heltec.cn/search/

Connecting with an Example Sketch

Open the example sketch: File > Examples > ESP32_LoRaWAN > OTAA

Paste the new license in this line:

uint32_t LICENSE[4] = {0xC1670CF8,0x19C71AD5,0x6CE47540,0x8CF267EC};

Upload the Sketch, open the serial monitor and you should see something like this:

Serial LoRaWAN Start Up

In The Things Network website navigate to Applications > **your_application** > Devices > **your_device** and you should see something like this:

Device Status

Your node is now connected to The Things Network!


Heltec Development Environment: https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series (Doc – https://heltec-automation-docs.readthedocs.io/en/latest/esp32/quick_start.html)

Heltec ESP32_LoraWAN library on Github: https://github.com/HelTecAutomation/ESP32_LoRaWAN

If you found something useful above please say thanks by buying me a coffee here...

Post Views:21,006

Sours: https://robotzero.one/heltec-lora32-lorawan-node/
  1. American dad intro memes
  2. Td ameritrade widget ios
  3. Xbox 360 profile editor

In this tutorial we’ll explore the basic principles of LoRa, and how it can be used with the ESP32 for IoT projects using the Arduino IDE. To get you started, we’ll also show you how to create a simple LoRa Sender and LoRa Receiver with the RFM95 transceiver module.

Introducing LoRa

For a quick introduction to LoRa, you can watch the video below, or you can scroll down for a written explanation.

What is LoRa?

LoRa is a wireless data communication technology that uses a radio modulation technique that can be generated by Semtech LoRa transceiver chips.

This modulation technique allows long range communication of small amounts of data (which means a low bandwidth), high immunity to interference, while minimizing power consumption. So, it allows long distance communication with low power requirements.

LoRa Frequencies

LoRa uses unlicensed frequencies that are available worldwide. These are the most widely used frequencies:

  • 868 MHz for Europe
  • 915 MHz for North America
  • 433 MHz band for Asia

Because these bands are unlicensed, anyone can freely use them without paying or having to get a license. Check the frequencies used in your country.

LoRa Applications

LoRa long range and low power features, makes it perfect for battery-operated sensors and low-power applications in:

  • Internet of Things (IoT)
  • Smart home
  • Machine-to-machine communication
  • And much more…

So, LoRa is a good choice for sensor nodes running on a coil cell or solar powered, that transmit small amounts of data.

Keep in mind that LoRa is not suitable for projects that:

  • Require high data-rate transmission;
  • Need very frequent transmissions;
  • Or are in highly populated networks.

LoRa Topologies

You can use LoRa in:

  • Point to point communication
  • Or build a LoRa network (using LoRaWAN for example)

Point to Point Communication

In point to point communication, two LoRa enabled devices talk with each other using RF signals.

For example, this is useful to exchange data between two ESP32 boards equipped with LoRa transceiver chips that are relatively far from each other or in environments without Wi-Fi coverage.

Unlike Wi-Fi or Bluetooth that only support short distance communication, two LoRa devices with a proper antenna can exchange data over a long distance.

You can easily configure your ESP32 with a LoRa chip to transmit and receive data reliably at more than 200 meters distance (you can get better results depending on your enviroment and LoRa settings). There are also other LoRa solutions that easily have a range of more than 30Km.


You can also build a LoRa network using LoRaWAN.

The LoRaWAN protocol is a Low Power Wide Area Network (LPWAN) specification derived from LoRa technology standardized by the LoRa Alliance. We won’t explore LoRaWAN in this tutorial, but for more information you can check the LoRa Alliance and The Things Network websites.

How can LoRa be useful in your home automation projects?

Let’s take a look at a practical application.

Imagine that you want to measure the moisture in your field. Although, it is not far from your house, it probably doesn’t have Wi-Fi coverage. So, you can build a sensor node with an ESP32 and a moisture sensor, that sends the moisture readings once or twice a day to another ESP32 using LoRa.

The later ESP32 has access to Wi-Fi, and it can run a web server that displays the moisture readings.

This is just an example that illustrates how you can use the LoRa technology in your ESP32 projects.

Note: we teach how to build this project on our “Learn ESP32 with Arduino IDE” course. It is Project 4 on the Table of Contents: LoRa Long Range Sensor Monitoring – Reporting Sensor Readings from Outside: Soil Moisture and Temperature. Check the course page for more details.

ESP32 with LoRa

In this section we’ll show you how to get started with LoRa with your ESP32 using Arduino IDE. As an example, we’ll build a simple LoRa Sender and a LoRa Receiver.

The LoRa Sender will be sending a “hello” message followed by a counter for testing purposes. This message can be easily replaced with useful data like sensor readings or notifications.

To follow this part you need the following components:


Instead of using an ESP32 and a separated LoRa transceiver module, there are ESP32 development boards with a LoRa chip and an OLED built-in, which makes wiring much simpler. If you have one of those boards, you can follow: TTGO LoRa32 SX1276 OLED Board: Getting Started with Arduino IDE.

ESP32 built-in LoRa and OLED

You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!

Preparing the Arduino IDE

There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language. Follow one of the next tutorials to prepare your Arduino IDE to work with the ESP32, if you haven’t already.

Installing the LoRa Library

There are several libraries available to easily send and receive LoRa packets with the ESP32. In this example we’ll be using the arduino-LoRa library by sandeep mistry.

Open your Arduino IDE, and go to Sketch > Include Library > Manage Libraries and search for “LoRa“. Select the LoRa library highlighted in the figure below, and install it.

Getting LoRa Tranceiver Modules

To send and receive LoRa messages with the ESP32 we’ll be using the RFM95 transceiver module. All LoRa modules are transceivers, which means they can send and receive information. You’ll need 2 of them.

You can also use other compatible modules like Semtech SX1276/77/78/79 based boards including: RFM96W, RFM98W, etc…

Alternatively, there are ESP32 boards with LoRa and OLED display built-in like the ESP32 Heltec Wifi Module, or the TTGO LoRa32 board.

Before getting your LoRa transceiver module, make sure you check the correct frequency for your location. You can visit the following web page to learn more about RF signals and regulations according to each country. For example, in Portugal we can use a frequency between 863 and 870 MHz or we can use 433MHz. For this project, we’ll be using an RFM95 that operates at 868 MHz.

Preparing the RFM95 Transceiver Module

If you have an ESP32 development board with LoRa built-in, you can skip this step.

The RFM95 transceiver isn’t breadboard friendly. A common row of 2.54mm header pins won’t fit on the transceiver pins. The spaces between the connections are shorter than usual.

There are a few options that you can use to access the transceiver pins.

  • You may solder some wires directly to the transceiver;
  • Break header pins and solder each one separately;
  • Or you can buy a breakout board that makes the pins breadboard friendly.

We’ve soldered a header to the module as shown in the figure below.

This way you can access the module’s pins with regular jumper wires, or even put some header pins to connect them directly to a stripboard or breadboard.


The RFM95 transceiver chip requires an external antenna connected to the ANA pin.

You can connect a “real” antenna, or you can make one yourself by using a conductive wire as shown in the figure below. Some breakout boards come with a special connector to add a proper antenna.

The wire length depends on the frequency:

  • 868 MHz: 86,3 mm (3.4 inch)
  • 915 MHz: 81,9 mm (3.22 inch)
  • 433 MHz: 173,1 mm (6.8 inch)

For our module we need to use a 86,3 mm wire soldered directly to the transceiver’s ANA pin. Note that using a proper antenna will extend the communication range.

Important: you MUST attach an antenna to the module.

Wiring the RFM95 LoRa Transceiver Module

The RFM95 LoRa transceiver module communicates with the ESP32 using SPI communication protocol. So, we’ll use the ESP32 default SPI pins. Wire both ESP32 boards to the corresponding transceiver modules as shown in the next schematic diagram:

Here’s the connections between the RFM95 LoRa transceiver module and the ESP32:

  • ANA: Antenna
  • GND: GND
  • DIO3: don’t connect
  • DIO4: don’t connect
  • 3.3V: 3.3V
  • DIO0: GPIO 2
  • DIO1: don’t connect
  • DIO2: don’t connect
  • GND: don’t connect
  • DIO5: don’t connect
  • RESET: GPIO 14
  • NSS: GPIO 5
  • SCK: GPIO 18
  • MOSI: GPIO 23
  • MISO: GPIO 19
  • GND: don’t connect

Note: the RFM95 transceiver module has 3 GND pins. It doesn’t matter which one you use, but you need to connect at least one.

For practical reasons we’ve made this circuit on a stripboard. It’s easier to handle, and the wires don’t disconnect. You may use a breadboard if you prefer.

The LoRa Sender Sketch

Open your Arduino IDE and copy the following code. This sketch is based on an example from the LoRa library. It transmits messages every 10 seconds using LoRa. It sends a “hello” followed by a number that is incremented in every message.

View raw code

Let’s take a quick look at the code.

It starts by including the needed libraries.

Then, define the pins used by your LoRa module. If you’ve followed the previous schematic, you can use the pin definition used in the code. If you’re using an ESP32 board with LoRa built-in, check the pins used by the LoRa module in your board and make the right pin assignment.

You initialize the counter variable that starts at 0;

In the setup(), you initialize a serial communication.

Set the pins for the LoRa module.

And initialize the transceiver module with a specified frequency.

You might need to change the frequency to match the frequency used in your location. Choose one of the following options:

LoRa transceiver modules listen to packets within its range. It doesn’t matter where the packets come from. To ensure you only receive packets from your sender, you can set a sync word (ranges from 0 to 0xFF).

Both the receiver and the sender need to use the same sync word. This way, the receiver ignores any LoRa packets that don’t contain that sync word.

Next, in the loop() you send the LoRa packets. You initialize a packet with the beginPacket() method.

You write data into the packet using the print() method. As you can see in the following two lines, we’re sending a hello message followed by the counter.

Then, close the packet with the endPacket() method.

After this, the counter message is incremented by one in every loop, which happens every 10 seconds.

Testing the Sender Sketch

Upload the code to your ESP32 board. Make sure you have the right board and COM port selected.

After that, open the Serial Monitor, and press the ESP32 enable button. You should see a success message as shown in the figure below. The counter should be incremented every 10 seconds.

The LoRa Receiver Sketch

Now, grab another ESP32 and upload the following sketch (the LoRa receiver sketch). This sketch listens for LoRa packets with the sync word you’ve defined and prints the content of the packets on the Serial Monitor, as well as the RSSI. The RSSI measures the relative received signal strength.

View raw code

This sketch is very similar to the previous one. Only the loop() is different.

You might need to change the frequency and the sycnword to match the one used in the sender sketch.

In the loop() the code checks if a new packet has been received using the parsePacket() method.

If there’s a new packet, we’ll read its content while it is available.

To read the incoming data you use the readString() method.

The incoming data is saved on the LoRaData variable and printed in the Serial Monitor.

Finally, the next two lines of code print the RSSI of the received packet in dB.

Testing the LoRa Receiver Sketch

Upload this code to your ESP32. At this point you should have two ESP32 boards with different sketches: the sender and the receiver.

Open the Serial Monitor for the LoRa Receiver, and press the LoRa Sender enable button. You should start getting the LoRa packets on the receiver.

Congratulations! You’ve built a LoRa Sender and a LoRa Receiver using the ESP32.

Taking It Further

Now, you should test the communication range between the Sender and the Receiver on your area. The communication range greatly varies depending on your environment (if you live in a rural or urban area with a lot of tall buildings). To test the communication range you can add an OLED display to the LoRa receiver and go for a walk to see how far you can get a communication (this is a subject for a future tutorial).

In this example we’re just sending an hello message, but the idea is to replace that text with useful information.

Wrapping Up

In summary, in this tutorial we’ve shown you the basics of LoRa technology:

  • LoRa is a radio modulation technique;
  • LoRa allows long-distance communication of small amounts of data and requires low power;
  • You can use LoRa in point to point communication or in a network;
  • LoRa can be especially useful if you want to monitor sensors that are not covered by your Wi-Fi network and that are several meters apart.

We’ve also shown you how to build a simple LoRa sender and LoRa receiver. These are just simple examples to get you started with LoRa. We’ll be adding more projects about this subject soon, so stay tuned!

You may also like reading:

This is an excerpt from our course: Learn ESP32 with Arduino IDE. If you like ESP32 and you want to learn more, we recommend enrolling in Learn ESP32 with Arduino IDE course.

Thanks for reading.

Sours: https://randomnerdtutorials.com/esp32-lora-rfm95-transceiver-arduino-ide/

Introduction: ESP32 Long Distance - LoRaWan

In this article, we are going to discuss LoRaWAN, a network that travels with little energy. But for just how far? With the chip I use in the video, the ESP32, the control distance reaches 3.6 kilometers. So today, we talk about the characteristics of the chip and the LoRa network, which was practically made for IoT (Internet of Things).

In the assembly, in the example of Heltec, with the ESP32 plus the SX1276 chip, we have Sender sending the data packet to the Receiver. In the green head device, the Receiver, we have the signal that is at -9dB. This is because the antennas are practically glued and extremely close, but as you move them away from each other, you can see that the signal strength decreases, reaching -124dB when you stop to receive the information. In the same display, Rx9 bytes indicate the packet size and Hello is the string that the yellow cable device, Sender, is sending. In Sender, we also have a LED flashing at 500 milliseconds.

Step 1: ESP32 LoRaWan

Concerning my ESP32 cards, I bought them with the LoRa chips already built-in. These development kits already come with display, which I consider advantageous. So we dismantled the kit. Under the device, we can see the information on the SX1276 chip.

It is important to remember that the ESP32 has three chips: Flash memory, Espressif, which is the processor of Tensilica, and also there is a USB to Serial Ttl, of Silicon Labs. In the case of this development kit, we also have a fourth chip, which is the SX1276.

Step 2: How the LoRa Network Is Used

To understand the use of the network, we have the LoRa chips communicating with each other, measuring geographic position, temperature, pressure, humidity, and all the information that is analyzed through the IoT in the LoRa network. We then have a hub, the Gateway, which receives all these signals. This is going to enter the TCP / IP network LoRaWAN SSL and then follow to a server side, a more robust thing, IBM Watson, Amazon, in short, the data is processed at another level.

Step 3: Key Features of LoRa Technology and LoRaWAN Protocol

Here, I show some characteristics of the LoRa technology and the LoRaWAN protocol.

I emphasize that the idea of this network LoRa is not for you to send multimedia content, but to send packages of data of reading.

LoRaWAN Protocol

LoRaWAN is a protocol specification built upon the LoRa technology developed by the LoRa Alliance. It uses unlicensed radio spectrum in the Industrial, Scientific, and Medical (ISM) bands to enable low power and wide area communication between remote sensors and gateways connected to the network. This standards-based approach to building an LPWAN enables the rapid deployment of public or private IoT networks anywhere using hardware and software that is bi-directional, secure, interoperable, and mobile, which provides a precise location and works the way you would expect it to.

Step 4: CHIP Sx1276

Then, by disassembling the development kit, we unscrew the display and locate the LoRa chip, created by the French company Semtech. Here, I have a table taken from the Datasheet with information of this device on the 1276, 1277, 1278, and 1279 models. The difference is more in frequency.

Step 5: ESP32 LoRa X ESP32 WiFi

Comparing the traditional ESP32 with ESP32 LoRa, we again point out that the traditional has three chips, while LoRa has four. This fourth chip, in this case, is the sx1276.

It is connected via the SPI port. As for OLED Flat, it is connected to i2c.

Step 6: ESP32 LoRa Pinout

It is important to note the pins that are already occupied.

Step 7: Test

ESP32 LoRaWAN TTGO To perform the test, we took the chips from TTGO, put on an antenna and battery, and walked out. Right away, we found it running at 915 MHz. We tested the 433 MHz as well.

We set up a packet to send Sender to the Receiver. The second will receive this packet and measure the signal strength in dB, which will show on the display. In this way, it will be possible for you to perform a test. I also intend to do this using my drone, which travels up to 7 kilometers, to see how far I can get.

Step 8: ESP32 LoRaWAN - Heltec

This is Heltec's model, which is at 433 MHz and works very well. If you are looking to buy an ESP32, I recommend this brand because it has a Lib inside the Arduino IDE, which makes handling easier.

Step 9: Lib and Heltec Examples

Heltec examples are in GitHub.


Below is the path to locate the source code of your computer after installation.

C: \ Program Files (x86) \ Arduino \ hardware \ heltec \ esp32 \ libraries \ LoRa \ examples \ OLED_LoRa_Sender

Step 10: Manual PDF

I translated the manual from Portuguese and will deliver it to you in a PDF file.

Register to my email list:

Subscribe to the link: pdf.fernandok.com

You will receive a message confirming your application. Check your inbox, as well as your spam box, among others.

With the confirmed registration, I will send you a second email with the download link from the manual: "How to install Arduino IDE ESP32 LoRa - Heltec on Windows".

Step 11: Source Code

Today, we have two .INO programs, the Sender and the Receiver.

Sender and Receiver

First, I declare the SPI pins and set the radio frequency, that is, I make all the necessary statements.

#include <spi.h> //responsável pela comunicação serial
#include <lora.h> //responsável pela comunicação com o WIFI Lora #include <wire.h> //responsável pela comunicação i2c #include "SSD1306.h" //responsável pela comunicação com o display #include "images.h" //contém o logo para usarmos ao iniciar o display // Definição dos pinos #define SCK 5 // GPIO5 -- SX127x's SCK #define MISO 19 // GPIO19 -- SX127x's MISO #define MOSI 27 // GPIO27 -- SX127x's MOSI #define SS 18 // GPIO18 -- SX127x's CS #define RST 14 // GPIO14 -- SX127x's RESET #define DI00 26 // GPIO26 -- SX127x's IRQ (Interrupt Request) #define BAND 915E6 //Frequencia do radio - podemos utilizar ainda : 433E6, 868E6, 915E6 #define PABOOST true

Sender: OLED_LoRa_Sender.ino

Here, I have the display that is connected to the i2c pins and the strings.

//variável responsável por armazenar o valor do contador (enviaremos esse valor para o outro Lora)
unsigned int counter = 0; //parametros: address,SDA,SCL SSD1306 display(0x3c, 4, 15); //construtor do objeto que controlaremos o display String rssi = "RSSI --"; String packSize = "--"; String packet ;

Setup: OLED_LoRa_Sender.ino

Here, we configure the pins as output, as well as the actions of the display. We initiate LoRa communication and configure the pins that will be used by the library.

Highlight: Every time you connect the ESP32 to the LoRa network, it checks if the antenna is plugged into the Pigtail connector, because if you connect to the USB without it being connected to the antenna, you can burn the transmitter chip.

void setup()
{ //configura os pinos como saida pinMode(16,OUTPUT); //RST do oled pinMode(25,OUTPUT); digitalWrite(16, LOW); // reseta o OLED delay(50); digitalWrite(16, HIGH); // enquanto o OLED estiver ligado, GPIO16 deve estar HIGH display.init(); //inicializa o display display.flipScreenVertically(); display.setFont(ArialMT_Plain_10); //configura a fonte para um tamanho maior //imprime o logo na tela logo(); delay(1500); display.clear(); //apaga todo o conteúdo da tela do display SPI.begin(SCK,MISO,MOSI,SS); //inicia a comunicação serial com o Lora LoRa.setPins(SS,RST,DI00); //configura os pinos que serão utlizados pela biblioteca (deve ser chamado antes do LoRa.begin) //inicializa o Lora com a frequencia específica. if (!LoRa.begin(BAND,PABOOST)) { display.drawString(0, 0, "Starting LoRa failed!"); display.display(); //mostra o conteúdo na tela while (1); } //indica no display que inicilizou corretamente. display.drawString(0, 0, "LoRa Initial success!"); display.display(); //mostra o conteúdo na tela delay(1000); }

Loop: OLED_LoRa_Sender.ino

Here's how to assemble a package and turn on the LED.

void loop()
{ //apaga o conteúdo do display display.clear(); display.setTextAlignment(TEXT_ALIGN_LEFT); display.setFont(ArialMT_Plain_16); display.drawString(0, 0, "Sending packet: "); display.drawString(40, 26, String(counter)); display.display(); //mostra o conteúdo na tela //beginPacket : abre um pacote para adicionarmos os dados para envio LoRa.beginPacket(); //print: adiciona os dados no pacote LoRa.print("hello "); LoRa.print(counter); //endPacket : fecha o pacote e envia LoRa.endPacket(); //retorno= 1:sucesso | 0: falha //beginPacket : abre um pacote para adicionarmos os dados para envio LoRa.beginPacket(); //print: adiciona os dados no pacote LoRa.print("hello "); LoRa.print(counter); //endPacket : fecha o pacote e envia LoRa.endPacket(); //retorno= 1:sucesso | 0: falha //incrementa uma unidade no contador counter++; digitalWrite(25, HIGH); // liga o LED indicativo delay(500); // aguarda 500ms digitalWrite(25, LOW); // desliga o LED indicativo delay(500); // aguarda 500ms }

Print - Logo: OLED_LoRa_Sender.ino

This function only prints the logo on the display.

//essa função apenas imprime o logo na tela do display
void logo() { //apaga o conteúdo do display display.clear(); //imprime o logo presente na biblioteca "images.h" display.drawXbm(0,5,logo_width,logo_height,logo_bits); display.display(); }

Setup: OLED_LoRa.Reciver.ino

We start LoRa here with the specific frequency, we point the correct initialization in the display, and we enable LoRa to receive the data sent by Sender. We also check the receipt of the package.

//inicializa o Lora com a frequencia específica.
if (!LoRa.begin(BAND,PABOOST)) { display.drawString(0, 0, "Starting LoRa failed!"); display.display(); while (1); } //indica no display que inicilizou corretamente. display.drawString(0, 0, "LoRa Initial success!"); display.drawString(0, 10, "Wait for incomm data..."); display.display(); delay(1000); //LoRa.onReceive(cbk); LoRa.receive(); //habilita o Lora para receber dados } void loop() { //parsePacket: checa se um pacote foi recebido //retorno: tamanho do pacote em bytes. Se retornar 0 (ZERO) nenhum pacote foi recebido int packetSize = LoRa.parsePacket(); //caso tenha recebido pacote chama a função para configurar os dados que serão mostrados em tela if (packetSize) { cbk(packetSize); //função responsável por recuperar o conteúdo do pacote recebido delay(10); } }

Print on OLED: OLED_LoRa.Reciver.ino

Here, we configure the information that will appear on the display.

//função responsável por configurar os dados que serão exibidos em tela.
//RSSI : primeira linha //RX packSize : segunda linha //packet : terceira linha void loraData(){ display.clear(); display.setTextAlignment(TEXT_ALIGN_LEFT); display.setFont(ArialMT_Plain_16); display.drawString(0 , 18 , "Rx "+ packSize + " bytes"); display.drawStringMaxWidth(0 , 39 , 128, packet); display.drawString(0, 0, rssi); display.display(); }

Step 12:

Be the First to Share

Did you make this project? Share it with us!


  • Back to School: Student Design Challenge

    Back to School: Student Design Challenge
  • Micro:bit Contest

    Micro:bit Contest
  • Lamps and Lighting Contest

    Lamps and Lighting Contest
Sours: https://www.instructables.com/ESP32-Long-Distance-LoRaWan/

Lora example heltec

Heltec ESP32+LoRa Series Quick Start¶


Before all operation, please confirm whether the , and has been installed correctly. If not, please refer to this two articles establish serial connection and Install Git and Arduino IDE.

There are two methods to install the development framework, choose one of they:

Via Git¶

  • For Windows:

  • For MacOS:

  • For Linux

    • Debian/Ubuntu:

    • Fedora:

    • OpenSUSE:


This section for verifying whether you can program with Arduino or not. Now, The USB cable connects to Heltec ESP32 board, then select your serial port which is connected to Heltec ESP32 board.

Select a demo example, compile and upload.

Execute an example¶

Correctly select a board and relevant options in the menu:


Then select an example likes


Compile & Upload


New a Heltec ESP32 program¶

Open Arduino IDE, create a new file, then copy the below code.

#include<heltec.h>// the setup routine runs once when starts upvoidsetup(){// Initialize the Heltec ESP32 objectHeltec.begin(true/*DisplayEnable Enable*/,true/*LoRa Disable*/,true/*Serial Enable*/,true/*PABOOST Enable*/,470E6/**/);}// the loop routine runs over and over again forevervoidloop(){}

compile it and upload, the screen (if this board has a screen) will show and Arduino’s serial monitor will print something, it means Heltec ESP32 board is running successfully!

© Copyright 2019, Heltec. Revision .

Built with Sphinx using a theme provided by Read the Docs.
Sours: https://heltec-automation-docs.readthedocs.io/en/latest/esp32/quick_start.html
Heltec LoRa ESP32 and GPS Module Range Test

Heltec_ESP32 Library

English | 简体中文

This library must work with Heltec ESP32 develop framework! A detail document about how to install Heltec ESP32 development framework and this library available here:



  1. How to install this library

  2. How to use this library

  3. API Reference

  4. Relevant Resources

How to install this library

Use Arduino Library Manager

Open Arduino IDE, then Select ->-> Search and install it. image


Use Git

Firstly, make sure git and the Arduino IDE have been installed first. If not, please refer How to install Git and Arduino. When Arduino is installed correctly, you will find a folder in "Username/Documents/Arduino/Library". this library must in this path!

Open "Git bash" in path , and input:

You will see such a new folder in your library path, install done.


How to use this library

This library requires the Heltec ESP32 develop framework!

A detailed step by step instructions to execute some examples available here:


API Reference



Relevant Resources

If there is a "Limited" folder in the resources page, it means the product have limited resources that not public by default, refer to this document to download: Get Limited Technical Resources.


Please make sure use a high-quality Micro USB cable, it will reduce many problems.

Summary of common problems


这个Arduino库必须配合Heltec ESP32编译环境一起使用!完整的“编译环境 + 库”的的教程可以参考这里:



  1. 安装方法

  2. 怎样使用这个库

  3. API参考

  4. 相关资源



打开Arduino IDE, 选择->->,打开“库管理器” 搜索并安装. image



*首先,请确保和都已经正确安装。如果没有,请参考这里的安装方法怎样安装Git和Arduino IDE。 *


在“文档/Arduino/libraries”路径下打开"Git bash",输入:











Sours: https://github.com/HelTecAutomation/Heltec_ESP32

Now discussing:

Heltec WiFi LoRa 32 V2 Arduino Guide

Introduction to Guide


Before we begin, please make sure you've followed the steps from this guide, which goes over some initial setup steps.

Objective and Requirements

In this guide, you will learn:

  • How to setup your environment
  • How to program a basic application that will send packets over the Helium Network
  • Verify real-time packets sent to the Helium Console via Hotspot that's in range

For this example, you will need the following:



Hardware Setup

Adding the Antenna

Your board should have come with a U.FL antenna. All you have to do is attache it to the U.FL port as shown in the image at the top of the guide.

Connect Board

Next, lets connect our board to our computer with a USB 2.0 A-Male to Micro B cable.

Software Setup

Getting the Arduino IDE

Download and install the latest version of Arduino IDE for your preferred OS.

Arduino Board Support

The Heltec WiFi LoRa 32 V2 requires one Arduino board support package. Follow the instructions below to install.


To install, open your Arduino IDE:

  1. Navigate to (File > Preferences), (Arduino > Preferences) on MacOS.
  2. Find the section at the bottom called Additional Boards Manager URLs:
  1. Add this URL in the text box:
  1. Close the Preferences windows

Next, to install this board support package:

  1. Navigate to (Tools > Boards > Boards Manager...)
  2. Search for Heltec ESP32
  3. Select the newest version and click Install

Arduino Library

To communicate with Helium's LoRaWAN network, we'll need to install two Arduino libraries.

Heltec ESP32

To install, open your Arduino IDE:

  1. Navigate to Library Manager (Sketch > Include Library > Manage Libraries).
  2. In the search box, type Heltec ESP32 into the search, select the version shown below, and click Install.

Heltec ESP32 LoRaWAN

Download this find into the directory below and unzip.

Install Serial Driver

Find Directions on Heltec's website here.

Select Board

Arduino IDE:

  1. Select Tools -> Board: -> WiFi LoRa 32(V2)

Obtain Heltec License Key

Upload GetChipID example

Arduino IDE:

  1. Select File -> Examples -> ESP32 -> ChipID -> GetChipID
  2. Select Tools -> Port: "COM# or ttyACM#"
  3. Select Sketch -> Upload
  4. Wait for Done uploading message
  5. Select Tools -> Serial Monitor Serial Monitor Window
  6. Select 115200 baud from bottom right dropdown.
  7. You should see something that looks like this every second
  8. Save this Chip ID

Obtain License Key with Chip ID

  1. Go to resource.heltec.cn/search
  2. Enter ChipID
  3. Save license field, will look like

Programming Example Sketch

Now that we have the required Arduino board support and library installed, lets program the board with the provided example sketch.

To create a new Arduino sketch, open your Arduino IDE, (File > New). Next, replace the template sketch with the sketch found here, copy and paste the entirety of it.

Next we'll need to fill in the AppEUI(msb), DevEUI(msb), and AppKey(msb), in the sketch, which you can find on the device details page on Console. Be sure to use the formatting buttons to match the endianess and formatting required for the sketch, shown below.

At the top of the sketch, replace the three FILL_ME_IN fields, with the matching field from Console, example shown below.


Selecting Port

Next, we need to select the correct Serial port in the Arduino IDE. Navigate to (Tools > Port: COM#/ttyACM#). You will also see either COM# or /dev/ttyACM# depending on whether you are on Windows, Mac, or Linux. If you do not see a port, please visit the Drivers section in Heltec's docs to make sure you have what's needed for your operating system.

Select LoRaWAN Region

The last step before we upload our sketch is to select the correct LoRaWAN Region, navigate to (Tools > LoRaWAN Region: > REGION_US915).

Select Uplink Mode

The last step before we upload our sketch is to select the LoRaWAN Uplink Mode, navigate to (Tools > LoRaWAN Uplink Mode: > UNCONFIRMED).

Required Change to Default DataRate

In this example sketch, ADR is turned off, therefore you must manually set the desired data rate for your payload size manually. This library uses a default data rate that is not supported by the Helium Network so you must change it to one in the following range DR_0 - DR_4. To do this change the default data rate on line 20 in the file found below for your operating system

Change line 20 to:

Upload Sketch

We're finally ready to upload our sketch to the board. In the Arduino IDE, click the right arrow button, or navigate to (Sketch > Upload), to build and upload your new firmware to the board. You should see something similar to the image below at the bottom of your Arduino IDE, when the upload is successful.


Viewing Serial Output

When your firmware update completes, the board will reset, and begin by joining the network. Let's use the Serial Monitor in the Arduino IDE to view the output from the board. We first need to select the serial port again, but this time it will be a different port than the one we selected to communicate with the bootloader. Once again, navigate to (Tools > Port: COM#/ttyACM#), but make sure the serial device, either COM# or ttyACM#, is different! Next navigate to (Tools > Serial Monitor), you should begin to see output similar to below.


Your device may take several minutes to join and begin to send uplink packets because the library is designed to work in several LoRaWAN regions and networks. Because of this, the firmware will attempt different sub-bands until it is successful. If you would like to change the default channel mask in the library to speed up this process you can make the following change below in the file specified.

Change lines 343-348 to:

Now let's head back to Helium Console and look at our device page, you should see something similar to the screenshot below.

Congratulations! You have just transmitted data on the Helium network! The next step is to learn how to use your device data to build applications, visit our Integrations docs here.

Sours: https://docs.helium.com/use-the-network/devices/development/heltec/wifi-lora-32-v2/arduino/

4495 4496 4497 4498 4499