Skip to content

Instantly share code, notes, and snippets.

@foxel
Created April 26, 2017 15:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxel/a163231293d7cf6f24831b363a91dfe5 to your computer and use it in GitHub Desktop.
Save foxel/a163231293d7cf6f24831b363a91dfe5 to your computer and use it in GitHub Desktop.
Python example for SI7021 board from ControlEverything
#!/usr/bin/python
import sys
from time import sleep, strftime
from OmegaExpansion import onionI2C # requires fixes for https://github.com/OnionIoT/i2c-exp-driver/issues/13
while True:
i2c = onionI2C.OnionI2C()
i2c.write(0x40, [0xE5])
sleep(0.1)
h0, h1 = i2c.read(0x40, 2)
i2c.write(0x40, [0xE0])
sleep(0.1)
t0, t1 = i2c.read(0x40, 2)
hum = ((125.0 * (h0 * 256 + h1)) / 65536.0) - 6.0
temp = ((175.72 * (t0 * 256 + t1)) / 65536.0) - 46.85;
print '%s | RH: %0.1f %% | Temp %0.1f C' % (
strftime('%X'),
hum,
temp
)
sleep(5)
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment