Sensors not working/triggers wont save


#1

Having trouble with two of four temp sensors not dispaying accurate temp. Just show -197
the two that are working cant save triggers either dont save or appear to save but revert back to default. Using arduino uno with 18b20 temp sensors below is my code

 // This example shows how to connect to Cayenne using an Ethernet W5500 shield and send/receive sample data.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
//#include <CayenneMQTTEthernet.h>
#include <CayenneMQTTEthernetW5500.h>
 #include <OneWire.h>
#include <DallasTemperature.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "bd4a1000-a9d3-11e6-82ee-87310fcf8579";
char password[] = "bada44eda9a38dd862c5a1afc0809579a6d882a9";
char clientID[] = "09709a20-6a81-11e8-a76a-fdebb8d0010d";

unsigned long lastMillis = 0;
#define VIRTUAL_CHANNEL4 4  
#define VIRTUAL_CHANNEL5 5
#define VIRTUAL_CHANNEL6 6
#define VIRTUAL_CHANNEL7 7


// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin7 = 7;
const int tmpPin6 = 6;
const int tmpPin5 = 5;
const int tmpPin4 = 4;

OneWire oneWire7(tmpPin7);
OneWire oneWire6(tmpPin6);
OneWire oneWire5(tmpPin5 ); 
OneWire oneWire4(tmpPin4); 
DallasTemperature sensors7(&oneWire7);
DallasTemperature sensors6(&oneWire6);
DallasTemperature sensors5(&oneWire5);
DallasTemperature sensors4(&oneWire4);

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  sensors4.begin(); 
  sensors5.begin();
  sensors6.begin();
  sensors7.begin(); 
}

void loop()
{
  Cayenne.loop();
}
CAYENNE_OUT(VIRTUAL_CHANNEL4) 
{
    // Send the command to get temperatures.
  sensors4.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  //Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors6.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL4, sensors4.getTempFByIndex(0)); 
  
}
 
  // This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL5)
{
  // Send the command to get temperatures.
  sensors5.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  //Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors5.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL5, sensors5.getTempFByIndex(0));
}  
CAYENNE_OUT(VIRTUAL_CHANNEL6) 
{
    // Send the command to get temperatures.
  sensors6.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  //Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors6.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL6, sensors6.getTempFByIndex(0)); 
  
}
CAYENNE_OUT(VIRTUAL_CHANNEL7) 
{
    // Send the command to get temperatures.
  sensors7.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  //Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors6.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL7, sensors7.getTempFByIndex(0)); 
  
}

#2

first try to get reading from the sensor http://arduino-info.wikispaces.com/MultipleTemperatureSensorsToLCD


#3

I had not planned to use 18b20 on one wire had this project set up before mqtte worked fine after trying to convert over is when above problems occured. Plugging in each temp sensor i seperate they populated fine but taking project back to storage hooking up all four only two poipulated properly. can sensors not be used seperalty and apart on own channel with mqtte??
Dave


#4

can you post the code you used without cayenne MQTT which worked fine for multiple temp readings. Are you getting reading from the each sensor without cayenne code.


#5

i used cayenne code

/*
Cayenne DS18B20 Example

This sketch shows how to send temperature data to a DS18B20 Sensor in the Cayenne Dashboard.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. Install the OneWire library (http://www.pjrc.com/teensy/td_libs_OneWire.html) from the Arduino Library Manager.
  2. Install the DallasTemperature library (http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library#Code.2FLibrary) from the Arduino Library Manager.
  3. In the Cayenne Dashboard add a new DS18B20 widget.
  4. Set the widget to Value Display.
  5. Select Virtual Pins and a virtual pin number.
  6. Set VIRTUAL_PIN to the pin number you selected.
  7. Attach a DS18B20 to an digital pin on your Arduino.
    Schematic:
    [Ground] – [DS18B20] – [4.7k resistor] – [5V]
    |______________|
    |
    Digital Pin
  8. Set the tmpPin variable to match the pin used to connect the DS18B20.
  9. Set the token variable to match the Arduino token from the Dashboard.
  10. Compile and upload this sketch.
  11. Once the Arduino connects to the Dashboard it should automatically update the DS18B20 widget with data.
    */

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <OneWire.h>
#include <DallasTemperature.h>
#include <CayenneEthernetW5500.h>

// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3

// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin1 = 7;
const int tmpPin2 = 6;
const int tmpPin3 = 5;

OneWire oneWire1(tmpPin1);
OneWire oneWire2(tmpPin2);
OneWire oneWire3(tmpPin3);

DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
DallasTemperature sensors3(&oneWire3);

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = “luhbdjf5h”;

void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
sensors1.begin();
sensors2.begin();
sensors3.begin();
}

void loop()
{
Cayenne.run();
}

// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN1)
{
// Send the command to get temperatures.
sensors1.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN1, sensors1.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
CAYENNE_OUT(VIRTUAL_PIN2)
{
// Send the command to get temperatures.
sensors2.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN2, sensors2.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
CAYENNE_OUT(VIRTUAL_PIN3)
{
// Send the command to get temperatures.
sensors3.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN3, sensors3.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}


#6

Try this code and see if you are getting value from sensor.

#include &lt;OneWire.h&gt;
#include &lt;DallasTemperature.h&gt;

// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3

// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin1 = 7;
const int tmpPin2 = 6;
const int tmpPin3 = 5;

OneWire oneWire1(tmpPin1);
OneWire oneWire2(tmpPin2);
OneWire oneWire3(tmpPin3);

DallasTemperature sensors1(&amp;oneWire1);
DallasTemperature sensors2(&amp;oneWire2);
DallasTemperature sensors3(&amp;oneWire3);

void setup()
{
Serial.begin(9600);
sensors1.begin();
sensors2.begin();
sensors3.begin();
}
int x;
int y;
int z;
void loop()
{
sensors1.requestTemperatures();
x = sensors1.getTempCByIndex(0)
delay(100);
sensors2.requestTemperatures();
xy= sensors2.getTempCByIndex(0)
sensors3.requestTemperatures();
z = sensors3.getTempCByIndex(0)
Serial.print(x);
Serial.print(y);
Serial.println(z);
}

#7

cant get code to verify hangs up on

#include <DallasTemperature.h> # include expects “filename” or


#8
#include <OneWire.h>
#include <DallasTemperature.h>

// Virtual Pin of the DS18B20 widget.
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3

// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin1 = 7;
const int tmpPin2 = 6;
const int tmpPin3 = 5;

OneWire oneWire1(tmpPin1);
OneWire oneWire2(tmpPin2);
OneWire oneWire3(tmpPin3);

DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
DallasTemperature sensors3(&oneWire3);

void setup()
{
Serial.begin(9600);
sensors1.begin();
sensors2.begin();
sensors3.begin();
}
int x;
int y;
int z;
void loop()
{
sensors1.requestTemperatures();
x = sensors1.getTempCByIndex(0);
delay(100);
sensors2.requestTemperatures();
y= sensors2.getTempCByIndex(0);
delay(100);
sensors3.requestTemperatures();
delay(100);
z = sensors3.getTempCByIndex(0);
Serial.print(x);
Serial.print(y);
Serial.println(z);
}

#9

code uploaded ok serial monitor has 22-127-127 the first two numbers appear to be temp c
it goes up and down with temp it only shows up with sensor #1 so am i back to square 0ne?
the tutorial you sent me to use sensors on one wire even if i get that figured out the code still has to be converted to cayenne MQTT right? Not much on coding been getting by put and take. Nor sure where to go from here


#10

First try to get the sensor reading using the tutorial i send above. once you have done that, we can move forward with cayenne code.
Also for the above output (22-127-127), try swapping the order for getting the temperature in the code and post the entire Serial output screenshot.

void loop()
{

sensors2.requestTemperatures();
y= sensors2.getTempCByIndex(0);
delay(100);
sensors1.requestTemperatures();
x = sensors1.getTempCByIndex(0);
delay(100);
sensors3.requestTemperatures();
delay(100);
z = sensors3.getTempCByIndex(0);
Serial.print(x);
Serial.print(y);
Serial.println(z);
}

#11

switched order serial print screen look as before switching


#12

-127 is an issue reported for bad connection. try this One wire probe problem


#13

Got code off sensors when i go to hook them up what will be best to work with cayenne alerting system 1 arduino uno pin doing true one wire hooking 4 sensors or 4 arduino uno pins to hook 4 sensors not using onnly one pin or does it matter??


#14

you can use which ever you want until you are getting the temperature reading from the sensor. then send the data of each sensor to cayenne using:

    Cayenne.celsiusWrite(1, temp1);
    Cayenne.celsiusWrite(2, temp2);
    Cayenne.celsiusWrite(3, temp3);

where temp1, temp2, temp3 are data of each sensor.


#15

Got all sensors working (see screen capture below) with arduino sketch shown below. Now i need to to convert to cayenne sent with ethernet shield 5500. Can you help to convert sketch to get this working again?
Dave

 //  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress  ColdStorage1Thermometer = { 0x28,0xFF,0xAC,0xCF,0x02,0x17,0x04,0x55 };
DeviceAddress  CooldStorage2Thermometer = { 0x28,0xFF,0x6E,0xED,0x02,0x17,0x03,0x00 };
DeviceAddress  ColdStorage3Thermometer = { 0X28,0xFF,0x34,0x58,0x02,0x17,0x05,0xE5 };
DeviceAddress  GH1Thermometer        =   { 0x28 ,0xFF,0xA2,0xCD,0x02,0x17,0x03,0x73 };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution( ColdStorage1Thermometer, 10);
  sensors.setResolution( CooldStorage2Thermometer, 10);
  sensors.setResolution(ColdStorage3Thermometer, 10);
  sensors.setResolution(GH1Thermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{ 
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("ColdStorage1 temperature is: ");
  printTemperature(ColdStorage1Thermometer);
  Serial.print("\n\r");
  Serial.print("CooldStorage2 temperature is: ");
  printTemperature(CooldStorage2Thermometer);
  Serial.print("\n\r");
  Serial.print("ColdStorage3 temperature is: ");
  printTemperature(ColdStorage3Thermometer);
  Serial.print("\n\r\n\r");
   Serial.print("GH1 temperature is: ");
  printTemperature(GH1Thermometer);
  Serial.print("\n\r\n\r");
}

#16

in your arduino IDE navigate to File --> examples --> CayenneMQTT --> Sensors and open DS18B20.ino.
Make changes and add you sensor code to this.


#17

Here is the sketch i combined cant get to compile, [ virtual channel was not declared in this scope]
not sure how to set up virtual channels with only one wire pin on arduino
dave

//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>// Cayenne authentication info. This should be obtained from the Cayenne Dashboar
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h> 

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";


// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  sensors.begin(); 
   
  }
 

void loop(void)
{ 
Cayenne.loop();
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  // Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
   Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));
}  

// This Arduino sketch reads DS18B20 “1-Wire” digital

 //  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>// Cayenne authentication info. This should be obtained from the Cayenne Dashboar
#include <DallasTemperature.h>
#include <CayenneMQTTEthernet.h> 

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";


// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID);
  sensors.begin(); 
   
  }
 

void loop(void)
{ 
Cayenne.loop();
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
  // Send the command to get temperatures.
  sensors.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  // Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
   Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));
}

#18

why have you posted two codes?
Add this line in your code:
#define VIRTUAL_CHANNEL 1


#20

got things working but only picking up one sensor sensor 3

using following sketch

// This Arduino sketch reads DS18B20 “1-Wire” digital
// temperature sensors.
// Copyright © 2010 Mark McComb, hacktronics LLC
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>
#include <DallasTemperature.h>
//#include <CayenneMQTTEthernet.h>
#include <CayenneMQTTEthernetW5500.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “bd4a1000-a9d3-11e6-82ee-87310fcf8579”;
char password[] = “bada44eda9a38dd862c5a1afc0809579a6d882a9”;
char clientID[] = “09709a20-6a81-11e8-a76a-fdebb8d0010d”;

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
#define VIRTUAL_CHANNEL 1
#define VIRTUAL_CHANNEL 2
#define VIRTUAL_CHANNEL 3
#define VIRTUAL_CHANNEL 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress ColdStorage1Thermometer = { 0x28,0xFF,0xAC,0xCF,0x02,0x17,0x04,0x55 };
DeviceAddress CooldStorage2Thermometer = { 0x28,0xFF,0x6E,0xED,0x02,0x17,0x03,0x00 };
DeviceAddress ColdStorage3Thermometer = { 0X28,0xFF,0x34,0x58,0x02,0x17,0x05,0xE5 };
DeviceAddress GH1Thermometer = { 0x28 ,0xFF,0xA2,0xCD,0x02,0x17,0x03,0x73 };

void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
Cayenne.begin(username, password, clientID);
sensors.begin();

}

void loop(void)
{
Cayenne.loop();
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{

// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Channel.
// Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL, sensors.getTempFByIndex(0));
}


#21

you will have to add code for reading temperature from other sensor and send them using virtual channel 2 and 3 similar way you did for channel 1.