Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 20:46 27 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM one wire

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1801
Posted: 08:04pm 07 Jul 2013
Copy link to clipboard 
Print this post

This is an excerpt from the one wire routine;

GetTemp 18, Temp
Print "The temperature is:" Temp


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subroutine to get the temperature from a Dallas DS18B20.
' The temperature is returned to the varable used for the
' second argument in the calling program
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub GetTemp (PinNbr, Value)

Can someone tell me why the 18 in (GetTemp 18, Temp), is it the pin no.
if so I take it that 'PinNbr is the same pin'.
Also what is 'value' after 'PinNbr'

PALCAL.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:06pm 07 Jul 2013
Copy link to clipboard 
Print this post

I would guess that is an id number.
You can have many devices on that 1 wire so you need to address it.
If you show more code we can see how it is used.


Edited by TZAdvantage 2013-07-09
Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 08:51pm 07 Jul 2013
Copy link to clipboard 
Print this post

For anyone who is confused, Palcal is referring to the demo routine ONE-WIRE.BAS in the MMBasic Library downloadable from my web site.

PinNbr is the pin that the DS18B20 is connected to. You can use any I/O pin that can operate as open collector (ie, pins 11 to 20).

Temp is the variable that gets the result. Remember that if you use a variable in the parameter list the subroutine can change the value of that variable (which is what that subroutine does). See "Passing Arguments by Reference" on page 14 of the current MMBasic User Manual.

That demo was written before user defined functions became available. Nowadays you would use a function like this:


Print "The temperature is:" GetTemp(18)


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function to get the temperature from a Dallas DS18B20.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function GetTemp (PinNbr)
Local T1, T2, b, t
OWReset PinNbr ' reset
OWWrite PinNbr, 1, 2, &hcc, &h44 ' start conversion
Pause 100
t = Timer
Do
If Timer - t > 1000 Then Error "Sensor not responding"
OWRead PinNbr, 4 , 1 , b ' conversion done?
Loop Until b = 1
OWWrite PinNbr, 1, 2, &hcc, &hbe ' command read data
OWRead PinNbr, 2, 2, T1, T2 ' get the data
GetTemp = ((T2 And &b111) * 256 + T1) / 16
If T2 And &b1000 Then GetTemp = -GetTemp ' adjust if negative
End Function


Geoff
Geoff Graham - http://geoffg.net
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1801
Posted: 09:25pm 07 Jul 2013
Copy link to clipboard 
Print this post

Many thanks TZ and Geoff, I understand.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1801
Posted: 11:19pm 07 Jul 2013
Copy link to clipboard 
Print this post

Well I thought I understood, but I keep getting a reading of zero. Maybe my sensor is kaput but it was OK in a picaxe project I was using.
I will try another DS18B20 when I get one.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024