Reading temperature and sensor ID

Is easy to have only one device on your 1wire bus - no identification problem and only two function used. It is also a good solution to read the device's ID - required when you use multiple devices on your 1wire bus. So, this is what we do now - reading temperature and the ID.

Click on image to zoom

The code:

The code is based mainly on two important libraries: 1_wire.jal and ds18b20.jal - see header inside for authors.

-- Read sensor temperature DS18B20 in Celsius degree.
-- It is about an unique device on 1wire bus
-- Copyright Vasile Guta Ciucur
-- New BSD License
include freejalduino4
include delay
alias d1w_bus_in   is D11
alias d1w_bus_out  is D11_direction
include 1_wire
-- LCD IO definition
alias lcd_rs           is D9            -- LCD command/data select.
alias lcd_en           is D8            -- LCD data trigger
alias lcd_rs_direction is D9_direction
alias lcd_en_direction is D8_direction
alias  lcd_d4        is  D3
alias  lcd_d5        is  D4
alias  lcd_d6        is  D5
alias  lcd_d7        is  D6
alias  lcd_d4_direction        is  D3_direction
alias  lcd_d5_direction        is  D4_direction
alias  lcd_d6_direction        is  D5_direction
alias  lcd_d7_direction        is  D6_direction
const byte LCD_ROWS     = 2             -- 2 lines
const byte LCD_CHARS    = 16            -- 16 chars per line
lcd_rs_direction = output
lcd_en_direction = output
lcd_d4_direction = output
lcd_d5_direction = output
lcd_d6_direction = output
lcd_d7_direction = output
-- LED IO definition - Uncomment the lines if you want tp use leds for debug
--alias led is D13
--alias led_direction is D13_direction
--alias led2 is D2
--alias led2_direction is D2_direction
--led_direction = output
--led2_direction = output
--led = low
--led2 = low
include lcd_hd44780_4                   -- LCD library with 4 data lines
include print                           -- formatted output library
include ds18b20
const byte str1[] = "Temp.= "
lcd_init()                              -- initialize LCD
print_string(lcd, str1)
var bit sign
var byte units, decimals
var byte i
forever loop                            -- loop forever
  s_temp_18B20_CRC(units, decimals, sign)
  if sign == 1 then
    lcd = "-"
  end if
  print_byte_dec(lcd, units)
  lcd = "."
  print_byte_dec(lcd, decimals)
  lcd = "C"
  -- read the device's ID and print it
  for 8 using i loop
    print_byte_hex(lcd, rom_ID[i])
  end loop
end loop