Hi guys, I'm looking for some help with a DS18B20 temp sensor I have.
First of, I'm pretty new to arduino so appologies if my questions are daft
I can get the sensor to accurately display the temp using the one wire library. What I want to do however is get the sensor displaying the temperature without needing to use a library (I'm going to be running a course with kids and need to be able to fully explain every line of code to them - they have absolutely no programming experience).
I can get a value from the middle pin and am looking for a formula to convert this to an accurate temperature reading. I "think" I read somewhere that you needed to know the power to the sensor but can't find where I thought I seen this.
Can anyone supply (and explain ) a simple one line formula which will achieve this please.
Is there a way that this works also for native DS1820 ? (no DS18x20, they works fine).
I still have a bunch of DS1820 and want to use them...with the normal libs it seems to be impossible - if i use parasit power or not.
Trixi:
Is there a way that this works also for native DS1820 ? (no DS18x20, they works fine).
I still have a bunch of DS1820 and want to use them...with the normal libs it seems to be impossible - if i use parasit power or not.
The old DS1820 has been replaced by the DS18S20. "The primary specification difference between the two parts is the temperature conversion time: DS1820 = 500ms (max) and DS18S20 = 750ms (max)."
The steps on the DS18S20 (and by extension on the DS1820) is 1/2 Degree Centigrade. Take the code above and instead of 16 use 2.
If you need more resolution there is a formula in the datasheet for taking Byte 0 (Temperature LSB), Byte 1 (Temperature MSB), Byte 6 (COUNT REMAIN) and Byte 7 (COUNT PER °C) and calculating temperature to the nearest 1/16th degree.
That looks kind of like what I'm after John, although there are a few bits of the code I don't understand (as I said, I'm new to C and arduino programming).
The following are the main bits I'm unsure about -
Definitely not. So much not, indeed, that I haven't the faintest idea of what your discussion with Wasser is about, but I used the sheepdog stuff when a total newbie.
Sorry, I thought you were already familiar with the OneWire library.
You will have to call StartThermometers() to tell all DS18S20 chips on the OneWire bus to start reading a temperature. 750 milliseconds later you can read the 'scratchpad' of each chip and use the data you read to calculate the temperature.
#include <OneWire.h>
// DS18S20 Temperature chip I/O
const int ONEWIRE_PIN = 9;
OneWire DS18S20(ONEWIRE_PIN);
void startThermometers()
{
DS18S20.reset();
DS18S20.write(0xCC); // Address all thermometers
DS18S20.write(0x44); // start conversion, no parasite power on at the end
}
0xCC is the command that tells ALL devices on the OneWire bus to listen. You can use this in place of .select(address) if you are only sending or you expect an answer (Read Scratchpad) and you only have one device on the bus.
0x44 is the command to calculate the temperature and save it in the scratchpad. This takes up to 750 milliseconds.
0xBE is the command to send the contents of of the scratchpad.
What you are sending is "Everybody: Send your Scratchpad". This only works if you only have one device. Since you don't send any commands to take a new reading you get the same reading every time.
Try:
tempSensor.reset();
tempSensor.write(0xCC); // All devices:
tempSensor.write(0x44); // Start a temperature reading
delay(10000); // Reading takes 750 milliseconds. Waiting longer is OK.
tempSensor.reset();
tempSensor.write(0xCC); // All devices: (must be only one device)
tempSensor.write(0xBE); // Send the content of your scratchpad.
for (int i = 0; i < 9; i++) {
data[i] = tempSensor.read();
}
Thanks so much everyone for your input - the hex numbers were really throwing me, now I see where they are coming from. It was them being listed in code as things like 0xCC but in the datasheet as CCh.