Created
August 3, 2014 15:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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