Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

DS18B20 (or DS18S20+) help needed


  • Please log in to reply
11 replies to this topic

#1 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 28 February 2012 - 07:49 PM

Hi!

I'm struggling with DS18B20 and DS18S20+ sensors. I've got OneWire working thanks to CW2's OneWire firmware build. It reads temperature, everything seems fine, but the room temperature is 20 deg C (measured by two other digital thermometers), but the sensor reports 23.9375 deg C, so it is at least 3 degrees above.

The ND is a ND+ with LC filter attached to AREF, if that should make a difference, although I don't think so, since it is connected do digital I/O. I've tested D0, D5 and D13 (just to make sure).

I uploaded firmware from this post: http://forums.netdui...-onewire-alpha/

I'm using OneWireTestApp, with a simplified button interrupt handler, which is a copy/paste of CW2's sample code to read temperature. Pin1 is connected to ground, Pin2 is connected to I/O and to 5V via ~4.7kOhm resistor and Pin3 is connected to 5V.

Also, when deploying the app through Visual Studio, the debugger says:
Rebooting...

Done.

But then gets stuck. So I manually connect gnd to reset and it then attaches successfully to the ND+. ND+ is powered via USB.

I'd appreciate some pointers or any kind of help, that would send me in the right direction. I had hopes for DS1820 family of sensors, then tried to use KTY-11 thermistors, but had limited luck with them (complex non-linear resistance and huge variations in readings even when using LC filter).

#2 MDS

MDS

    Member

  • Members
  • PipPip
  • 16 posts

Posted 28 February 2012 - 08:34 PM

Is the ds1820 3 degrees different from the digital therms at all temps is it linier? If it is just build in a calibation factor, you have to do that with a lot of parts. As for themistors I have had a lot of luck with using the thermistor as part of a voltage devider, into a ADC and a lookup table. Its resonably accurate. If you need somthing really accurate use a themicouple through an opamp and a look up table.

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 February 2012 - 07:19 AM

DS18B20 thermometer is factory calibrated and has ±0.5°C accuracy - do you know what sensor is in those "two other thermometers" you have as references? In my experience, there is usually thermistor in there, which is less accurate than DS18B20, so I would tend to believe DS18B20 more (unless you have professional-grade reference devices). Also, where do you have DS18B20? Is it close to the other thermometers? Isn't it possible there is a heat source (e.g. power supply, LCD monitor, a table lamp, less air flow etc.) which may increase the local temperature?

#4 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 29 February 2012 - 07:37 AM

DS18B20 thermometer is factory calibrated and has ±0.5°C accuracy - do you know what sensor is in those "two other thermometers" you have as references? In my experience, there is usually thermistor in there, which is less accurate than DS18B20, so I would tend to believe DS18B20 more (unless you have professional-grade reference devices). Also, where do you have DS18B20? Is it close to the other thermometers? Isn't it possible there is a heat source (e.g. power supply, LCD monitor, a table lamp, less air flow etc.) which may increase the local temperature?


I know they are calibrated, that is the reason I think something is wrong with my setup. The other sensors are: air condition remote and temperature sensor probe for digital multimeter. The other thing is my feeling.

Ds18b20 is on a breadboard and I put the probe near it. there arent other heat sources around (except for nd+).

I'll take the setup out where it is cca 10deg and see what it reports there.

I also measured the pullup resistor and it is more like 4.6kohm, but that should not make a difference.

Thanks, Miha.

#5 OppaErich

OppaErich

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationEssen, Germany

Posted 29 February 2012 - 07:38 AM

I went through the same thing. Make sure you measure the temperature at exactly the same spot and your readings will be within a single degree C. ;)

#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 February 2012 - 07:57 AM

Do you power DS18B20 via [the third] VDD pin? If not (i.e. parasitic powered from the data line), try using the external power through VDD, the datasheet recommends it during the measurement (or strong pullup on the data line using a MOSFET).

Also, how often do you perform the measurement? Theoretically, the sensing element could be affected by self-heating when the measurement is done too often, so you could try increasing the time (e.g. once per second).

To verify there is no error in received data, you could read the whole scratchpad (9 bytes) and check the CRC.

#7 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 29 February 2012 - 01:08 PM

Do you power DS18B20 via [the third] VDD pin?

Yes. Though I've tried both options.

Also, how often do you perform the measurement? Theoretically, the sensing element could be affected by self-heating when the measurement is done too often, so you could try increasing the time (e.g. once per second).

I was reading it by pressing the onboard switch. Not more than once per second. Even if I waited 10 or more seconds, the results were the same.

To verify there is no error in received data, you could read the whole scratchpad (9 bytes) and check the CRC.

I did. CRC is valid.

As for the measuring part: I'm measuring in the same spot that the DS18B20 is (actually, I've put the probe on the TO92 housing). There probe s between 20 and 21deg, whereas DS18B20 reports 23.8. I believe I would know the difference between 20 and 24degrees - it seems really odd.

I also took it outside, protected it from the sun. I hooked up serial LCD so I could see what was going on, the thing was powered by external power supply. Outside temperature is 18deg at the moment (as provided by official weather service and by digital multimeter probe, which is actaully touching the housing of DS18B20. The DS18B20 reports 22.3. I'll test again in the evening, when the temperature drops enough so that I can see if the error is linear, as MDS suggested.

I appreciate your help! I believe that the sensor is working fine, and I think there might be something wrong with my ND+ setup (as I mentioned, I have LC filter attached to AREF, though I don't think that should bother it, since it is digital reading). The Vdd is 5.0V (give or take a few mV). The setup is visible here. The sensor is on the breadbord (the one on the left of ND+ is a thermistor I'm not currently using, though it is conencted to analog input). Digital I/O used for OneWire is D13.

Thanks,
Miha.

ps: why can't I use OneWire from my own project? I copied OneWire.cs and other required files, but get not supported exception.

#8 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 February 2012 - 01:55 PM

Thanks for the detailed description. I don't think the sensor readout can be affected by your ND+ setup, as you said the communication is digital and if the CRC is valid, the measurement data should be too. IMHO this leaves us with either bug in the code that calculates the temperature or defective sensor.

ps: why can't I use OneWire from my own project? I copied OneWire.cs and other required files, but get not supported exception.

When does the exception appear? Are you building CW.NETMF.OneWire.dll from sources? Could you please try referencing the original one and Rebuild?

#9 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 29 February 2012 - 08:41 PM

I tested now, when outside temp is 11 degrees. DS18B20 says it is 14.6. I'll test again in the morning. I also found this: http://arduino.cc/fo...p?topic=56307.0 I'll also move resistor further away from sensor and see if this helps. I have two DS18B20 sensors and will try another one as well. Will report back. As for the exception. It occurs on the new OneWire() line. I did not reference the DLL. I just copied OneWire.cs and DS18B20.cs to my project. This should be sufficient, right? (since OneWire.cs references native methods (built in the firmware)). Regards, Miha.

#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 February 2012 - 10:15 PM

As for the exception. It occurs on the new OneWire() line. I did not reference the DLL. I just copied OneWire.cs and DS18B20.cs to my project. This should be sufficient, right? (since OneWire.cs references native methods (built in the firmware)).

I see - if you want to use OneWire classes from CW.NETMF.OneWire.dll, you have to reference the library. The native code is baked into the firmware and when you call the managed method, the runtime searches for the native code that has the same name and matching checksum. So, when you add OneWire.cs to your project, the resulting assembly has different name (and checksum), its native counterpart in the firmware is not found (it does not exist there) and hence the exception.

#11 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 01 March 2012 - 08:34 AM

I tested now, when outside temp is 11 degrees. DS18B20 says it is 14.6. I'll test again in the morning.


So I tested again. The temperature outside is around ~6 and DS18B20 reports 9.3.

I then moved the DS18B20 away from pullup resistor (just to make sure), and the readings are still off. But less (!!).

Now, at room temperature 22, DS18B20 reports 24.3 (so it is not 3degree difference now, it is more like 2).

I guess I'll measure the temp. difference when the sensor will be deployed and then adjust accordingly in the software.

Miha

ps: can I put DS18B20 in the water? (what about wires, etc?) That would make test measurments more accurate IMHO.

#12 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 01 March 2012 - 08:53 AM

So, when you add OneWire.cs to your project, the resulting assembly has different name (and checksum), its native counterpart in the firmware is not found (it does not exist there) and hence the exception.


Thanks! I didn't know it compares the actual assembly with the native counterpart.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.