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

Newbie ds18b20 questions


  • Please log in to reply
19 replies to this topic

#1 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 21 June 2011 - 08:46 PM

Hi, So I have got my netduino had a play around and I have managed the LED blink and some other LED blink where it counts the number of times you press the button and flashes the LED that number of times. So now I have decided to get started with working out the various parts of my aquarium control project. I am new to both electronics and visual studio and my background as far as code is in access and excel vba. I tried one electronics project last year which was a dmx transceiver, but I think this was a little over my head especially when it can to flashing the avr. So I have decided the netduino may be a good starting point. First thing with my aquarium project I have decided is the temperature probe. I have wired up my ds18b20 with a 4k7 resistor, but I have no idea where to even begin with getting reading from this. I have search around the forum a fair bit and found these threads to mention but a few: http://forums.netdui...ch__1#entry1505 http://forums.netdui...ch__1#entry5962 I have tried to follow the latter of the two as I couldn't find the firmware referenced in the first, however I got no joy. My issue was regarding the SerialPort _COM1 reference in the class. The error said that "SerialPort" was not reference in the NETMF.hardware? Can anyone guide me how I can implement one wire with a ds18b20, and is there any class library's I need to install/ firmware I need to upgrade? Is 4.1.2 out yet with the one wire support? Also I followed the getting started guide, how do I no I have all the correct class library's etc installed and are there any additional ones I may need in order to achieve this? Finally as the project is going to eventually be sensing and controlling multiple variables as any given time can anyone advise or direct me to information as to the best way to structure/ write my code. My previous experience with vba has been very much after this, call that module/function, do this, then that and so on, however I can see that this is going to require processes to continue running simultaneously. Do I create functions or modules for my various measurements and controls or would it be structured all with the program file with class references or some other way? Thanks for your patience, Andy

#2 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 25 June 2011 - 04:22 PM

I am trying to follow this example: http://forums.netdui...ch__1#entry1505, I flashed the netduino and made a test program using your code examples. However when I went to run it I got 3 errors the same saying: "Error 1 Unable to copy file "C:\Documents and Settings\Claire\My Documents\Downloads\Netduino_v4.1.1_beta1_CW.NETMF.OneWire-1.0.5.0\Solutions\Netduino\Interop\CW_NETMF_OneWire\ManagedCode\bin\Release\BE\CW.NETMF.OneWire.pe" to "bin\Debug\BE\CW.NETMF.OneWire.pe". Could not find a part of the path 'C:\Documents and Settings\Claire\My Documents\Downloads\Netduino_v4.1.1_beta1_CW.NETMF.OneWire-1.0.5.0\Solutions\Netduino\Interop\CW_NETMF_OneWire\ManagedCode\bin\Release\BE\CW.NETMF.OneWire.pe'. NetduinoApplication1" This is my first attempt to use a netduino, probably something simple can any one advise where I am going wrong? Thanks Andy

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 25 June 2011 - 05:32 PM

However when I went to run it I got 3 errors the same saying:

The project should not have references to assemblies in 'BE' folder, but in 'LE' (Netduino is little-endian). Are you using the original test program (OneWireTestApp) or your own? And, is 'Debug' configuration working properly?

#4 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 25 June 2011 - 05:44 PM

The project should not have references to assemblies in 'BE' folder, but in 'LE' (Netduino is little-endian). Are you using the original test program (OneWireTestApp) or your own? And, is 'Debug' configuration working properly?


Hi,

Thanks for your quick reply, I am new to all this so please bear with me...

I have just used your example code in a new project, so I have your program.cs snippet from the thread and the DS18B20.cs from your test app. Debug seems to work correctly, originally I had errors on the DS18B20 references, until I copied your class in. Then when I debugged it gave me the previous error. What do I need to do to reference you OneWire.dll properly?

#5 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 25 June 2011 - 05:51 PM

Got it working and it gives me a single temperature reading, how would I get it to loop say one reading per second?

This is the code I am using as per your example:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using CW.NETMF.Hardware;

namespace NetduinoApplication1
{
    public class Program
    {
        public static void Main()
        {
            var oneWire = new OneWire(Pins.GPIO_PIN_D0); // Adjust the pin if necessary
            if (oneWire.Reset())
            {
                // DS18B20 Thermometer
                oneWire.WriteByte(OneWire.SkipRom); // Address all devices
                oneWire.WriteByte(DS18B20.ConvertT);
                Thread.Sleep(750);                  // Wait Tconv (for default 12-bit resolution)

                oneWire.Reset();
                oneWire.WriteByte(OneWire.SkipRom);
                oneWire.WriteByte(DS18B20.ReadScratchpad);

                // Read just the temperature (2 bytes)
                var tempLo = oneWire.ReadByte();
                var tempHi = oneWire.ReadByte();
                var temp = DS18B20.GetTemperature(tempLo, tempHi); // ((short)((tempHi << 8) | tempLo))/16F
                Debug.Print(temp.ToString());
            }
            Thread.Sleep(Timeout.Infinite);



        }

    }
}


#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 25 June 2011 - 05:56 PM

Referenced your .dll from the LE folder, everything compiled but I can't see any output window. Originally I forgot to switch to usb from emulator and a little output window popped up, but since I changed it to usb output I don't have an output window?

I see, glad to hear the build succeeded. You should be able to show the output window via menu command View\Output (you might need to adjust the window layout a bit...).

#7 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 25 June 2011 - 06:03 PM

Got it working and it gives me a single temperature reading, how would I get it to loop say one reading per second?

Just add a loop inside the Main() method:

...
var oneWire = new OneWire(...);
while(true)
{
  if(oneWire.Reset())
  {
    // ...
  }
  Thread.Sleep(250); // 250 ms delay + 750 ms measurement = 1 second
}
Please note the measurement may be affected by the thermometer's self-heating, when done too often.

#8 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 26 June 2011 - 11:34 AM

Thanks, I managed to snap the leg off it while making a DIY probe so off to get some more. Not sure if you would know, but are the premade probes fully submersible. It's going in my fish tank you see and I don't really want to risk having any stray current in the tank. This is a link: http://www.earthshin...ture-probe.html Also did you manage to have multiples of these working off one wire, I'm not to sure on the terminology is it running off one bus? e.g. 5 in series and you can address each one individually without using any more pins on the netduino than you would use for 1? And what are the bits for on the ds18b20? Does it go up to 16bit readouts and does this make a difference or is it unnecessary? Thanks again for your help, Andy

#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 26 June 2011 - 12:43 PM

Not sure if you would know, but are the premade probes fully submersible. ... This is a link: http://www.earthshin...ture-probe.html

I am not sure about the probe you linked, but I know similar probe from adafruit, which is waterproof. I think it should be possible to make waterproof probe just by isolating the sensor connection with heatshrinks, and then use slightly bigger heatshrink to wrap over the package (as done on the adafruit's probe).

Also did you manage to have multiples of these working off one wire, I'm not to sure on the terminology is it running off one bus? e.g. 5 in series and you can address each one individually without using any more pins on the netduino than you would use for 1?

Yes, it is possible to attach multiple devices on the bus ("multidrop"). If you don't know the identification (ROM ID) in advance, use Search() method to enumerate the devices, then you'd need to hardcode ROM IDs (addresses) in your application to identify individual sensors. In case you'd need to replace a sensor, the application has to be recompiled with updated ROM ID, or the sensor identification would need to be stored externally, e.g. on SD card. To resolve this drawback, you could use different sensors that support additional addressing, such as DS1825 (with 4-bit location address).

And what are the bits for on the ds18b20? Does it go up to 16bit readouts and does this make a difference or is it unnecessary?

DS18B20 has configurable resolution from 9 to 12 bits, it determines the precision and duration of measurement: at 9, 10, 11, 12 bits the precision is 0.5, 0.25, 0.125, 0.0625 °C and the measurement takes 93.75, 187.5, 375 and 750 ms respectively. The extra resolution may be helpful, for example to know if the temperature is on the increase or decline, but keep in mind the sensor has ±0.5 ºC accuracy (from -10 ºC to 85 ºC). For more detailed information, please have a look at the device datasheet.

#10 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 09 July 2011 - 02:35 PM

Hi,

Thanks for the brilliant advice I've just got my probe, a similar one to the adafruit one, probably made exactly the same but at a third of the price on ebay. May do some extra work to guarantee its 100% water proof. I tried putting a loop in 2 different places and neither seemed to produce the expected outcome. Needed another onewire.reset in at the end and it worked!
using System;
using System.Threading;
using System.Collections;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using CW.NETMF.Hardware;

namespace NetduinoApplication1
{
    public class Program
    {
        public static void Main()
        {
            var oneWire = new OneWire(Pins.GPIO_PIN_D0); // Adjust the pin if necessary
            if (oneWire.Reset())
            {
                while (true)
                {
                    // DS18B20 Thermometer
                    oneWire.WriteByte(OneWire.SkipRom); // Address all devices
                    oneWire.WriteByte(DS18B20.ConvertT);
                    Thread.Sleep(750);                  // Wait Tconv (for default 12-bit resolution)

                    oneWire.Reset();
                    oneWire.WriteByte(OneWire.SkipRom);
                    oneWire.WriteByte(DS18B20.ReadScratchpad);

                    // Read just the temperature (2 bytes)
                    var tempLo = oneWire.ReadByte();
                    var tempHi = oneWire.ReadByte();
                    var temp = DS18B20.GetTemperature(tempLo, tempHi); // ((short)((tempHi << 8) | tempLo))/16F
                    Debug.Print(temp.ToString() + " \u00b0" + "C");
                    oneWire.Reset();

                    Thread.Sleep(1000);
                }
            }
        }

    }
}

Also out of interest I never checked but just guessed off the temperature of my hands and the air, is the output in Celsius or Fahrenheit?

The ds1825 that you mentioned I had a look at the spec sheet and was a little confused, they have a unique laser etched address, but do you need this for addressing single chips where multiples exist on onewire, or can you pragmatically assign a value to each chip so you can address them? If so would you need to know which chip is which by their unique address first or could you get the code to handle this. I was think as an example, you have a box with 10 sockets on that allows you to buy your own probes from adafruit or where ever. The sockets are numbered 1 to 10 and the idea would be that you plug in your probes and as you do the code would assign an address automatically. Is this possible with the ds1825's or ds18b20's?

#11 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 09 July 2011 - 03:09 PM

Just testing the temperature readings which seemed really good in one of my aquariums really accurate and steady. Then I tested it from holding it in my hand to putting it on an ice cube and these are the readings I got as follows. You can see it starts of high around 30 then falls gradually, then as it tends towards 0 it starts reading 85? 30.1875 °C 29.4375 °C 28.75 °C 28.125 °C 27.5 °C 26.9375 °C 26.5 °C 26 °C inserted in to ice cube 16.875 °C 8.625 °C 4.0625 °C 85 °C 85 °C 85 °C 85 °C

#12 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 10 July 2011 - 08:25 AM

The sockets are numbered 1 to 10 and the idea would be that you plug in your probes and as you do the code would assign an address automatically. Is this possible with the ds1825's or ds18b20's?

You'd need DS1825 for that - each device in sockets 1 to 10 (or 0 to 9) would have an unique location address, set by connecting AD0 to AD3 pins as described in the datasheet (i.e. sensor #0 will have location address 0000, sensor #1 0001,..., sensor #9 1001). The application then performs 1-Wire search during initialization to discover all the attached sensors and reads their location address (configuration register), so it can create a map (array) of address vs. ROM ID. Or, it could start temperature conversion for all sensors at once (Skip Rom, Convert T), then perform Search and read scratchpad of individual sensors, including the location address (4. byte) to identify them.

You may also want to check out Stuart's DS18*20 Temperature Sensor Auto Identity Circuit.

#13 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 10 July 2011 - 08:32 AM

then as it tends towards 0 it starts reading 85?

85°C is power-on reset value, so it may indicate the conversion fails. What power mode do you use - parasitic or external supply?

#14 OppaErich

OppaErich

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationEssen, Germany

Posted 10 July 2011 - 08:59 AM

...
, but keep in mind the sensor has ±0.5 ºC accuracy (from -10 ºC to 85 ºC). For more detailed information, please have a look at the device datasheet.


Well, they pretend to have. Mine here is more than 2°C off. Does anyone know a way to calibrate them ?

#15 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 10 July 2011 - 09:04 AM

Well, they pretend to have. Mine here is more than 2°C off. Does anyone know a way to calibrate them ?

I don't think they can be calibrated, IMHO you'd need to implement it in software. Just out of curiosity, how often do you perform the temperature conversion? At what range? What is your reference?

#16 OppaErich

OppaErich

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationEssen, Germany

Posted 11 July 2011 - 01:59 PM

I don't think they can be calibrated, IMHO you'd need to implement it in software. Just out of curiosity, how often do you perform the temperature conversion? At what range? What is your reference?

The sensor is called once every few seconds, I've added this to the Arduino 16x2 LCD demo sketch. Oh, it's 'range', I've read 'rate' first. Well, I did nothing range related, so I don't know. What do you mean with 'reference' ? An cheap IN/OUT thermometer and my body. It's 25°C in my room according to my thermometer and the DS18B20 shows almost 28°C, at 28°C I would start to sweat even in 'idle' mode.

Supply Voltage doesn't matter (5V / 3V3). I've used a 4k7 resistor and it's powered - not parasitic.

#17 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 11 July 2011 - 03:19 PM

Oh, it's 'range', I've read 'rate' first. Well, I did nothing range related, so I don't know.

I meant the temperature range - DS18B20 has ±0.5°C accuracy from -10°C to 85°C, it will be slightly worse outside that.

An cheap IN/OUT thermometer and my body. It's 25°C in my room according to my thermometer and the DS18B20 shows almost 28°C...

I see. In my experience DS18B20s are rather precise, so the difference may be caused by some heat source near the sensor (power supply, LCD monitor etc.; measurement once every few seconds should not cause self-heating), or it may be positioned at place where it is not affected by airflow (unlike the reference thermometer or your body) etc.

#18 OppaErich

OppaErich

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationEssen, Germany

Posted 13 July 2011 - 01:35 PM

Hmm, I guess I stand corrected. I've placed the thermometer close to the sensor and the difference dropped to 1.5C. The sensor is close to the display (right under the resistor). Although the display does not feel hot, its temperature has to be higher than ambient temps. I will try to get some distance with some wires. Stephan http://foto.arcor-on...73039363264.jpg Yep, that's it. At first the difference was 4C but after a while it dropped to 0.7C, if both failures add up unlucky we're there. Just holding my hands close (~1") to the sensor is raising the temperature quickly. Cheers, Stephan PS: Patience is the key - I'm down to 0.4C now. B)

#19 Stuart Crawshaw

Stuart Crawshaw

    Advanced Member

  • Members
  • PipPipPip
  • 60 posts
  • LocationLeeds, United Kingdom

Posted 13 July 2011 - 02:00 PM

You may also want to check out Stuart's DS18*20 Temperature Sensor Auto Identity Circuit.


Thanks for the link to my topic! Just to update on this, i am awaiting components to build the circuit, just need some transistors really. Currently working on the code to do the hard work and then ill post it all on my thread.

In theory, with my idea, you would have as many sensors on the bus as needed (buy you would need a transistor for each of them to turn them on/off) and a shift register per eight sensor/transistor pairs.

so in the case of 8 sensors, you would send 1 byte to the shift registor to set pin 0 high and the rest low -> read the ROM code from the sensor bus, and then turn off pin 0 and turn pin 1 on etc etc... at the end send all 1's to the SR and all sensors will be active.
Intelligent People Aren't Afraid To Ask For Help.

#20 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 30 July 2011 - 04:32 PM

hi sorry for taking so long to reply, thanks for the response. I'm measuring a fish tank so in reality it wouldn't matter that the temp doesn't read below 4 degrees but it just seemed a little strange and from a learning perspective I fancied making sure that I could read the entire range of temps. I am using parasitic currently while I am testing, and read temps about every 5 seconds. How would I best approach the 85 degree power issue? Also slightly off topic how do you write a degree sign to an lcd, I can do in a debug.print but can't work it out on the lcd. I have a 128x64 sparkfun serial graphic display. Also having issues with a really slow write time. For instance I know have an rtc hooked up and the time including seconds is displayed, however it takes nearly a second to fully rewrite the screen and you get this flickering effect.




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.