Hi Rui, I’m using Heltec Wifi Lora 32 and SHT20 sensor for my Lora sender project (with a display). without display code in the project, the sensor worked fine and after the display code were added, the sensor did not showed a correct value. Below is the code that I used (bold font for display):
//OLED #include <Adafruit_SSD1306.h> #include <Adafruit_GFX.h> #include <Adafruit_SPITFT.h> #include <Adafruit_SPITFT_Macros.h> #include <gfxfont.h> //Oled display //SHT20 #include <Wire.h> //allows communication with I2C #include "DFRobot_SHT20.h" //SHT20 library DFRobot_SHT20 sht20; //LoRa #include <SPI.h> //(Serial Peripheral Interface - communication protocol) #include <LoRa.h> //define the pins used by the transceiver module #define ss 18 #define rst 14 #define dio0 26 #define OLED_RESET 16 //OLED Adafruit_SSD1306 display(OLED_RESET); String message; //variable for data packet (LoRa) void setup() { //****SHT20 Serial.begin(115200); Serial.println("SHT20 Example!"); sht20.initSHT20(); // Init SHT20 Sensor delay(1000); sht20.checkSHT20(); // Check SHT20 Sensor /* //****OLED display setup Wire.begin(4,15); display.begin(SSD1306_SWITCHCAPVCC, 0x3c); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0,0); display.println("Initializing..."); display.display(); */ //****LoRa //setup LoRa transceiver module LoRa.setPins(ss, rst, dio0); //replace the LoRa.begin(---E-) argument with your location's frequency //433E6 for Asia //866E6 for Europe //915E6 for North America if (!LoRa.begin(915E6)) { Serial.println("Starting LoRa failed!"); while (1); } Serial.println("LoRa Initializing OK!"); } void loop() { //****SHT20 float humd = sht20.readHumidity(); // Read Humidity float temp = sht20.readTemperature(); // Read Temperature //Serial.print("Time:"); //Serial.print(millis()); Serial.print(" Temperature:"); Serial.print(temp, 1); Serial.print("C\t"); Serial.print(" Humidity:"); Serial.print(humd, 1); Serial.print("%"); Serial.println(); //delay(1000); message = String (1) + "/" +String(temp,1) + "&" +String(humd,1) + "#"; //Variable management /* //****OLED display.clearDisplay(); display.setCursor(0,0); //display.print("Time:"); //display.print(millis()); display.print("\nTemperature:"); display.print(temp,1); //1 is decimal place display.print("C"); display.print("\nHumidity:"); display.print(humd,1); display.print("%"); display.display(); */ //****LoRa //Send LoRa packet to receiver LoRa.beginPacket(); LoRa.print(message); LoRa.endPacket(); delay(1000); }
hope you can help me, thank you.