[IoT EDGE V.3 Board] LoRa Communication Test. , Heltec CubeCell Capsule HDC1080

Supphakarin Phoruangrong
4 min readMay 17, 2021

--

Device

  • IoT EDGE V.3 Board
  • LoRa Shield Dragino V.1.4
  • CubCell Capsule HDC1080 (Temperature and Humidity)

Software

Library for Arduino IDE

Model Test

  • IoT EDGE V.3 Board + LoRa Shield (Receive)
  • CubCell Capsule HDC1080 (Node)

Source Code

  • IoT EDGE V.3 + LoRa, Temp.Humidity (Download)

Explain

ในการทดสอบการใช้งานบอร์ด IoT EAGE V.3 ในบทความนี้ความจะทดสอบการสื่อสารแบบ LoRa ใช้ในการส่งข้อมูลระหว่าง ตัวรับ(Receive) และ ตัวส่งข้อมูล(Node) ในตัวของตัวส่งมี Temp.Humidity sensor ของ Heltec HDC1080
ความถี่ใช้งาน 915 MHz หลักการในการส่งใช้แบบ LoRa Modulation

Method

  1. Install CubCell Capsule Heltec
  • Open Arduino 2.0 Beta → File → Preferences → Copy URL → Press on Additional boards manager URLs : → Ok

https://resource.heltec.cn/download/package_CubeCell_index.json

2.Search Board

  • Tools → Board → Boards Manager → click → Search : CubeCell → Install

3.เขียน Code

IoT EDGE V.3 + LoRa Shield

#include <SPI.h>
#include <LoRa.h>
#define ss 2
#define reset 17
#define dio0 26
void setup() {
Serial.begin(115200);
while (!Serial);
LoRa.setPins(ss, reset, dio0);
Serial.println("LoRa Receiver");
if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}

Capsule HDC 1080

#include "LoRaWan_APP.h"#include "Arduino.h"#include <Wire.h>#include "HDC1080.h"#include "LoRaWan_APP.h"#include "Arduino.h"/** set LoraWan_RGB to 1,the RGB active in loraWan* RGB red means sending;* RGB green means received done;*/#ifndef LoraWan_RGB#define LoraWan_RGB 0#endif#define RF_FREQUENCY                                915000000 // Hz#define TX_OUTPUT_POWER                             14        // dBm#define LORA_BANDWIDTH                              0         // [0: 125 kHz,//  1: 250 kHz,//  2: 500 kHz,//  3: Reserved]#define LORA_SPREADING_FACTOR                       7         // [SF7..SF12]#define LORA_CODINGRATE                             1         // [1: 4/5,//  2: 4/6,//  3: 4/7,//  4: 4/8]#define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx#define LORA_SYMBOL_TIMEOUT                         0         // Symbols#define LORA_FIX_LENGTH_PAYLOAD_ON                  false#define LORA_IQ_INVERSION_ON                        false#define RX_TIMEOUT_VALUE                            1000#define BUFFER_SIZE                                 30 // Define the payload size herechar txpacket[BUFFER_SIZE];char rxpacket[BUFFER_SIZE];static RadioEvents_t RadioEvents;double txNumber;int16_t rssi,rxSize;void  DoubleToString( char *str, double double_num,unsigned int len);HDC1080 hdc1080;void setup() {Serial.begin(115200);txNumber=0;rssi=0;Radio.Init( &RadioEvents );Radio.SetChannel( RF_FREQUENCY );Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,LORA_SPREADING_FACTOR, LORA_CODINGRATE,LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );}void loop(){hdc1080.begin(0x40);int temperature = (hdc1080.readTemperature());int humidity = (hdc1080.readHumidity());hdc1080.end();// Serial.println(temperature);delay(1000);txNumber += 0.01;sprintf(txpacket,"%s","Teamp. = ");  //start a packagesprintf(txpacket+strlen(txpacket)," %d / ",temperature); //add to the end of packageDoubleToString(txpacket,txNumber,3);     //add to the end of packageturnOnRGB(COLOR_SEND,0); //change rgb colorSerial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out}/*** @brief  Double To String* @param  str: Array or pointer for storing strings* @param  double_num: Number to be converted* @param  len: Fractional length to keep* @retval None*/void  DoubleToString( char *str, double double_num,unsigned int len) {double fractpart, intpart;fractpart = modf(double_num, &intpart);fractpart = fractpart * (pow(10,len));sprintf(str + strlen(str),"%d", (int)(intpart)); //Integer partsprintf(str + strlen(str), ".%d", (int)(fractpart)); //Decimal part}

4. Code Upload

IoT EDGE V.3 + LoRa Shield (Board →ESP32 → ESP32DeV Module)

Capsule HDC 1080 (Board →CubeCell → CubeCell-Capsule)

5. ดูข้อมูลจาก Serial Monitor ของ IoT EDGE V.3

Reference

--

--