Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

june bug con4 & DS18S20

Status
Not open for further replies.

ghostman11

Well-Known Member
i have a number of DS18S20 and i assume i can connect theese to the junebug directly via con4, what i would like to know is wich way round do i connect it? i have looked at the circuit diagram for con4 and to me it looks like i cant just plug the DS18S20 into it as the pin config is wrong (5v centre pin) does that mean i have to mount the DS18S20 on a sep board and wire from that? i have included a diagram from the DS18S20 data sheet
 
ok messed up upload of pic :D here it is hopefuly
 

Attachments

  • dallas.png
    dallas.png
    15.7 KB · Views: 243
Con4 has A3, A4, Gnd and so you can plug a DS1820 into it. You just have to make A3 output and high to power it. Or, you could use parasitic power.

Was you looking at Con5?

Mike.
 
i was looking at con4 according to the circuit diagram in the assembly manual. i may be reading it wrong :D i will post a pic of it from the manual. wich way round do i put the DS18S20 into con4? thanks pom
 
Just make sure the gnd pin is connected to ground and all will be fine. You can then make A3 high and use A4 as the OW pin.

Mike.
 
ok i found this

Device = 18F1320
Clock = 8
Config OSC = INTIO2, WDT = OFF // Use the Internal Oscillator
Include "DS18B20.bas"
Include "convert.bas"
Include "usart.bas"

Dim
TempA As ShortInt,
TempB As Word

OSCCON = $72
High(PORTA.3) // power DS18S20
SetBaudrate(br9600)
SetPin(PORTA.4)

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

End



how do i convert it to work with the DS18S20
 
This is the code I used to access a DS1820.
Code:
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF

include "OW.bas"
Include "USART.bas"
Include "CONVERT.bas"

Dim Temperature as Word
Dim i as Byte

OSCCON = $72            // select 8MHz internal clock
ADCON1  = $7f           //all digital
TRISA.3=0               //A3 output
PORTA.3=1               //and high
SetBaudrate(br9600)
OW.SetPin(PORTA.4)
while true
    if OW.Reset then
        OW.WriteByte(owReadROM)    //Read ROM
        USART.Write("Rom = ")
        for i = 0 to 7
            USART.Write(HexToStr(OW.ReadByte()))
        next
        OW.Reset
        OW.WriteByte(owSkipROM)    //Skip ROM
        OW.WriteByte($44)          //Convert
        OW.Reset
        OW.WaitForHigh              //wait for convert to finish
        OW.Reset
        OW.WriteByte(owSkipROM)    //Skip Rom
        OW.WriteByte($be)          //Read Scratch Pad
        Temperature=OW.ReadByte()
        Temperature=(Temperature+OW.ReadByte()*256)/2
        USART.Write(" Temperature = ",DecToStr(Temperature),"C.",13,10)
    else
        USART.Write("No device found", 13, 10)
    endif
    DelayMS (100)
wend
End

Once the code is running you can use the UART tool in the stand alone PK2 software to see the attached.

Mike.
 

Attachments

  • uart.png
    uart.png
    49.7 KB · Views: 183
Last edited:
Good to hear it's working. I'll bet it doesn't say 29C on your screen.

For slightly better accuracy you can change it to,
Code:
        Temperature=OW.ReadByte()
        Temperature=(Temperature+OW.ReadByte()*256)
        USART.Write(" Temperature = ",DecToStr(Temperature/2))
        if (Temperature and 1) = 1 then
            USART.Write(".5")
        endif
        USART.Write("C",13,10)    
    else
        USART.Write("No device found", 13, 10)
    endif
    DelayMS (100)
wend

Have fun.

Mike.
 
Code:
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF

include "OW.bas"
Include "USART.bas"
Include "CONVERT.bas"

Dim Temperature as Word
Dim i as Byte

OSCCON = $72            // select 8MHz internal clock
ADCON1  = $7f           //all digital
TRISA.3=0               //A3 output
PORTA.3=1               //and high
SetBaudrate(br9600)
OW.SetPin(PORTA.4)
while true
    if OW.Reset then
        OW.WriteByte(owReadROM)    //Read ROM
        USART.Write("Rom = ")
        for i = 0 to 7
            USART.Write(HexToStr(OW.ReadByte()))
        next
        OW.Reset
        OW.WriteByte(owSkipROM)    //Skip ROM
        OW.WriteByte($44)          //Convert
        OW.Reset
        OW.WaitForHigh              //wait for convert to finish
        OW.Reset
        OW.WriteByte(owSkipROM)    //Skip Rom
        OW.WriteByte($be)          //Read Scratch Pad
                Temperature=OW.ReadByte()
        
        USART.Write(" Temperature = ",DecToStr(Temperature/2))
        if (Temperature and 1) = 1 then
            USART.Write(".5")
        endif
        USART.Write("C",13,10)    
    else
        USART.Write("No device found", 13, 10)
    endif
    DelayMS (100)
wend

   end



ok i gone wrong somewhere :D man i cant believe people play with this stuff for fun

woohoo found out how to put code in a box on here lol:p
 
Last edited:
You missed a line,
Code:
        Temperature=OW.ReadByte()
        [COLOR="Red"]Temperature=(Temperature+OW.ReadByte()*256)[/COLOR]
        USART.Write(" Temperature = ",DecToStr(Temperature/2))
        if (Temperature and 1) = 1 then
            USART.Write(".5")
        endif
        USART.Write("C",13,10)    
    else
        USART.Write("No device found", 13, 10)
    endif
    DelayMS (100)
wend

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top