DS18B20

04 Jun 2012

Hello Everyone,

I should really be in a good position to get the answer to this at work but I want to do this whilst I am off.

Using the following code for the DS18B20 temperature sensor as per the project code below.

http://mbed.org/users/feabhas/notebook/ds18b20-temperature-sensor/?page=1#comment-230

I have put this together and got the sensor running and periodically updating. However I now need to explore a conditional statement that should the temperature exceed X degrees then an warning sound/led should light up.

I have added the following code

if (displayTemperature > 30 );{ mbled1 = 1; }

but when I go to compile I get the following error:

"operand types are incompatible ("void (*)(mbed::Serial &)" and "int")" in file "/main.cpp", Line: 28, Col: 26

This is obviously where my knowledge of coding fails.

The information comes out to my hyperterminal ok so I am just puzzled at the moment.

04 Jun 2012

You shouldn't put that ";" after if (condition ) Check this ..... if (condition) statement http://www.cplusplus.com/doc/tutorial/control/

05 Jun 2012

Ok Tried removing the ";",. I still get the same compile error.

05 Jun 2012

That library does not look to have really nice code, but displayTemperature sends the temperature on the serial port that should be its argument, so for example displayTemperature(pc);

You will need to replace it by the function getTemperature(), that will return the temperature stored by the sensor, but it will be 16 times too large (due to the format it is stored in). So the code you need is:

if ( (getTemperature()/16.0) > 30 ) mbled1 = 1;
10 Jun 2012

Erik, thank you for the response. I am pretty new to the actual writing of embedded code. Is there any examples that I could look at? The above makes sense so I just need to work out the function part now.

I'll get there eventually.

11 Jun 2012

You already should be able to copy/paste the code I posted into your program to enable the LED above 30 degrees. There are probably quite some examples, but what exactly do you want to know/have an example of?

The problem here is mainly that that library has little documentation, so you had to go through the code to get the function you need.

12 Jun 2012

Erik

Thank you for your help. After some guidance at work I have got this to work and yes it was down to the function. I bolted in the code below in the DS18B20.cpp (with a little help from Niall)

float getTemperature() { DoConversion(); uint32_t temp = GetRAWTemperature(); float f = (temp & 0x0F) * 0.0625; calculate .4 part f += (temp >> 4); add 7.0 part to it return f;

This also allowed me to remove the division part by 16.

Gavin