ds3231 - ds3231 Real Time Clock Sensor#

Adaptation status unknown

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Example

--Note: due to the use of sys.wait() all apis need to be used in the coroutine
-- Usage Examples
local ds3231 = require "ds3231"
i2cid = 0
i2c_speed = i2c.FAST
sys.taskInit(function()
    i2c.setup(i2cid,i2c_speed)
    ds3231.init(i2cid)--initialization, passing in i2c_id
    while 1 do
        log.info("ds3231.get_temperature", ds3231.get_temperature())
        local time = ds3231.read_time()
        log.info("ds3231.read_time",time.tm_year,time.tm_mon,time.tm_mday,time.tm_hour,time.tm_min,time.tm_sec)
        sys.wait(5000)
        local set_time = {tm_year=2021,tm_mon=3,tm_mday=0,tm_wday=0,tm_hour=0,tm_min=0,tm_sec=0}
        ds3231.set_time(set_time)
        time = ds3231.read_time()
        log.info("ds3231_read_time",time.tm_year,time.tm_mon,time.tm_mday,time.tm_hour,time.tm_min,time.tm_sec)
        sys.wait(1000)
    end
end)

ds3231.init(i2c_id)#

ds3231 Initialization

Parameters

Incoming Value Type

Explanation

number

The i2c bus id

Return Value

return value type

explanation

bool

Successful return true

Examples

ds3231.init(0)

ds3231.get_temperature()#

Obtaining Temperature Data

Parameters

None

Return Value

return value type

explanation

number

Temperature data

Examples

log.info("ds3231.get_temperature", ds3231.get_temperature())

ds3231.read_time()#

Acquisition time

Parameters

None

Return Value

return value type

explanation

table

Schedule

Examples

local time = ds3231.read_time()
log.info("ds3231.read_time",time.tm_year,time.tm_mon,time.tm_mday,time.tm_hour,time.tm_min,time.tm_sec)

ds3231.set_time(time)#

Set time

Parameters

Incoming Value Type

Explanation

table

time Schedule

Return Value

None

Examples

local set_time = {tm_year=2021,tm_mon=3,tm_mday=0,tm_wday=0,tm_hour=0,tm_min=0,tm_sec=0}
ds3231.set_time(set_time)