Reading a specific sensor using his ID
This time we read the temperature based on the device's ID, supposing we have multiple devices on our 1wire bus. To find out the ID of your device, see this page.
The code:
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 on a single device using the -- drive's ID (see thermometer.jal) where you have multiple -- devices 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 enable_digital_io() 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 -- put the ID device on the buffer array -- Note: this ID is for my sensor, use thermometer.jal to see your ID rom_ID[0] = 0x28 rom_ID[1] = 0x98 rom_ID[2] = 0x85 rom_ID[3] = 0x8B rom_ID[4] = 0x02 rom_ID[5] = 0x00 rom_ID[6] = 0x00 rom_ID[7] = 0x15 -- print_string(lcd, str1) var bit sign var byte units, decimals var byte i forever loop -- loop forever convert_18B20 temp_18B20_CRC(units, decimals, sign) lcd_cursor_position(0,7) if sign == 1 then lcd = "-" end if print_byte_dec(lcd, units) lcd = "." print_byte_dec(lcd, decimals) lcd = "C" end loop --