Slider does not work correctly with temperature


#1

I,m using a Mega 2560 Arduino Controller with DS18B20 temperature sensor.

I want to use a Slider to define the temperature and switch on an off a relay to control a refrigerator temperature. But the temperature off slider is diferent from the virtual Display Widget that shows the Slider temperature.

The Slider value = 6.9 and the widget value = 12736.40

Follow the exemple

This is my sketch

//#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// Importa a biblioteca OneWire
#include <OneWire.h>
// Importa a biblioteca DallasTemperature para os sensores DS18B20
#include <DallasTemperature.h>
// Importa a biblioteca para conexao Cayenne
#include <CayenneSerial.h> // Utilize outra biblioteca caso utilize um outro meio de conexao
// Importa a biblioteca SimpleTimer para utilizar o timer
#include <SimpleTimer.h>

// Define os pinos virtuais para os widgets - Sensor de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
#define VIRTUAL_PIN3 V3
//-------------------------------------------------------------------------------------------------------------------------//


// Define os pinos virtuais para teste geladeira 01 - Sensor de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
#define VIRTUAL_PIN23 V23 // VALOR DO SLIDE
#define VIRTUAL_PIN24 V24 // Rele de comando da geladeira
#define VIRTUAL_PIN25 V25 // Slider com temperatura
//-------------------------------------------------------------------------------------------------------------------------//

// Define o pino de conexao do sensor OneWire (DS18B20) no Arduino. Nao utilizar os pinos 0 ou 1 pois podem gerar conflitos com a porta Serial
const int tmpPin = 2;


// Cria um objeto do tipo SimpleTimer
SimpleTimer timer;


//Define as variáveis OneWire e tambem para o Sensor de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
//-------------------------------------------------------------------------------------------------------------------------//


//Endereço dos sensores de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
DeviceAddress V1_ENDERECO = { 0x28, 0xEE, 0x02, 0x88, 0x16, 0x16, 0x01, 0xE1 }; // Endereço físico do Sensor da panela 01
DeviceAddress V2_ENDERECO = { 0x28, 0xEE, 0x1E, 0x3B, 0x15, 0x16, 0x01, 0x41 }; // Endereço físico do Sensor da panela 01
DeviceAddress V3_ENDERECO = { 0x28, 0xEE, 0xA1, 0x45, 0x17, 0x16, 0x02, 0x71 }; // Endereço físico do Sensor da panela 01
//-------------------------------------------------------------------------------------------------------------------------//


//Define as variáveis de coleta de informações das temperaturas
//-------------------------------------------------------------------------------------------------------------------------//
double SENSOR_TEMP_01;
double SENSOR_TEMP_02;
double SENSOR_TEMP_03;
double SENSOR_TARGET_01;
int RELE_STATUS_01 = 0;
//-------------------------------------------------------------------------------------------------------------------------//


//Cria a função para ser utilizada pelo timer
//-------------------------------------------------------------------------------------------------------------------------//
void repeatMe() 
{
  
  //Captura a temperatura do Sensor
  sensors.requestTemperatures();
  SENSOR_TEMP_01 = sensors.getTempCByIndex(0);
  SENSOR_TEMP_02 = sensors.getTempCByIndex(1);
  SENSOR_TEMP_03 = sensors.getTempCByIndex(2);

  if (RELE_STATUS_01 == 0) {
RELE_STATUS_01 = 1;
  }
  else {
RELE_STATUS_01 = 0;
  }



  //SENSOR_TARGET_01 = 25.1;


  //Serial.print("Sensor 01: ");
  //Serial.println(SENSOR_TEMP_01);


  //Serial.print("Sensor 01: ");
  //Serial.println(RELE_STATUS_01);


  //Serial.print("Sensor 01: ");
  //Serial.println(SENSOR_TARGET_01);


  //Serial.print("Sensor 02: ");
  //Serial.println(sensors.getTempCByIndex(1));

  //Serial.print("Sensor 03: ");
  //Serial.println(sensors.getTempCByIndex(2));
 
}
//-------------------------------------------------------------------------------------------------------------------------//
//Finaliza a função exemplo para ser utilizada pelo timer


//Cria a função para ser utilizada pelo timer
//-------------------------------------------------------------------------------------------------------------------------//
void Regrigerador_01_teste() 
{
  
  //Captura a temperatura do Sensor
  if (SENSOR_TEMP_01 < SENSOR_TARGET_01) 
  {
RELE_STATUS_01 = 1;
  }
  
  else 
  {
RELE_STATUS_01 = 0;
  }

}
//-------------------------------------------------------------------------------------------------------------------------//
//Finaliza a função exemplo para ser utilizada pelo timer


//Define o token de inicializacao do Cayenne
char token[] = "27hmhv6grc";

//Inicio do bloco Setup
//-------------------------------------------------------------------------------------------------------------------------//
void setup()
{
	//Serial.begin(9600);
	
  //Inicializa a conexao com o Cayenne
	Cayenne.begin(token);

  // Inicializa os sensores de medicao
	sensors.begin();


  //Define a resolução dos sensores por meio do endereco individual - Sensor de temperatura DS18B20
  //-------------------------------------------------------------------------------------------------------------------------//
  sensors.setResolution(V1_ENDERECO, 11); //Rezoliucija: 9 - 0.5°C; Rezoliucija: 10 - 0.25°C; Rezoliucija: 11 - 0.125°C;
  sensors.setResolution(V2_ENDERECO, 11);
  sensors.setResolution(V3_ENDERECO, 11);
  //-------------------------------------------------------------------------------------------------------------------------//


  //Define a função do Timer
  timer.setInterval(5000, repeatMe);
 
}
//-------------------------------------------------------------------------------------------------------------------------//
//Fim do Bloco Setup

//Inicio do bloco Loop
//-------------------------------------------------------------------------------------------------------------------------//
void loop()
{
	//Executa o módulo Cayenne
  Cayenne.run();

  //Executa o módulo do timer
  timer.run();

  //Regrigerador_01_teste();

}
//-------------------------------------------------------------------------------------------------------------------------//
//Fim do bloco Loop


// Funcao (Output) cahamada quando o Cayenne requisita informacoes sobre o Pino Virtual 01 - Sensor de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
CAYENNE_OUT(VIRTUAL_PIN1)
{
	// Send the command to get temperatures. 
  //sensors.requestTemperatures();
	// This command writes the temperature in Celsius to the Virtual Pin.
	Cayenne.celsiusWrite(VIRTUAL_PIN1, SENSOR_TEMP_01);
	// To send the temperature in Fahrenheit use the corresponding code below.
	//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
//-------------------------------------------------------------------------------------------------------------------------//
// Fim da função Output do Pino Virtual 01


// Funcao (Output) cahamada quando o Cayenne requisita informacoes sobre o Pino Virtual 03 - Sensor de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
CAYENNE_OUT(VIRTUAL_PIN2)
{
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN2, SENSOR_TEMP_02);
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
//-------------------------------------------------------------------------------------------------------------------------//
// Fim da função Output do Pino Virtual 02

// Funcao (Output) cahamada quando o Cayenne requisita informacoes sobre o Pino Virtual 03 - Sensor de temperatura DS18B20
//-------------------------------------------------------------------------------------------------------------------------//
CAYENNE_OUT(VIRTUAL_PIN3)
{
  // This command writes the temperature in Celsius to the Virtual Pin.
  Cayenne.celsiusWrite(VIRTUAL_PIN3, SENSOR_TEMP_03);
  // To send the temperature in Fahrenheit use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
//-------------------------------------------------------------------------------------------------------------------------//
// Fim da função Output do Pino Virtual 03



CAYENNE_OUT(VIRTUAL_PIN23)
{
  // Envia o valor do Slider
  Cayenne.virtualWrite(VIRTUAL_PIN23, SENSOR_TARGET_01);
  
}


CAYENNE_OUT(VIRTUAL_PIN24)
{
  // Envia o status do Rele
  Cayenne.virtualWrite(VIRTUAL_PIN24, RELE_STATUS_01);
  
}


CAYENNE_IN(VIRTUAL_PIN25)
{
  //Cayenne.celsiusWrite(VIRTUAL_PIN25, SENSOR_TARGET_01);

  //SENSOR_TARGET_01 = getValue.asDouble(); // Get value as Float
  SENSOR_TARGET_01 = getValue.asInt(); // Get value as Float

}

Thanks in advance.


#2

Apparently it’s a known issue, for three months, no solution yet, look http://community.mydevices.com/t/slider-value-problem/1125