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