Pin - is a variable/constant which specifies the input pin to use.


Read serial number from any Dallas/Maxim 1-wire device.

This command (read-one-wire-serial-number) reads the unique serial number from any Dallas 1-wire device (e.g DS18B20 digital temp sensor, DS2415 clock, or DS1990A iButton). If using an iButton device (e.g. DS1990A) this serial number is laser engraved on the casing of the iButton.

The readowsn command reads the serial number and then puts the family code in b6, the serial number in b7 to b12, and the checksum in b13 Note that you should not use variables b6 to b13 for other purposes in your program during a readowsn command.

This command cannot be used on the following pins due to silicon restrictions:

08, 08M, 08M2 3 = fixed input
14M, 14M2 C.3 = fixed input
18M2 C.4, C.5 = fixed input
20M, 20M2, 20X2 C.6 = fixed input
Applies To:
All (except 08, 18, 28, 28A)
See Also:
Related Create:

Read a serial number from a 1-wire device

This program reads the serial number of a 1-wire device when connected to input pin C.2

Code Example:
main:	let b6 = 0 ; reset family code to 0

	; loop here reading numbers until the
	; family code (b6) is no longer 0

loop1:	readowsn C.2		; read serial number on input2
	if b6 = 0 then loop1

	; Do a simple safety check here.
	; b12 serial no value will not likely be FF
	; if this value is FF, it means that the device
	; was removed before a full read was completed
	; or a short circuit occurred

	if b12 = $FF then main

	; Everything is ok so continue

	debug			; ok so display
	pause 1000		; short delay
	goto main
Copy Code Submit an Example

Verifying a 1-wire device serial number

This program will read the serial number of a 1-wire device and check if the checksum returned in variable b13 is correct.

Code Example:
symbol ONE_WIRE_DEVICE = B.0

symbol val             = b0
symbol crc             = b1
symbol bitNumber       = b2


	sertxd( #b6,  " ", #b7,  " ", #b8,  " ", #b9,  " " )
	sertxd( #b10, " ", #b11, " ", #b12, " ", #b13, " " )

	crc = 0
	val = b6  : gosub CrcAdd
	val = b7  : gosub CrcAdd
	val = b8  : gosub CrcAdd
	val = b9  : gosub CrcAdd
	val = b10 : gosub CrcAdd
	val = b11 : gosub CrcAdd
	val = b12 : gosub CrcAdd

	if crc = b13 then
		sertxd( "Checksum Okay", cr, lf )
		sertxd( "Checksum Fail", cr, lf )


	for bitNumber = 0 to 7
		crc = crc ^ val & 1 * $118 ^ crc / 2
		val = val / 2
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.