I am almost done with a project in which I have 2 DallasOneWire sensors and a DHT11 returning temps. I want to compare the dewpoint from the DHT11 to the temps on the Dallas sensors. I have the dewpoint converted to an integer but when I try to convert the dallas sensors to an integer I keep running into issues. They are set as pointers and I don't know how to convert to integer.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#include <dht11.h>
#include <math.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
dht11 DHT11;
#define ONE_WIRE_BUS 3
#define DHT11PIN 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress OTA={0x28, 0x94, 0xBB, 0x60, 0x03, 0x00, 0x00, 0x38};
DeviceAddress EP={0x28, 0xFE, 0xF6, 0xB6, 0x03, 0x00, 0x00, 0x39};
void setup() {
Serial.begin(9600);
sensors.begin();
sensors.setResolution(OTA, 10);
sensors.setResolution(EP, 10);
lcd.begin(16,2);
lcd.clear();
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.println(DallasTemperature::toFahrenheit(tempC));
if (tempC == -127.00) {
lcd.print("XX");
} else {
lcd.print((int)(DallasTemperature::toFahrenheit(tempC)));
}
}
void loop(void)
{
int chk = DHT11.read(DHT11PIN);
//Lcd display for ambient temp, humidity and dew point on line 1. Remote temps for OTA and EP on line 2.
lcd.setCursor(0,0);
lcd.print("T");
lcd.print((int)DHT11.fahrenheit(), DEC);
lcd.setCursor(5,0);
lcd.print("H");
lcd.print((int)((float)DHT11.humidity), DEC);
lcd.print("%");
lcd.setCursor(10,0);
lcd.print("Dew");
lcd.print((int)((DHT11.dewPointFast()*1.8+32)), DEC);
sensors.requestTemperatures();
lcd.setCursor(0,1);
lcd.print("OTA ");
printTemperature(OTA);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print("EP ");
printTemperature(EP);
lcd.print(" ");
int DEW = ((int)((DHT11.dewPointFast()*1.8+32))); //converts dewpoint to an integer for comparison at end of code
int Scope = (char)OTA;
//if(OTA <= DEW){
//digitalWrite(6,HIGH);
//Serial.print("The heater is on");
//}
delay(2000);
}}
this is the source of the issue int Scope = (char)OTA;
Delta_G:
No, that's the right way to do a cast. But in this case you don't want to cast. You want to dereference. To get the thing that a pointer points to, use the * operator.
Also, here's the function being called:
float DallasTemperature::getTempC(uint8_t* deviceAddress)
{
// TODO: Multiple devices (up to 64) on the same bus may take some time to negotiate a response
// What happens in case of collision?
ScratchPad scratchPad;
if (isConnected(deviceAddress, scratchPad)) return calculateTemperature(deviceAddress, scratchPad);
return DEVICE_DISCONNECTED;
}
Been a while since I messed with this, but I believe it returns a float, not a pointer.
If you say ((int)DallasTemperature::getTempC) you are trying to convert the address of the function to an integer. You need to add the opening '(', arguments, and close ')' to call the function.
Also I think the line:
lcd.print((int)((float)DHT11.humidity), DEC)
should be:
lcd.print((int)((float)DHT11.humidity()), DEC);
It means you have put the function inside another function.
Put the added code at the end after the last }
Then call the function from where you are trying to put it at the moment.
Okay, got it put in the right place. I am using 2 Dallas sensors and think that is the next hurdle. Now a new set of errors:
DallasTemperature\DallasTemperature.cpp.o: In function DallasTemperature::getTempC(unsigned char*)': C:\Users\User\Downloads\Arduino\arduino-1.0\libraries\DallasTemperature/DallasTemperature.cpp:463: multiple definition of DallasTemperature::getTempC(unsigned char*)'
Dual_sensor_DHT11_and_LCD_simplified.cpp.o:C:\Users\User\AppData\Local\Temp\build8552269310572340016.tmp/Dual_sensor_DHT11_and_LCD_simplified.cpp:83: first defined here
mitaccio:
I put it in because someone else suggested it. Ultimately all i want is to be able to compare OTA and EP to DewPoint.
Well, no. That code that I posted was the code found in the DallasTemperature library. I posted it to show that it doesn't return a pointer. I did not suggest that you paste that into your code.
I understand that this can be frustrating, but if you want to succeed, you will need to learn to read more carefully, and also don't just paste code into your sketch willy-nilly.
Sorry JustJed. You were right. I was frustrated and tired. I am looking over the Dallas library for ways to convert from 'uint8_t*' to 'int'. Not finding it, but I am learning.
mitaccio:
Sorry JustJed. You were right. I was frustrated and tired. I am looking over the Dallas library for ways to convert from 'uint8_t*' to 'int'. Not finding it, but I am learning.
There is no reason I can think of for you to do that. The unsigned int there is the device address. In fact, you declared these in your code:
In the above, tempF is a float. Once you've retrieved that, then
Serial.println(int(tempF));
Now, Delta_G has said some generic stuff about using pointers in C and C++ and that's good to know. But don't get wrapped in any of these comments too much, because you don't need to use and dereference any pointers to get your sketch to do what you want it to do.
Now, if you want to know what a 'DeviceAddress' is, then look in the DallasTemperature.h file, where you'll find the typedef which defines it.