Skip to content

Instantly share code, notes, and snippets.

@wuub
Created August 3, 2014 15:10
Show Gist options
  • Save wuub/579bee663d121a10d552 to your computer and use it in GitHub Desktop.
Save wuub/579bee663d121a10d552 to your computer and use it in GitHub Desktop.
Micropython DS1624 temperature read in continous mode with maximum (0.0625°C) resolution
import pyb
ACCESS_CONFIG = 0xAC
READ_TEMPERATURE = 0xAA
START_CONVERT = 0xEE
STOP_CONVERT = 0x22
LSB_RESOLUTION = 2 ** (-4)
LSB_BITS = 4
i2c = pyb.I2C(1, pyb.I2C.MASTER)
ds1624_addr = i2c.scan()[0]
# OOTB DS1624 operates in continous mode (1SHOT==0)
# there is no need to START_CONVERT before every read
i2c.send(START_CONVERT, addr=ds1624_addr)
def read_temperature():
i2c.send(READ_TEMPERATURE, ds1624_addr)
msb, lsb = i2c.recv(2, ds1624_addr)
return int(msb) + (int(lsb) >> LSB_BITS) * LSB_RESOLUTION
while True:
pyb.delay(1000)
print(read_temperature())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment