It's playtime again and I have been poking about with the DS18B20-PAR Temperature Sensor with a 16F18326 and a SSD1307 GLCD Display. I have it up and running and it is performing a Read cycle every 2 Seconds which is what is supposed to be happening if I have read the demo file correctly.
My problem is that it is not displaying the correct temperature or registering any increase in temperature when it should.
The Datasheet draws attention to the fact that the temperature sensor is user-configurable to 9, 10, 11, or 12 bits, which corresponds to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default resolution at power-up is 12-bit.
My problem being is that I don’t seem to be able to locate anything in the demo code or the DS18B20.h file relative to setting the conversation rate which is where I feel the problem is resting
As always your help and input is appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The dallas semi "PAR" (for parasitic) 1-wire temp devices are a special case scenario where only two wires are needed to drive the device. Commonly given out when asked for samples, ask me how I know :). A nfet is used to pullup the DQ line to source voltage for additional current, in addition to the 1-wire pullup resistor. Take a look at the data sheet on how this done.
Getting 85C is the default reading that you will get from the scratchpad I think whether the device is working properly or not.
GCB does not support this PAR mode directly, although I may have previously released a header file on this, I can't remember. Attached is a header file that should handle the PAR devices, it has been awhile, if you want to try it.
With the attached file, some defines will be required for the ds18b20 and the PAR mode.
#include<NewReadTemp.h>'requireddefines#define ds18b20#define DQ PortX.x#define ReadTemp_Pullup PortX.x 'gate pin of nfet like 2n7000#define PAR#define ReadTemp_12bits 'values 8-12'negvaluescanbeoutputbyreadingifflag"ReadTemp_Neg"istrueorfalse
EDIT: revised npn or nfet, to just nfet for PAR pullup
The data sheet says to use mosfet for the PAR pullup, so revised previous post to reflect that. I think I used a 2n7000 if my memory serves me correctly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have found the PAR devices to be a pain in the rump. I wont use them. Unless you are really needing to conserve every microwatt of enegy, suggest you ditch the PAR device and get the regular one. Otherwise be prepared to jump through a few hoops.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you all, I didn't know there was that much difference I have taken your advice William and ordered the regular Maxim DS18B20+ so that I can get a handle on the code.
I'll take a look at Kent's solution once I have acheived what I'm looking for. Looks like a very interesting challenge but as always at present, a good bit above my current Pensiongrade....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you have some 2n7000 nfets (any handy logic level nfet actually)? If not, they are always handy for small power switching projects. If yes, than it is not a big deal to hookup for the PAR device. Forgot to mention the call to the above library function is "OWTemp".
The Dallas devices arived this morning. Plugged them in situ and Bingo !! all working. I will definately try out the PAR devices once I am more familiar with these.
What I am looking to do is to try and have the micro run two temperature sensors for our two freezers in the utility room (an area I don't frequent two often - two busy with these projects!) to monitor the temperature and if it looks like the temperature is going hairwire it will signal my alarm system which will send me a text home or away. Well, thats the plan anyway.
So, my first plan is to have the reading displayed in decimal increments (21.6°C as oposed to 21°C)
Next have the code operate an alarm sense condition i.e. above -14°C trigger an alarm.
Then have the code run two DS18B20+'s which I have seen someone do on another thread here.
This should keep me busy until about the Christmas q8o)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The demo shows how to read the ROM, see ..\GCB@Syn_97\GreatCowBasic\Demos\Temperature Sensor Solutions\DS18B20 Sensor Solutions\Sensor ROM Read to LCD\DS18B20 ROM Read to LCD 1Wire supporting LCD_IO_0 mega168.gcb - there are other examples in the same folder.
Once you 'know' the ROM code you can address directly.
Enjoy... the next step in your project.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm looking at the demo examples but the solution I'm looking for is to display the temperature to 1 decimal place appears to be surrounded in fairly complex mathematics in the DS18B20.h file. is there any shortcuts I can use to achieve what I'm looking for?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
..\GCB@Syn\GreatCowBasic\Demos\Temperature Sensor Solutions\DS18B20 Sensor Solutions\Sensor to Hardware Serial Terminal
This demo shows how to obtain an accurate temp.... so, use same method and then just display the first character after the decimal point. So, just print the number as a string.
Or, adapt the maths to only return a single decimal place.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Theo, Wow ! that looks impressive but it is really well above my pensiongrade as far as a programming skills go.
On my bucketlist I have so far managed to get down to the third item which is to have the processor read two DS18B20+'s run simultaneously display both temperatures but I'm stuck as to how to go about it.
Finally did I read your project correctly that you have chained your sensors up to 15 metres away from the microprocessor. That is one of the queries I have, 'How far can I reasonably extend the sensors on decent quality screened cable from the source and signal return, I think the answer is buried somewhere in the datasheet but I don't seem to be able to find it clearly stated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Keith; always nice to get some response on programs that one has published.
If you would like to know how long a long wire could be: read AN 148: "Guidelines for Reliable Long Line 1-Wire Networks";
For the topology: read AN162: "Interfacing the DS18X20/DS1822 1-Wire® Temperature Sensor in a Microcontroller Environment"
www.maximintegrated.com
How to start with multiple sensors connected to a multidrop:
1.identify the Rom-ID of the sensors you've planned to use; you could use the standard code from
GCB to do that or use my code. The advantage of my code is that it shows the power mode:
normal or parasitic power mode(notice that you need an OWinBit routine for that).
It also calculates the CRC, so there's no doubt about the communication with the sensor (and thus
the ID of the sensor).
2.create a multidrop by connecting 2 or more sensors(no mix of normal and parasitic ones) to the
same wiring(see below) with a resistor of 2700 ohm(2K7).
3.create some code that addresses and reads the individual sensor : (look into my code how it's
done)
Loop
read in: RomID
gosub Readtemp
wait some time
read in:(next) RomID
gosub Readtemp
wait some time
end loop
Readtemp:
MasterRST
OWout MatchRom
OWout RomID
OWout ReadScratch
OWin Romregisters
Calculate CRC
Calculate temperature
display temperature
return
Wiring:
For a home application there's no need to create some difficult and expensive wiring: just take an ethernet cable of 10 or 20 meters; use a twisted pair of wires for the DQ(data) and GND connection, and another wire for Vdd. That's it.
Theo.
Last edit: Theo 2017-05-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Theo
You Wrote' >you could use the standard code from
GCB to do that or use my code. The advantage of my code is that it shows the power mode:normal or parasitic power mode
Can I bother you for a copy of your code please. I'm using TbL with an I2C bus and I can view the devices on the I2C bus but I cannot see the DS18B20+ device (because it's not on the I2C Bus Duh !)
Last edit: Keith 2017-05-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could someone please help me with the syntax in this line. I really need to get this to work as it is going hairwire when the temperature goes negative.
Text from the GCB Helpfile:
The Str function will convert a number into a string. Number can be any byte or word variable, or a fixed number between 0 and 65535 inclusive.
The string variable stringvar will contain the same number, represented as a string.
This function is especially useful if a number needs to added to the end of a string, or if a custom data sending routine has been created but only supports the output of string variables.
Having said that:
the printroutines of GCB are not happy when you manipulate a (complicated) string within a print routine,
You have to separate them;
Example:
Dim temp$ as string * 10 'long enough for this example
Yes, I had read that prior to asking but I thought perhaps someone with much more programming experience than me knew of a workaround to concatenate the strings rather than a handful of clumsy looking conditional statements.
Oh well, thanks for the replies – soldier on !
@ William, I'm not having much joy reading from two DS18B20+ devices. spent best part of a day on it but my programming skills are letting me down. I have put that part aside for the time being as it is doing my head in.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's playtime again and I have been poking about with the DS18B20-PAR Temperature Sensor with a 16F18326 and a SSD1307 GLCD Display. I have it up and running and it is performing a Read cycle every 2 Seconds which is what is supposed to be happening if I have read the demo file correctly.
My problem is that it is not displaying the correct temperature or registering any increase in temperature when it should.
The Datasheet draws attention to the fact that the temperature sensor is user-configurable to 9, 10, 11, or 12 bits, which corresponds to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default resolution at power-up is 12-bit.
My problem being is that I don’t seem to be able to locate anything in the demo code or the DS18B20.h file relative to setting the conversation rate which is where I feel the problem is resting
As always your help and input is appreciated.
Odd... what value is the method returning?
Let me know what is being displayed. This may help me.
Let me know what is being displayed. This may help me.
It is giving a constant reading of 85° C and 185° F (In your words a picture tells a thousand words)
Last edit: Keith 2017-05-21
The dallas semi "PAR" (for parasitic) 1-wire temp devices are a special case scenario where only two wires are needed to drive the device. Commonly given out when asked for samples, ask me how I know :). A nfet is used to pullup the DQ line to source voltage for additional current, in addition to the 1-wire pullup resistor. Take a look at the data sheet on how this done.
Getting 85C is the default reading that you will get from the scratchpad I think whether the device is working properly or not.
GCB does not support this PAR mode directly, although I may have previously released a header file on this, I can't remember. Attached is a header file that should handle the PAR devices, it has been awhile, if you want to try it.
With the attached file, some defines will be required for the ds18b20 and the PAR mode.
EDIT: revised npn or nfet, to just nfet for PAR pullup
Last edit: kent_twt4 2017-05-22
The data sheet says to use mosfet for the PAR pullup, so revised previous post to reflect that. I think I used a 2n7000 if my memory serves me correctly.
I have found the PAR devices to be a pain in the rump. I wont use them. Unless you are really needing to conserve every microwatt of enegy, suggest you ditch the PAR device and get the regular one. Otherwise be prepared to jump through a few hoops.
Thank you all, I didn't know there was that much difference I have taken your advice William and ordered the regular Maxim DS18B20+ so that I can get a handle on the code.
I'll take a look at Kent's solution once I have acheived what I'm looking for. Looks like a very interesting challenge but as always at present, a good bit above my current Pensiongrade....
Do you have some 2n7000 nfets (any handy logic level nfet actually)? If not, they are always handy for small power switching projects. If yes, than it is not a big deal to hookup for the PAR device. Forgot to mention the call to the above library function is "OWTemp".
@keith
take a look at:
https://sourceforge.net/p/gcbasic/discussion/629990/thread/1b9bd1b2/
and
https://sourceforge.net/p/gcbasic/discussion/629990/thread/1d444d66/
That might help you.
The Dallas devices arived this morning. Plugged them in situ and Bingo !! all working. I will definately try out the PAR devices once I am more familiar with these.
What I am looking to do is to try and have the micro run two temperature sensors for our two freezers in the utility room (an area I don't frequent two often - two busy with these projects!) to monitor the temperature and if it looks like the temperature is going hairwire it will signal my alarm system which will send me a text home or away. Well, thats the plan anyway.
So, my first plan is to have the reading displayed in decimal increments (21.6°C as oposed to 21°C)
Next have the code operate an alarm sense condition i.e. above -14°C trigger an alarm.
Then have the code run two DS18B20+'s which I have seen someone do on another thread here.
This should keep me busy until about the Christmas q8o)
The demo shows how to read the ROM, see ..\GCB@Syn_97\GreatCowBasic\Demos\Temperature Sensor Solutions\DS18B20 Sensor Solutions\Sensor ROM Read to LCD\DS18B20 ROM Read to LCD 1Wire supporting LCD_IO_0 mega168.gcb - there are other examples in the same folder.
Once you 'know' the ROM code you can address directly.
Enjoy... the next step in your project.
I'm looking at the demo examples but the solution I'm looking for is to display the temperature to 1 decimal place appears to be surrounded in fairly complex mathematics in the DS18B20.h file. is there any shortcuts I can use to achieve what I'm looking for?
..\GCB@Syn\GreatCowBasic\Demos\Temperature Sensor Solutions\DS18B20 Sensor Solutions\Sensor to Hardware Serial Terminal
This demo shows how to obtain an accurate temp.... so, use same method and then just display the first character after the decimal point. So, just print the number as a string.
Or, adapt the maths to only return a single decimal place.
Well, here is my offering thus far which is a 16F18326 and a SSD1307 GLCD Display with the TinyBootloader. Big thank you Evan.
Last edit: Keith 2017-05-24
@Theo, Wow ! that looks impressive but it is really well above my pensiongrade as far as a programming skills go.
On my bucketlist I have so far managed to get down to the third item which is to have the processor read two DS18B20+'s run simultaneously display both temperatures but I'm stuck as to how to go about it.
Finally did I read your project correctly that you have chained your sensors up to 15 metres away from the microprocessor. That is one of the queries I have, 'How far can I reasonably extend the sensors on decent quality screened cable from the source and signal return, I think the answer is buried somewhere in the datasheet but I don't seem to be able to find it clearly stated.
Thank you Keith; always nice to get some response on programs that one has published.
If you would like to know how long a long wire could be: read AN 148: "Guidelines for Reliable Long Line 1-Wire Networks";
For the topology: read AN162: "Interfacing the DS18X20/DS1822 1-Wire® Temperature Sensor in a Microcontroller Environment"
www.maximintegrated.com
How to start with multiple sensors connected to a multidrop:
1.identify the Rom-ID of the sensors you've planned to use; you could use the standard code from
GCB to do that or use my code. The advantage of my code is that it shows the power mode:
normal or parasitic power mode(notice that you need an OWinBit routine for that).
It also calculates the CRC, so there's no doubt about the communication with the sensor (and thus
the ID of the sensor).
2.create a multidrop by connecting 2 or more sensors(no mix of normal and parasitic ones) to the
same wiring(see below) with a resistor of 2700 ohm(2K7).
3.create some code that addresses and reads the individual sensor : (look into my code how it's
done)
Loop
read in: RomID
gosub Readtemp
wait some time
read in:(next) RomID
gosub Readtemp
wait some time
end loop
Readtemp:
MasterRST
OWout MatchRom
OWout RomID
OWout ReadScratch
OWin Romregisters
Calculate CRC
Calculate temperature
display temperature
return
Wiring:
For a home application there's no need to create some difficult and expensive wiring: just take an ethernet cable of 10 or 20 meters; use a twisted pair of wires for the DQ(data) and GND connection, and another wire for Vdd. That's it.
Theo.
Last edit: Theo 2017-05-25
@Theo
You Wrote' >
you could use the standard code from GCB to do that or use my code. The advantage of my code is that it shows the power mode:normal or parasitic power mode
Can I bother you for a copy of your code please. I'm using TbL with an I2C bus and I can view the devices on the I2C bus but I cannot see the DS18B20+ device (because it's not on the I2C Bus Duh !)
Last edit: Keith 2017-05-25
Keith,
The OW bus is completely different compared to the I2C bus.
See my message 3 days ago with the links; those 2 programs have everything in it.
Wow !! that's impressive. Works a treat.
I have added your code modified for 16F18326
Last edit: Keith 2017-05-25
Could someone please help me with the syntax in this line. I really need to get this to work as it is going hairwire when the temperature goes negative.
GLCDPrint(46, 30, str(Whole) + "." + str(dig) + "'C " )
"Whole" is the integer value of the temperture and "dig" is the decimal value
Last edit: Keith 2017-05-26
Keith,
Text from the GCB Helpfile:
The Str function will convert a number into a string. Number can be any byte or word variable, or a fixed number between 0 and 65535 inclusive.
The string variable stringvar will contain the same number, represented as a string.
This function is especially useful if a number needs to added to the end of a string, or if a custom data sending routine has been created but only supports the output of string variables.
Having said that:
the printroutines of GCB are not happy when you manipulate a (complicated) string within a print routine,
You have to separate them;
Example:
Dim temp$ as string * 10 'long enough for this example
temp$ = str(Whole) + "." + str(dig) + "'C "
GLCDPrint(46, 30, temp$)
Theo.
Last edit: Theo 2017-05-26
I had problems with str(val)+" "+str(val2). I had to do it in 2 glcdprints. What is the method?
sorted thanks
Last edit: stan cartwright 2017-05-26
Yes, I had read that prior to asking but I thought perhaps someone with much more programming experience than me knew of a workaround to concatenate the strings rather than a handful of clumsy looking conditional statements.
Oh well, thanks for the replies – soldier on !
@ William, I'm not having much joy reading from two DS18B20+ devices. spent best part of a day on it but my programming skills are letting me down. I have put that part aside for the time being as it is doing my head in.