Cubecell won't find DS18B20

I have a working DS18B20 sensor (works fine on a Wireless Stick). When I try it on the CubeCell capsule it just reports -127. I have it connected to GPIO, Vext, & GND. I’ve tried the onewiresearch sketch and that doesn’t find it either. What am I doing wrong? Thanks. Code is below:
// Include the libraries we need
#include “LoRaWan_APP.h”
#include “Arduino.h”
#include <OneWire.h>
#include <DallasTemperature.h>

#define timetillsleep 1000
#define timetillwakeup 100*60
static TimerEvent_t sleep;
static TimerEvent_t wakeUp;
uint8_t lowpower=1;
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif

// Data wire is plugged into GPIO1 on the CubeCell
#define ONE_WIRE_BUS 01
#define TEMPERATURE_PRECISION 9

float temp = 0;

#define RF_FREQUENCY 868000000 // 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 8 // [SF7…SF12]
#define LORA_CODINGRATE 4 // [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 // was 1000
#define BUFFER_SIZE 30 // Define the payload size here

char txPacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

int16_t rssi,rxSize;

// 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 setup()
{
// Vext ON
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(10);

// start serial port
Serial.begin(115200);
Serial.println(“Dallas Temperature IC Control Library Demo”);

// Start up the library
sensors.begin();

// init LoRa
boardInitMcu( );
temp = 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 );

Radio.Sleep( );
TimerInit( &sleep, onSleep );
TimerInit( &wakeUp, onWakeUp );
onSleep();
// Vext OFF
pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
delay(10);
}

void loop() {
if(lowpower){
//note that lowPowerHandler() runs six times before the mcu goes into lowpower mode;
delay(100);
turnOffRGB();
lowPowerHandler();
}
}

void onSleep()
{
Serial.printf(“Going into lowpower mode, %d ms later wake up.\r\n”,timetillwakeup);
lowpower=1;
turnOnRGB(COLOR_JOINED,0);
delay(100);
turnOffRGB();
//timetillwakeup ms later wake up;
TimerSetValue( &wakeUp, timetillwakeup );
TimerStart( &wakeUp );
}
void onWakeUp()
{
Serial.printf(“Woke up, %d ms later into lowpower mode.\r\n”,timetillsleep);
lowpower=0;
//
// Vext ON
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(1000);
// get temp
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(“Requesting temperatures…”);
sensors.requestTemperatures(); // Send the command to get temperatures
delay(2000);
Serial.println(“DONE”);
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
Serial.print(“Temperature for the device 1 (index 0) is: “);
float temp = (sensors.getTempCByIndex(0));
Serial.println(temp);
// Vext OFF
pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
delay(10);
// TX
sprintf(txPacket,”%s”,“T: “);
sprintf(txPacket+strlen(txPacket),”%d”,temp);
turnOnRGB(COLOR_SEND,0);
delay(100);
turnOffRGB();
Serial.printf("\r\nsending packet “%s” , length %d\r\n",txPacket, strlen(txPacket));
Radio.Send( (uint8_t *)txPacket, strlen(txPacket) );
//timetillsleep ms later into lowpower mode;
TimerSetValue( &sleep, timetillsleep );
TimerStart( &sleep );

}

Not all (arduino) librarys work with Cubecell Boards.

E_T

Are you using the most recents Heltec libraries as they are on github, there have been some fixes around micros() and interrupts …

Which IDE do you use? Arduino or platform.io?

do you use a pullup resistor on the dataline?

Thank you all for your replies. Yes, I’m using a pull-up resistor, and I’m using the Arduino IDE. I have got it working now - it was the DallasTemperature library that was stopping it working. I found an example using just the oneWire library and it all works fine. The code needs tidying up but here it is…

// Include the libraries we need
#include “LoRaWan_APP.h”
#include “Arduino.h”
#include <OneWire.h>

#define timetillsleep 1000
#define timetillwakeup 100*60
static TimerEvent_t sleep;
static TimerEvent_t wakeUp;
uint8_t lowpower=1;
#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif

// Data wire is plugged into GPIO1 on the CubeCell

#define RF_FREQUENCY 868000000 // 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 8 // [SF7…SF12]
#define LORA_CODINGRATE 4 // [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 // was 1000
#define BUFFER_SIZE 30 // Define the payload size here

char txPacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

int16_t rssi,rxSize;

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire ds(GPIO1); // on pin GPIO1 PIN 6 (a 4.7K resistor is necessary)

/*
The setup function. We only start the sensors here
*/
void setup()
{
// Vext ON
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(10);

// start serial port
Serial.begin(115200);

// init LoRa
boardInitMcu( );
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 );

Radio.Sleep( );
TimerInit( &sleep, onSleep );
TimerInit( &wakeUp, onWakeUp );
onSleep();
// Vext OFF
pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
delay(10);
}

/*
Main function, get and show the temperature
*/
void loop() {
if(lowpower){
//note that lowPowerHandler() runs six times before the mcu goes into lowpower mode;
delay(100);
turnOffRGB();
lowPowerHandler();
}
}

void onSleep()
{
Serial.printf(“Going into lowpower mode, %d ms later wake up.\r\n”,timetillwakeup);
lowpower=1;
turnOnRGB(COLOR_JOINED,0);
delay(100);
turnOffRGB();
//timetillwakeup ms later wake up;
TimerSetValue( &wakeUp, timetillwakeup );
TimerStart( &wakeUp );
}
void onWakeUp()
{
Serial.printf(“Woke up, %d ms later into lowpower mode.\r\n”,timetillsleep);
lowpower=0;
//
// Vext ON
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(1000);
// get temp
//
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

//if ( !ds.search(addr)) {
// Serial.println(“No more addresses.”);
// Serial.println();
// ds.reset_search();
// delay(250);
// return;
//}
ds.reset_search();
ds.search(addr);

Serial.print(“ROM =”);
for( i = 0; i < 8; i++) {
Serial.write(’ ');
Serial.print(addr[i], HEX);
}

if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println(“CRC is not valid!”);
return;
}
Serial.println();

//the first ROM byte indicates which chip

switch (addr[0]) {
case 0x10:
Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
Serial.println(“Device is not a DS18x20 family device.”);
return;
}

ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad

Serial.print(" Data = “);
Serial.print(present, HEX);
Serial.print(” “);
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
Serial.print(data[i], HEX);
Serial.print(” “);
}
Serial.print(” CRC=");
Serial.print(OneWire::crc8(data, 8), HEX);
Serial.println();
// Vext OFF
pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
delay(10);
//
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an “int16_t” type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// “count remain” gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let’s zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = “);
Serial.print(celsius);
Serial.print(” Celsius, “);
Serial.print(fahrenheit);
Serial.println(” Fahrenheit");
char *str_temp;
String msgT ="";

msgT= String(celsius,1);
memset(txPacket, 0,BUFFER_SIZE);
str_temp= (char*)(msgT).c_str();
sprintf(txPacket,"%s",str_temp);
Serial.printf("\r\nsending packet “%s” , length %d\r\n",txPacket, strlen(txPacket));
// TX
turnOnRGB(COLOR_SEND,0);
delay(100);
turnOffRGB();
Radio.Send( (uint8_t *)txPacket, strlen(txPacket) );
//timetillsleep ms later into lowpower mode;
TimerSetValue( &sleep, timetillsleep );
TimerStart( &sleep );

}

this code work for me, always with pullup resistence

// Include the libraries we need
#include “LoRaWan_APP.h”
#include “Arduino.h”
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
uint16_t voltage;
// Data wire is plugged into GPIO5 on the CubeCell
#define ONE_WIRE_BUS GPIO0

// 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);

/*
The setup function. We only start the sensors here
*/

/* OTAA para*/
uint8_t devEui[] = { your deveui };
uint8_t appEui[] = { your appeui } ;
uint8_t appKey[] = {your appkey };

/* 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 = LORAWAN_CLASS;

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

/OTAA or ABP/
bool overTheAirActivation = LORAWAN_NETMODE;

/ADR enable/
bool loraWanAdr = LORAWAN_ADR;

/* set LORAWAN_Net_Reserve ON, the node could save the network info to flash, when node reset not need to join again */
bool keepNet = LORAWAN_NET_RESERVE;

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

/* 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;

static void prepareTxFrame( uint8_t port )
{

pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
sensors.begin();
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);

Wire.end();

pinMode(VBAT_ADC_CTL,OUTPUT);
digitalWrite(VBAT_ADC_CTL,LOW);
voltage=analogRead(ADC)*2;

//digitalWrite(Vext, HIGH);
uint16_t voltage=analogRead(ADC)*2;

unsigned char *puc;
puc = (uint8_t *)(&temperature);
appDataSize = 6;//AppDataSize max value is 64
appData[0] = puc[0];
appData[1] = puc[1];
appData[2] = puc[2];
appData[3] = puc[3];

appData[4] = (uint8_t)(voltage>>8);
appData[5] = (uint8_t)voltage;

Serial.println(“voltaje bateria:”);
Serial.print(voltage);
Serial.print("Temperature: ");
Serial.print(temperature);
digitalWrite(Vext, HIGH);
}
void setup() {
boardInitMcu();
Serial.begin(115200);
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
sensors.begin();
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.print(temperature);
Wire.end();
#if(AT_SUPPORT)
enableAt();
#endif
deviceState = DEVICE_STATE_INIT;
LoRaWAN.ifskipjoin();
}

void loop()
{
switch( deviceState )
{
case DEVICE_STATE_INIT:
{
#if(AT_SUPPORT)
getDevParam();
#endif
printDevParam();
LoRaWAN.init(loraWanClass,loraWanRegion);
deviceState = DEVICE_STATE_JOIN;
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( 0, APP_TX_DUTYCYCLE_RND );
LoRaWAN.cycle(txDutyCycleTime);
deviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
LoRaWAN.sleep();
break;
}
default:
{
deviceState = DEVICE_STATE_INIT;
break;
}
}
}

There are several issues in the code, zapal, you say “this code works”. It can not run as you have posted it. - Have you copied it from another guy on a random site?..

I have now repaired the code you posted to be able to use it locally. It sends Lora messages. But using and reading the DS18B20 does still not work with your code.

I was not able to reproduce your success with your code. - I must have additional challenges too in my case.

I am using pull-up resistor.

I am using the Arduino IDE (1.18.13).

I can assure you it does run. What makes you think it won’t?

I do not think that it does not work. It says so:

ROM = 40 7 0 20 0 0 0 0 - CRC is not valid!

I know by the way that the ID of the DS18B20 is
28 43 FC 4 17 13 1 6C - so obvious not working, in my eyes.

But as I said: Maybe do I have additional challenges?..

in my case i use Dallastemperature 3.8.0 and a pullup resistor 47K. this code work with lorawan protocol in cubecell board and cubecell capsule. check library version and check wires. my code works on lorawan otta, you need to put yours aplicattion keys.

You can check a simple sketch example from ide arduino of this library.

1 Like

In your code posted, several
/* comment */
have turned into
/ comment /
That fails when using your code “as is”.

The VBAT_ADC_CTL was not defined according to the compiler. I guess a variable from the system somewhere? But I had to define it. Did not work “as is”.

I think to remember there was something with the line “uint8_t appPort = 2;” also.

I can’t remember more now.

I have a pull-up - of 4K7 Ohm. Works with Heltec WiFi Lora 32 - and DOIT ESP32 Dev Kit V1.

I have 3.8.0 from DallasTemp.

Other lib version are:

Multiple libraries were found for “OneWire.h”
Used: /home/xox/Arduino/libraries/OneWire
Not used: /home/xox/.arduino15/packages/CubeCell/hardware/CubeCell/0.0.5/libraries/OneWire
Using library LoRa at version 1.0 in folder: /home/xox/.arduino15/packages/CubeCell/hardware/CubeCell/0.0.5/libraries/LoRa
Using library OneWire at version 2.3.5 in folder: /home/xox/Arduino/libraries/OneWire
Using library DallasTemperature at version 3.8.0 in folder: /home/xox/Arduino/libraries/DallasTemperature
Using library RGB at version 1.0 in folder: /home/xox/.arduino15/packages/CubeCell/hardware/CubeCell/0.0.5/libraries/RGB

Your cubecell board versio is 0.0.5 and way to old. Update with the arduino board manager

1 Like

I just updated an hour ago by using
github .com / HelTecAutomation / ASR650x-Arduino/blob/master/InstallGuide/debian_ubuntu.md
(added spaces to disable link functionality)

  • But maybe I had to remove / delete some files before I did that ??? … Is something double ?.. What would I have to delete before using the Github version?

i have 1.0.0 version cubecell board, and duplicate libraries

1 Like

C:\Users\USER\AppData\Local\Arduino15\packages\CubeCell\hardware\CubeCell\1.0.0

Hello, greetings from Mexico.
Here I bring you what worked for me and where the error seems to be because the DS18B20 sensor does not work initially.
If you have previously worked with the DS18B20 sensor, it is obvious that you must already have the onewire.h library installed. This is where the error occurs. When you install everything related to the Cube Cell, there are some libraries edited to work with it, and one of them is onewire.h. If I remember correctly, this is here:
C:\Users\Luis\AppData\Local\Arduino15\packages\CubeCell\hardware\CubeCell\1.1.0\libraries

The Arduino IDE is calling by default the one you had previously installed and it does not work with the Cube Cell. Therefore what you have to do is remove it from your libraries. The one you have to remove is here:
C:\Users\Luis\Documents\Arduino\libraries

I hope this will help you, it took me two days doing tests and reading to make my sensor work, lol =).

Greetings

hi,

Thank you for your effort!