Pascal - please start a new thread. You’ll get much more attention.
Could you please tell me how to to start a new thread, I didn’t find it unfortunately.
Connect 5V to pin 3 of the DS18B20 and your problem should be solved
Yes it works now, thanks a lot for your help.
Next step connect more than one sensor on the bus…
Pascal - I meant start a new forum thread, not a NETMF code Thread object. Seems you figured it out already.
Welcome to the forum.
Ransomhall, well I only find the way to reply an existing topic, not the way to create a new one… Is there any “Post new topic” button somewhere ?
Go up a level to where you can see the list of all topics in a particular forum. Then there is a “New Topic” button.
Wouldn’t be much of a forum if we couldn’t create new topics ;D At the top of each forum is a New Topic button.
Get it, in my case I should have place it in Home > Forum > FEZ Rhino, Domino, Mini, Panda and USBizi
Thanks a lot for your help.
Hi Everybody, i have play arround with the DS1820 and i think that i found a bug in previous code exposed.
In fact, reading the DALAS Manufacturer documentation, i noticed that the temperature read through the 2 bytes read after the “Read Scratchpad” command shall be devided by 2 to get the result in Celsius:
Ds1820Sensor.WriteByte(0xBE); // Read Scratchpad
ushort temp = Ds1820Sensor.ReadByte();
temp |= (ushort)(Ds1820Sensor.ReadByte() << 8);
float Celcius = (float)(temp) * 0.5f;
There is an ever more precise method to get the temperature if you consider all the bytes that you could read from the ds1820:
if (Ds1820Sensor.Reset())
{
Ds1820Sensor.WriteByte(0x55); //Match ROM
Ds1820Sensor.Write(address, 0, address.Length);
Ds1820Sensor.WriteByte(0x44); //Start conversion
while (Ds1820Sensor.ReadByte() == 0)
{
;
}
Ds1820Sensor.Reset();
Ds1820Sensor.WriteByte(0x55); // Match ROM
Ds1820Sensor.Write(address, 0, 8);
Ds1820Sensor.WriteByte(0xBE); // Read Scratchpad
ushort temp = Ds1820Sensor.ReadByte(); //LSB
temp |= (ushort)(Ds1820Sensor.ReadByte() << 8); // MSB
ushort register = Ds1820Sensor.ReadByte();
register |= (ushort)(Ds1820Sensor.ReadByte() << 8);
ushort reserved = Ds1820Sensor.ReadByte();
reserved |= (ushort)(Ds1820Sensor.ReadByte() << 8);
byte countRemain = Ds1820Sensor.ReadByte();
byte countPerC = Ds1820Sensor.ReadByte();
byte CRC = Ds1820Sensor.ReadByte();
float Celcius = (float)(temp) * 0.5f - 0.25f + (((float)countPerC - (float)countRemain) / (float)countPerC);
Be carefull about the cast in float.
Wrong positionning of the cast might truncate the result and introduce some errors.
I hope this will help …
Bye.
DGA2011,
First you sholud take care how your DS18B20 is configure, as temperature precision could be from 9 to 12 bits.
The simpless way I found to caluculate it (assum that you are on default 12 bits configuratiojn) is :
float temp=(Ds1820Sensor.ReadByte()|(Ds1820Sensor.ReadByte()<<8))*0.0625;
By default DS18B20 return Celsius temp, and this is not necessary an integer and it could be negative (from -55 to +125).
For information :
T° Precision Coef
9 bits 0.5
10 bits 0.25
11 bits 0.125
12 bits 0.0625
Rgds Pascal.