ADT7410 I2C temp sensor works only after a power cycle

DIY Projects and Methodologies, Hobby Circuits, Circuit Samples
Post Reply
Message
Author
kimi
Posts: 12
Joined: 11 Aug 2016, 14:56

ADT7410 I2C temp sensor works only after a power cycle

#1 Post by kimi » 27 Oct 2016, 22:00

I have an ADT7410 temperature sensor connected to an ESP8266 running nodemcu.
The issue I am having is that I can only get good changing data after power cycling the ADT7410. Until that I get either an reasonable fixed temp reading which doesn't change even if I heat/cool down the sensor or 0x0000 (a disconnected sensor results in 0xFFFF). I tried resetting the IC over I2C but it doesn't change anything.
The system consists of a mainboard/daughterboard. This schematic shows the connections between the boards. Unrelated things on the mainboard have been removed.
Image
How could I solve this so that the device starts working after I plug in power without adding a fet to power cycle the daughter board?
NodeMCU lua code:

Code: Select all

---------------------
-- Wifi connection --
---------------------

function is_connected()
    print(wifi.sta.status())
    return wifi.sta.status() == 5
end

function block_connected()
    while not is_connected() do
        print("Waiting for connection")
        tmr.delay(1000000)
    end
    print("WIFI connected!")
end

------------------
-- I2C & Sensor --
------------------

I2C_ID = 0
I2C_PIN_SDA = 2
I2C_PIN_SCL = 1

I2C_ADDRESS = 0x48
I2C_TEMP_REG_MSB = 0x00
I2C_TEMP_REG_LSB = 0x01
I2C_STATUS_REG = 0x02
I2C_CONF_REG = 0x03

function adt_reset()
    i2c.start(I2C_ID)
    i2c.address(I2C_ID, 0x00, i2c.TRANSMITTER)
    i2c.write(I2C_ID, 0x06)    
    i2c.stop(I2C_ID)
end

function adt_setup()    
    i2c.start(I2C_ID)
    i2c.address(I2C_ID, I2C_ADDRESS, i2c.TRANSMITTER)
    i2c.write(I2C_ID, I2C_CONF_REG)
    i2c.write(I2C_ID, 127)
    i2c.stop(I2C_ID)
end

function read_reg(id, dev_addr, reg_addr)
  i2c.start(id)
  i2c.address(id, dev_addr ,i2c.TRANSMITTER)
  i2c.write(id,reg_addr)
  i2c.start(id)
  i2c.address(id, dev_addr,i2c.RECEIVER)
  c=i2c.read(id,1)
  i2c.stop(id)
  return string.byte(c)
end

function get_temp()
    msb = read_reg(I2C_ID, I2C_ADDRESS, I2C_TEMP_REG_MSB)
    print(msb)
    lsb = read_reg(I2C_ID, I2C_ADDRESS, I2C_TEMP_REG_LSB)
    print(lsb)

    val = bit.lshift(msb, 8) + lsb
    if bit.isset(msb, 7) then
        return (val - 65536)/128
    else
        return val/128
    end
end

---------------------
-- MQTT Connection --
---------------------

MQTT_HOST = "rabbitmq-sysd.containers.ikioma"
MQTT_PORT = 1883

MQTT_CLIENTID = "temp-" .. node.chipid()
MQTT_KEEPALIVE = 120
MQTT_USER = "guest"
MQTT_PASS = "guest"

MQTT_QOS = 1
MQTT_RETAIN = 0


mqtt_connected = false

m = mqtt.Client(MQTT_CLIENTID, MQTT_KEEPALIVE, MQTT_USER, MQTT_PASS)

function mqtt_connected()
    print("MQTT connected")
    mqtt_connected = true
    m:publish("/connections", MQTT_CLIENTID, MQTT_QOS, MQTT_RETAIN)
end

function mqtt_disconnected()
    print("MQTT disconnected")
    mqtt_connected = false
end

function mqtt_get_connected()
    return mqtt_connected
end

m:lwt("/lwt", MQTT_CLIENTID, MQTT_QOS, MQTT_RETAIN)
m:on("connect", function(con) print ("connected?") end)
m:on("offline", mqtt_disconnected)

mqtt_ip = ""

function mqtt_connect()
    m:connect(mqtt_ip, MQTT_PORT, 0, 0, mqtt_connected)
end

function mqtt_connect_with_ip(ip)
    mqtt_ip = ip
    mqtt_connect()
end

function main_loop()
    if mqtt_get_connected() then
        m:publish("/" .. MQTT_CLIENTID, get_temp(), MQTT_QOS, MQTT_RETAIN, function(conn) print("sent") end)
        if to_advertisement == 0 then
            m:publish("/devices", MQTT_CLIENTID, MQTT_QOS, MQTT_RETAIN)
            to_advertisement = ADVERTISE_INTERVAL
        else
            to_advertisement = to_advertisement - 1
        end
    else
        mqtt_connect()
    end
end

----------
-- MAIN --
----------

block_connected()
print(wifi.sta.getmac())
print(wifi.sta.getip())


i2c.setup(I2C_ID, I2C_PIN_SDA, I2C_PIN_SCL, i2c.SLOW)
adt_reset()
adt_setup()

sk = net.createConnection(net.TCP, 0)
sk:dns(MQTT_HOST, function(conn, ip) mqtt_connect_with_ip(ip) end)
sk = nil

ADVERTISE_INTERVAL = 10
to_advertisement = 0


-- run "loop" every 10s
tmr.alarm(0, 5000, 1, main_loop)
The datasheet of the ADT7410 temperature sensor can be seen at http://www.kynix.com/Parts/2540563/ADT7410TRZ-REEL.html

User avatar
KevinA
Posts: 639
Joined: 18 Dec 2015, 08:35

Re: ADT7410 I2C temp sensor works only after a power cycle

#2 Post by KevinA » 28 Oct 2016, 04:06

Is the part in shutdown?
SHUTDOWN
The ADT7410 can be placed in shutdown mode by writing 1
to Bit 5 and 1 to Bit 6 of the configuration register (Register
Address 0x03), in which case the entire IC is shut down and
no further conversions are initiated until the ADT7410 is
taken out of shutdown mode. The ADT7410 can be taken
out of shutdown mode by writing 0 to Bit 5 and 0 to Bit 6 in
the configuration register (Register Address 0x03). The
ADT7410 typically takes 1 ms (with a 0.1 μF decoupling
capacitor) to come out of shutdown mode. The conversion
result from the last conversion prior to shutdown can still be
read from the ADT7410 even when it is in shutdown mode.
When the part is taken out of shutdown mode, the internal
clock is started and a conversion is initiated.

I do not see where you're setting up the device with 0x2F.
RESET
To reset the ADT7410 without having to reset the entire I2
C bus,
an explicit reset command is provided. This uses a particular
address pointer word as a command word to reset the part and
upload all default settings. The ADT7410 does not respond to
the I2
C bus commands (do not acknowledge) during the default
values upload for approximately 200 μs.
The reset command address word is 0x2F.

Why a $4 part (or $7 for the ADT7420) What is the goal of this design?
Have you looked at VDD of the ADT7410 during power up?
Look at GPIO5/4 - are the lines active during boot before your code?
Generate firmware for the ESP with nothing but a test loop for the ADT.
Does the ADT get VDD from VR1?
What size part is C2 (0402?)
The 'Reset the Part and Upload all default settings' doesn't appear to be happening with the code you have listed.

Post Reply