buy hot The Fixer cool video Year One download Kasabian album nice Terminator Salvation hit cool track Jordin Sparks USA Whatever Works video download Check My Brain melodies nice video Finding Nemo nice Pop - Various Artists hit cheap DIVX Year One

digital-diy.com

Swordfish Tutorial - DS18B20 Temperature Sensor Print E-mail
( 1 Vote )
  
Saturday, 04 April 2009 09:00

images1

There are 3 Dallas digital temperature sensors, so be sure to get the correct one. There is the 1820, 18S20 and 18B20. The 18S20 is the successor to the 1820, and does not drift over time. The 18B20 is further enhanced, and offers faster conversions. Be aware that the 1820 and 18S20 will not function correctly with this 18B20 example.


The basic wiring diagram;

 

18f18b201

 

 

Be sure to attach the 4.7K pull-up resistor to the databus, this is a requirement of the Dallas 1-Wire system. Most of the popular One Wire devices have their own libraries within Swordfish, I'm using the DS18B20 library to make this as simple as possible. Note that Swordfish also has an extensive One Wire library should you want to create your own custom interfacing module.

Device = 18F452
Clock = 20
 
// import modules...
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"
 
// working variables...
Dim
   TempA As ShortInt,
   TempB As Word
 
// Start Of Program...
SetBaudrate(br19200)
SetPin(PORTC.0)
 
// Find() will search the bus for a single DS1820 device
// and load its ROM ID into the DS1820 public variable RomID - you
// could do this manually. For example, RomID = MyRomID...
 
If DS18B20.Find Then
    While true
      Convert
      GetTemp(TempA, TempB)
      USART.Write(DecToStr(TempA),".",DecToStr(TempB,4), " C", 13, 10)
      DelayMS(1000)
    Wend  
Else
    USART.Write("No device found", 13, 10)
EndIf

 

Comments (5)
  • Graham

    Yes, it is a software driven library that allows any pin to be defined via SetPin(PORT.Pin).

    Be wary of analogue pins etc - make sure they are configured correctly.

  • MrDEB  - using for multiple temps

    not familiar with your statement
    // Find() will search the bus for a single DS1820 device
    // and load its ROM ID into the DS1820 public variable RomID - you
    // could do this manually. For example, RomID = MyRomID...
    what I want to do is use this module for 3 possibly 4 refrigerators.
    hopefully the furtherest is 50 feet away from PIC and it hopefully will still work?
    how can I institute this code to read out 4 separate temps?
    am assuming that dim 4 seserate ports for each temp sensor Temp 1 as word, temp 2 as word.
    Theres a method to define the 4 temp as word??

  • Graham

    Hi MrDEB,

    There's a couple of ways to do this, direct addressing each device will probably be the easiest. You will need to make a separate program that reads the ROMID from 1-Wire devices - allowing you to discover each ID one at a time.

    Create constants that can be used to address each device, and as the comment suggests; you can more or less address each via RomID = MyRomID_1 or RomID = MyRomID_2 etc.. (more info in the SF help file as well)

    Here's some info when considering length http://www.maxim-ic.com/app-notes/index.mvp/id/148

  • Anonymous  - Now I am really LOST

    went to the link you posted, very informative.
    Thinking that the farthest run to a sensor is 50 feet or less (closer to 30ft) I should be alright so adding pull-up resistors etc may not be needed?
    as for configuration, 3 sensors can be on one wire and forth sensor on its own wire.
    maybe easier to connect to a separate input pin on the PIC to eliminate noise or banging?? impedance issues etc??
    Received sensors in mail. now to get the LCD program working then the temp added in.

Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
Security
Please input the anti-spam code that you can read in the image.
Last Updated ( Saturday, 18 April 2009 07:17 )