Newbie ds18b20 questions
#1
Posted 21 June 2011 - 08:46 PM
#2
Posted 25 June 2011 - 04:22 PM
#3
Posted 25 June 2011 - 05:32 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?However when I went to run it I got 3 errors the same saying:
#4
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
Posted 25 June 2011 - 05:51 PM
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
Posted 25 June 2011 - 05:56 PM
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...).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?
#7
Posted 25 June 2011 - 06:03 PM
Just add a loop inside the Main() method:Got it working and it gives me a single temperature reading, how would I get it to loop say one reading per second?
... 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
Posted 26 June 2011 - 11:34 AM
#9
Posted 26 June 2011 - 12:43 PM
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).Not sure if you would know, but are the premade probes fully submersible. ... This is a link: http://www.earthshin...ture-probe.html
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).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?
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.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?
#10
Posted 09 July 2011 - 02:35 PM
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
Posted 09 July 2011 - 03:09 PM
#12
Posted 10 July 2011 - 08:25 AM
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.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 may also want to check out Stuart's DS18*20 Temperature Sensor Auto Identity Circuit.
#13
Posted 10 July 2011 - 08:32 AM
85°C is power-on reset value, so it may indicate the conversion fails. What power mode do you use - parasitic or external supply?then as it tends towards 0 it starts reading 85?
#14
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
Posted 10 July 2011 - 09:04 AM
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?Well, they pretend to have. Mine here is more than 2°C off. Does anyone know a way to calibrate them ?
#16
Posted 11 July 2011 - 01:59 PM
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.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?
Supply Voltage doesn't matter (5V / 3V3). I've used a 4k7 resistor and it's powered - not parasitic.
#17
Posted 11 July 2011 - 03:19 PM
I meant the temperature range - DS18B20 has ±0.5°C accuracy from -10°C to 85°C, it will be slightly worse outside that.Oh, it's 'range', I've read 'rate' first. Well, I did nothing range related, so I don't know.
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.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...
#18
Posted 13 July 2011 - 01:35 PM
#19
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.
#20
Posted 30 July 2011 - 04:32 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users