Skip to content

Instantly share code, notes, and snippets.

@analog-io
Created April 10, 2015 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save analog-io/742cfb4a6c2d3499e172 to your computer and use it in GitHub Desktop.
Save analog-io/742cfb4a6c2d3499e172 to your computer and use it in GitHub Desktop.
Fixed point Si7020 Math
local rh = read_reg(0x40,0xE5,true)
local t = read_reg(0x40,0xE0,false)
rh = string.byte(rh,1)*256+string.byte(rh,2)
t = string.byte(t,1)*256+string.byte(t,2)
t=(17572*t)/65536-4685
t=tostring(t*18+32000)
rh=tostring(rh*12500/65536-600)
t=t:sub(1,t:len()-3).."."..t:sub(t:len()-2,t:len())
rh=rh:sub(1,rh:len()-2).."."..rh:sub(rh:len()-1,rh:len())
print(t.." : "..rh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment