This guide will show you step by step how to transmit LoRaWAN packets using a longfi-arduino sketch on a Heltec WiFi LoRa 32 V2.
{% hint style="warning" %} Before we begin, please make sure you've followed the steps from this guide, which goes over some initial steps to add your device to Console. {% endhint %}
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:
- Heltec WiFi LoRa 32 V2
- Micro USB Type B Cable - Example
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.
Next, lets connect our board to our computer with a USB 2.0 A-Male to Micro B cable.
Download and install the latest version of Arduino IDE for your preferred OS.
The Heltec WiFi LoRa 32 V2 requires one Arduino board support package. Follow the instructions below to install.
To install, open your Arduino IDE:
- Navigate to (File > Preferences), (Arduino > Preferences) on MacOS.
- Find the section at the bottom called Additional Boards Manager URLs:
- Add this URL in the text box:
http://resource.heltec.cn/download/package_heltec_esp32_index.json
- Close the Preferences windows
Next, to install this board support package:
- Navigate to (Tools > Boards > Boards Manager...)
- Search for Heltec ESP32
- Select the newest version and click Install
To communicate with Helium's LoRaWAN network, we'll need to install two Arduino libraries.
To install, open your Arduino IDE:
- Navigate to Library Manager (Sketch > Include Library > Manage Libraries).
- In the search box, type Heltec ESP32 into the search, select the version shown below, and click Install.
Download this find into the directory below and unzip.
linux: /home/{user}/Arduino/libraries
windows: Documents\Arduino\libraries
mac os: Documents/Arduino/libraries
Find Directions on Heltec's website here.
Arduino IDE:
- Select Tools -> Board: -> WiFi LoRa 32(V2)
Arduino IDE:
- Select File -> Examples -> ESP32 -> ChipID -> GetChipID
- Select Tools -> Port: "COM# or ttyACM#"
- Select Sketch -> Upload
- Wait for Done uploading message
- Select Tools -> Serial Monitor Serial Monitor Window
- Select 115200 baud from bottom right dropdown.
- You should see something that looks like this every second
ESP32 Chip ID = ############
- Save this Chip ID
- Go to resource.heltec.cn/search
- Enter ChipID
- Save license field, will look like
0x########,0x#########,0x########,0x########
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.
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.
The last step before we upload our sketch is to select the correct LoRaWAN Region, navigate to (Tools > LoRaWAN Region: > REGION_US915).
The last step before we upload our sketch is to select the LoRaWAN Uplink Mode, navigate to (Tools > LoRaWAN Uplink Mode: > UNCONFIRMED).
The Helium network does not fully support ADR (Adapative Data Rate), read more here. 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
linux: /home/{user}/Arduino/libraries/ESP32_LoRaWAN-master/src/ESP32_LoRaWAN.cpp
windows: Documents\Arduino\libraries\ESP32_LoRaWAN-master\src\ESP32_LoRaWAN.cpp
mac os: Documents/Arduino/librariesESP32_LoRaWAN-master/src/ESP32_LoRaWAN.cpp
Change line 20 to:
#define LORAWAN_DEFAULT_DATARATE DR_3
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.
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:
channelsMaskTemp[0] = 0xFF00;
channelsMaskTemp[1] = 0x0000;
channelsMaskTemp[2] = 0x0000;
channelsMaskTemp[3] = 0x0000;
channelsMaskTemp[4] = 0x0002;
channelsMaskTemp[5] = 0x0000;
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.