[SOLVED] Heltec WiFi32 LoRa V4.3 LoRaWAN DS18B20 invalid readings

been doing some LoRaWAN tests with the Heltec WiFi32 LoRa V4 attempting to transmit data from a DS18B20 temperature sensors
sometimes worked most of the time failed with -127.00 reading

then tested with a V3 and the LoRaWAN and DS18B20 worked OK

so implemented a simple test program

using a Heltec WiFi32 LoRa V4.3

  1. on the V3 and V4 DS28B10 test program runs OK gives valid temperatures
  2. a program which worked OK on the Heltec WiFi32 LoRa V3 using LoRaWAN and a DS18B20 on the V4 gives DS18B20 invalid results

V4 code (the only difference with V3 version was the version number in tile and Serial print)

//Heltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor

// using IDE 2.3.10  ESP32 core 3.3.10 Heltec ESP32 Dev-Boards library 2.1.6
// code adapted from Tools>Board> Heltec ESP32 Dev-Boardslibrary>LoRaWAN>LoRaWAN


// NOTE: in Tools menu select
// USB CDC on Boot: select Enabled
// for V4.3 LoRa FEM Type select USE_KCT8103L_PA.

/* Heltec Automation LoRaWAN communication example
 *
 * Function:
 * 1. Upload node data to the server using the standard LoRaWAN protocol.
 *  
 * Description:
 * 1. Communicate using LoRaWAN protocol.
 * 
 * HelTec AutoMation, Chengdu, China
 * 成都惠利特自动化科技有限公司
 * www.heltec.org
 *
 * */

#include "LoRaWan_APP.h"

/* OTAA para*/
uint8_t devEui[] = { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx };
uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t appKey[] = { zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz};

/* ABP para*/
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda, 0x85 };
uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef, 0x67 };
uint32_t devAddr = (uint32_t)0x007e6ae1;

/*LoraWan channelsmask, default channels 0-7*/
uint16_t userChannelsMask[6] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };

/*LoraWan region, select in arduino IDE tools*/
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;

/*LoraWan Class, Class A and Class C are supported*/
DeviceClass_t loraWanClass = CLASS_A;

/*the application data transmission duty cycle.  value in [ms].*/
uint32_t appTxDutyCycle = 30000;

/*OTAA or ABP*/
bool overTheAirActivation = true;

/*ADR enable*/
bool loraWanAdr = true;

/* Indicates if the node is sending confirmed or unconfirmed messages */
bool isTxConfirmed = true;

/* Application port */
uint8_t appPort = 2;
/*!
* Number of trials to transmit the frame, if the LoRaMAC layer did not
* receive an acknowledgment. The MAC performs a datarate adaptation,
* according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
* to the following table:
*
* Transmission nb | Data Rate
* ----------------|-----------
* 1 (first)       | DR
* 2               | DR
* 3               | max(DR-1,0)
* 4               | max(DR-1,0)
* 5               | max(DR-2,0)
* 6               | max(DR-2,0)
* 7               | max(DR-3,0)
* 8               | max(DR-3,0)
*
* Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
* the datarate, in case the LoRaMAC layer did not receive an acknowledgment
*/
uint8_t confirmedNbTrials = 4;

float DStemperature = 0;  // DS18B20 temperature
/* Prepares the payload of the frame */
static void prepareTxFrame(uint8_t port) {
  /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
  *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
  *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
  *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
  *for example, if use REGION_CN470, 
  *the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in "RegionCN470.h".
  */
  appDataSize = 4;
  DS18B20loop();
  int temp = (int)((DStemperature + 100) * 100.0);
  appData[0] = 0x00;
  appData[1] = 0x01;
  appData[2] = (temp & 0xff);
  appData[3] = (temp >> 8) & 0xff;
}

//if true, next uplink will add MOTE_MAC_DEVICE_TIME_REQ


void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("\n\nHeltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor");
  Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE);
  DS18B20setup();
}

void loop() {
  switch (deviceState) {
    case DEVICE_STATE_INIT:
      {
#if (LORAWAN_DEVEUI_AUTO)
        LoRaWAN.generateDeveuiByChipID();
#endif
        LoRaWAN.init(loraWanClass, loraWanRegion);
        //both set join DR and DR when ADR off
        LoRaWAN.setDefaultDR(3);
        break;
      }
    case DEVICE_STATE_JOIN:
      {
        LoRaWAN.join();
        break;
      }
    case DEVICE_STATE_SEND:
      {
        prepareTxFrame(appPort);
        LoRaWAN.send();
        deviceState = DEVICE_STATE_CYCLE;
        break;
      }
    case DEVICE_STATE_CYCLE:
      {
        // Schedule next packet transmission
        txDutyCycleTime = appTxDutyCycle + randr(-APP_TX_DUTYCYCLE_RND, APP_TX_DUTYCYCLE_RND);
        LoRaWAN.cycle(txDutyCycleTime);
        deviceState = DEVICE_STATE_SLEEP;
        break;
      }
    case DEVICE_STATE_SLEEP:
      {
        LoRaWAN.sleep(loraWanClass);
        break;
      }
    default:
      {
        deviceState = DEVICE_STATE_INIT;
        break;
      }
  }
}

//  ESP32 DS18B20 one-wire temperature sensors -  read the temperature

// connect red 3v black GND yellow (signal) pin 2

/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into
#define ONE_WIRE_BUS 7
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/
void DS18B20setup(void) {
  Serial.begin(115200);
  Serial.println("Dallas Temperature IC Control Library Demo");
  // Start up the library
  sensors.begin();
}


void DS18B20loop(void) {
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  /********************************************************************/
  Serial.print("\nRequesting temperatures...");
  sensors.requestTemperatures();  // Send the command to get temperature readings
  Serial.println("DONE");
  /********************************************************************/
  Serial.print("Temperature is: ");
  Serial.println(DStemperature = sensors.getTempCByIndex(0));  // Why "byIndex"?
  // You can have more than one DS18B20 on the same bus.
  // 0 refers to the first IC on the wire
  delay(1000);
}

Heltec WiFi32 LoRa V3 serial output

Heltec WiFi32 LoRa V3 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

LoRaWAN EU868 Class A start!

+OTAA=1
+Class=A
+ADR=1
+IsTxConfirmed=1
+AppPort=2
+DutyCycle=30000
+ConfirmedNbTrials=4
+ChMask=0000000000000000000000FF
+DevEui=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx(For OTAA Mode)
+AppEui=0000000000000000(For OTAA Mode)
+AppKey=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz(For OTAA Mode)
+NwkSKey=15B1D0EFA463DFBE3D11181E1EC7DA85(For ABP Mode)
+AppSKey=D72C78758CDCCABF55EE4A778D16EF67(For ABP Mode)
+DevAddr=007E6AE1(For ABP Mode)


joining...
joined


Requesting temperatures...DONE
Temperature is: 23.50
confirmed uplink sending ...
received unconfirmed downlink: rssi = -47, snr = 13, datarate = 5


Heltec WiFi32 LoRa V3 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

Requesting temperatures...DONE
Temperature is: 28.50
confirmed uplink sending ...
received unconfirmed downlink: rssi = -47, snr = 13, datarate = 5


Heltec WiFi32 LoRa V3 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

Requesting temperatures...DONE
Temperature is: 32.00
confirmed uplink sending ...
received unconfirmed downlink: rssi = -45, snr = 13, datarate = 5

Heltec WiFi32 LoRa V4 serial output

Heltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

LoRaWAN EU868 Class A start!


joining...
joined

Requesting temperatures...DONE
Temperature is: -127.00
confirmed uplink sending ...
received unconfirmed downlink: rssi = -42, snr = 14, datarate = 5


Heltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

Requesting temperatures...DONE
Temperature is: -127.00
confirmed uplink sending ...

it can seen that the DS18B20 is read without problems using the V3 but gives -127.00 with the V4 - any ideas?

TTN output for V3

The picture in the documentation shows pin 7 is already being used for something.

Good catch by @mikb55.

Given that the DS18B20 test sketch works on the V4, and the LoRaWAN sketch also works on the V4, I would first investigate the GPIO assignment before looking for timing or library issues.

A reading of -127°C usually indicates that the sensor is not being detected. If GPIO7 is already connected to onboard hardware on the V4, moving the DS18B20 to a different GPIO would be a quick test and could explain why the standalone examples work while the combined application fails.

BTW, since the discussion involves DS18B20 error readings, this may also be of interest:

In control/protection applications I generally recommend validating DS18B20 readings before using them, rather than blindly accepting the returned value.

thought I had checked the pinout avoiding GPIO1 VBAT Read and GPIO3 strapping pin
however, missed that pin 7 was used for VFEM_Control which is why the DS18B20 test program worked OK but failed when LoRa was used

using a V3 at the moment - will try V4 ASAP

thanks for the help!

EDIT: update - changed DS18B20 data to GPIO6 which works with LoRaWAN OK

Heltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

LoRaWAN EU868 Class A start!


joining...
joined

Requesting temperatures...DONE
Temperature is: 24.00
confirmed uplink sending ...
received unconfirmed downlink: rssi = -41, snr = 14, datarate = 5

Heltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

Requesting temperatures...DONE
Temperature is: 28.50
confirmed uplink sending ...
received unconfirmed downlink: rssi = -45, snr = 15, datarate = 5

Heltec WiFi32 LoRa V4 LoRaWAN test transmitting DS18B20 temperature sensor
Dallas Temperature IC Control Library Demo

Requesting temperatures...DONE
Temperature is: 31.00
confirmed uplink sending ...
received unconfirmed downlink: rssi = -45, snr = 14, datarate = 5