# JUnebug with OW device

Status
Not open for further replies.

#### MrDEB

##### Well-Known Member
been hacking at this most of the day.
Thought I had found the problem but to no avail
I connected a NEW ds18B20 to Junebug via the con4 port.
used this code, programed the Junebug, using pickit2 clicked on the usart tool.
perhaps something in the code hopefully.
Have A3 to pin 3, A4 to DQ and then grd (con4 connections)
nothing??
Code:
// device and clock speed...
device = 18F1320
clock = 8
config OSC = INTIO2, WDT = OFF, LVP = OFF

// import modules...
include "DS18B20.bas"
include "convert.bas"
include "usart.bas"

// FAMILY $28 ($1D) ($0000002CDBAE) <- DS18B20 // FAMILY$28 ($3F) ($0000002CD16E) <- DS18B20
const Sensor_A(8) as byte = ($28,$AE, $DB,$2C, $00,$00, $00,$1D)
const Sensor_B(8) as byte = ($28,$6E, $D1,$2C, $00,$00, $00,$3F)

// display a sensor value...
sub DisplaySensor(byrefconst pID() as byte)
dim TempA as shortint
dim TempB as word
RomID = pID
Convert
GetTemp(TempA, TempB)
USART.Write(DecToStr(TempA),".",DecToStr(TempB,2), $BA, "C",13,10) end sub // program start... SetBaudrate(br115200) SetPin(PORTA.4) while true DisplaySensor(Sensor_A) DisplaySensor(Sensor_B) delayms(1000) wend [/code/ #### Pommie ##### Well-Known Member Most Helpful Member Here is what worked for me, Code: Device = 18F1320 Clock = 8 // 8MHz clock Config OSC = INTIO2, WDT = OFF, LVP = OFF include "OW.bas" Include "USART.bas" Include "DS18B20.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) //Skip 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

#### MrDEB

##### Well-Known Member
Not really sure of how to debug except try different things like inserting an LED=HIGH into the code to get an idea of what is going on.
Am just a newbi at this PIC stuff but learning as I go.
I guess I use the trial and error method then discover what each command does.
Thinking that this present code is reading the temp sensor only once then displaying only that temperature?
Might try using the FIND command as presented in another temperature code for the 18F452.

#### 3v0

##### Coop Build Coordinator
Forum Supporter
Trial and error is ok as far as it goes. But you need to be able to follow the program flow and inspect the value of your variables.

Learn to use a debugger or debug by printing to the uart and watching the results in hypertem.

Last edited:

#### Pommie

##### Well-Known Member
Which code isn't working?

The first code you posted expects two sensors with specific ROM numbers to work. Do you know the ROM number of your device?

The code I posted should just work. The steps to get it to work are,
1. Place a DS18B20 into con4 on the junebug with the flat side facing the USB socket.
2. Compile the above code in Swordfish.
3. Use the PICkit2 programming software to program the Junebug after loading the hex file. See first attachment.
4. Select Menu Tools->UART Tool and click connect. See second attachment.

Edit, forgot one thing, for this to work, Junebug switches 1 to 4 need to be switched on. These are Tutor and TX.

Mike.

#### Attachments

• PK2.png
46.6 KB · Views: 94
• UART.png
50.1 KB · Views: 107
Last edited:

#### MrDEB

##### Well-Known Member
I get the same temperature reguardless of applying a finger or ? to sensor body.
Looking at the code you posted (only code I could get that actually worked and displayed ROMid)
I see where the math dosn't make any real sense? and it "looks like" the code only gets the sensor temp only one time?
I am inserting LED indicators and delay lines to slow down the readings so I can SEE what is going on.
I need to learn MPlab better for sure to learn debugging.

#### 3v0

##### Coop Build Coordinator
Forum Supporter
If you are not using the MPLAB debugger now is the time to learn. You can set a breakpoint and the code will run to that line and stop. Then you can look in the local window to see what values your variables have. For non local variables you need to look at them in a watch window.

Once you can do that it will be a lot easier to help you with code.

Last edited:

#### MrDEB

##### Well-Known Member
will try using the debugger after I find out how to get the dang MPLAB with a code running first

#### Pommie

##### Well-Known Member
What ROMid do you get?

I have never managed to get Swordfish working with MPLAB. Has anyone else?

Mike.

#### MrDEB

##### Well-Known Member
using Swordfish and pickit2 here are the ROMid #'s
2874c05b2007b
2866c15b20083
2865cd5b200fb
28b295b200c3
2851a05b20037
they all say 21.5 C
I still think the code you posted only retrieves the temp one time
Have two sensors in frezzer and going to test them to see if temp changed.
I also wonder about your temp conversion? divide by 4 as well as multiply by 256

#### MrDEB

##### Well-Known Member
trying different code just to see buit its for a 452 not a 1320
changed device and int2 etc.
seen this before but ??

#### Pommie

##### Well-Known Member
Ahh ha, just realized the problem. My bad, I am using a DS18S20.

Try this code,
Code:
Device = 18F1320
Clock = 8 // 8MHz clock
Config OSC = INTIO2, WDT = OFF, LVP = OFF

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

Dim Temperature as Word
Dim i as Byte
Dim ROM(8) 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
USART.Write("Rom = ")
for i = 0 to 7
USART.Write(right("00"+HexToStr(ROM(i)),2))
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
if ROM(0)=\$28 then
Temperature=Temperature/8
endif
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

Mike.

#### MrDEB

##### Well-Known Member
That would make a difference.
Will try out your new code.
QUESTION- in the data sheet it has a wiring diagram with the #1 pin N/C (grd)
I wonder if this makes any difference?

#### Pommie

##### Well-Known Member
Pin #1 is left disconnected if the device is parasitically powered which, in this case, it isn't.

Mike.

Status
Not open for further replies.

Replies
34
Views
3K
Replies
5
Views
2K
Replies
6
Views
1K
Replies
39
Views
2K
Replies
3
Views
796