Introduction: Installing ESP32 LoRa on the Arduino IDE
Today, I am going to talk about the installation of ESP32 LoRa in the Arduino IDE. I have already talked about this subject before, but I think it needs an update. I will introduce you the installation of the ESP32 LoRa libraries step by step, both for LoRa communication and for the display. Also, I will show a sample source code using some LoRa and display functions. In this Project, we use the Heltec microcontroller.
Step 1: Demonstration
Step 2: Resources Used
ESP32 LoRa Heltec
Micro USB to USB cable
Step 3: For Those Who Have Already Installed Esp32
You must delete the following folders:
Step 4: Steps Followed in the Video
1. Installation of the ESP32 card (The Heltec_WiFi_LoRa_32 and Heltec_WiFi_Kit_32 cards will also be installed)
1.1 - In your Arduino IDE go to:
Arduino -> Preferences
In Additional URLs for Cards Managers, add the url:
https://dl.espressif.com/dl/package_esp32_index.json
1.2 - In your Arduino IDE go to:
Tools -> Cards -> Cards Manager
Search for: esp32
Install the package described as: esp32 by Espressif Systems
2. Installation of Silicon Labs CP210x USB drivers for UART Bridge VCP.
Go to: https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
Download and install the driver compatible with your OS
3. LoRa library installation
In your IDE Arduino go to:
Sketch -> Include library -> Manage libraries
Search for: LoRa
Install the library described as: LoRa (distributed by Sandeep Mistry)
4. Installing the SSD1306 library for the display
In your IDE Arduino go to:
Sketch -> Include library -> Manage libraries
Search for: SSD1306
Install the library described as: ESP8266 and ESP32 Oled Driver for SSD1306 display
Step 5: Code: Declarations and Variables
#include #include // Pinos do display (comunicação i2c) const int DISPLAY_ADDRESS_PIN = 0x3c; const int DISPLAY_SDA_PIN = 4; const int DISPLAY_SCL_PIN = 15; const int DISPLAY_RST_PIN = 16; // Pinos do lora (comunicação spi) const int LORA_SCK_PIN = 5; const int LORA_MISO_PIN = 19; const int LORA_MOSI_PIN = 27; const int LORA_SS_PIN = 18; const int LORA_RST_PIN = 15; const int LORA_DI00_PIN = 26; // Frequência de comunicação const int BAND = 433E6; // Contador de pacotes enviados via lora int counter = 0;
// Altura da fonte (correspondente a fonte ArialMT_Plain_16) const int fontHeight = 16; // Objeto do display SSD1306 display(DISPLAY_ADDRESS_PIN, DISPLAY_SDA_PIN, DISPLAY_SCL_PIN);
Step 6: Code: Setup
void setup()
{
// Iniciamos a serial com velocidade de 9600
Serial.begin(9600);
// Exibimos "Starting..." na serial (debug)
Serial.println("Starting...");
// Iniciamos o display
if(!displayBegin())
{
// Se não deu certo, exibimos falha de display na serial
Serial.println("Display failed!");
// E deixamos em loop infinito
while(1);
}
// Configuramos o posicionamento da tela, fonte e o alinhamento do texto
displayConfig();
// Iniciamos o lora
if(!loraBegin())
{
// Se não deu certo, exibimos falha de lora na serial
Serial.println("LoRa failed!");
// E deixamos em loop infinito
while (1);
}
}
Step 7: Code: Loop
void loop()
{
// Variável usada para indicar em qual linha o cursor deverá estar quando uma mensagem no display for exibida
int line;
// Limpamos o display
display.clear();
// Iniciamos na primeira linha (zero)
line = 0;
// Escrevemos a mensagem "Sending packet: " na primeira linha
display.drawString(0, line, "Sending packet: ");
// Mudamos para a segunda linha
line++;
// Escrevemos o incrementador "counter" na segunda linha
display.drawString(0, line * fontHeight, String(counter));
// Exibimos as alterações no display
display.display();
// Enviamos um pacote com a mensagem "hello" concatenado com o número "counter"
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
// Incrementamos o contador
counter++;
// Aguardamos 1 segundo
delay(1000);
}
Step 8: Code: Display Begin and Display Config
// Função que inicializa o display
bool displayBegin()
{
// Reiniciamos o display
pinMode(DISPLAY_RST_PIN, OUTPUT);
digitalWrite(DISPLAY_RST_PIN, LOW);
delay(1);
digitalWrite(DISPLAY_RST_PIN, HIGH);
delay(1);
return display.init();
}
// Função que faz algumas configuções no display
void displayConfig()
{
// Invertemos o display verticalmente
display.flipScreenVertically();
// Setamos a fonte
display.setFont(ArialMT_Plain_16);
// Alinhamos a fonta à esquerda
display.setTextAlignment(TEXT_ALIGN_LEFT);
}
Step 9: Code: LoraBegin
// Função que inicializa o radio lora
bool loraBegin()
{
// Iniciamos a comunicação SPI
SPI.begin(LORA_SCK_PIN, LORA_MISO_PIN, LORA_MOSI_PIN, LORA_SS_PIN);
// Setamos os pinos do lora
LoRa.setPins(LORA_SS_PIN, LORA_RST_PIN, LORA_DI00_PIN);
// Iniciamos o lora
return LoRa.begin(BAND);
}





