-
Notifications
You must be signed in to change notification settings - Fork 19
Description
I'm new to coding but kinda fell in love.
So I have a python script that posts a var to IO.adafruit.com. I have it working with a DHT11.
I'm trying to transition to an i2c sensor like the sht21 or sht31. But because the sht#1 code is long, I'm trying to make a module of it that I can import into my main code or to any other.
So I copied the sht31.py and sht21.py into /usr/lib/python2.7/ and /usr/lib/python3.4. I should be able to import the module into my code.
In the interpreter, I am able to import the sht31 or sht21, but when I try to build a test script I'm given errors about how the the "SHT31" var in not defined. (See below)
root@RPiZero1:/downloads# python test1.py
Traceback (most recent call last):
File "test1.py", line 7, in
with SHT31(1) as sht31:
NameError: name 'SHT31' is not defined
<
here is the code that I'm running in test1.py
import fcntl
import struct
import time
import sht31
while True:
with SHT31(1) as sht31:
print sht31.check_heater_status()
sht31.turn_heater_on()
print sht31.check_heater_status()
sht31.turn_heater_off()
print sht31.check_heater_status()
temperature, humidity = sht31.get_temp_and_humidity()
print "Temperature: %s" % temperature
print "Humidity: %s" % humidity
I know the import fcntl, struct, time is not necessary since those are import within the module, but for good measure, I did any what.
Any ideas on how to turn sht#1 into a module correctly.
Thanks