当前位置: 首页>>代码示例>>Python>>正文


Python SenseHat.get_temperature_from_humidity方法代码示例

本文整理汇总了Python中sense_hat.SenseHat.get_temperature_from_humidity方法的典型用法代码示例。如果您正苦于以下问题:Python SenseHat.get_temperature_from_humidity方法的具体用法?Python SenseHat.get_temperature_from_humidity怎么用?Python SenseHat.get_temperature_from_humidity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sense_hat.SenseHat的用法示例。


在下文中一共展示了SenseHat.get_temperature_from_humidity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sense_data

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
def sense_data():
    sense = SenseHat()
    comx, comy, comz = sense.get_compass_raw().values()
    accx, accy, accz = sense.get_accelerometer_raw().values()
    gyrox, gyroy, gyroz = sense.get_accelerometer_raw().values()
    temperature = sense.get_temperature_from_humidity()
    humidity = sense.get_humidity()
    pressure = sense.get_pressure()

    timestamp = datetime.now().isoformat()

    if accy > 0.1 :
        drop_flg = 1
    else:
        drop_flg = 0
            

    message = { "deviceid": deviceid, \
                "timestamp" : timestamp, \
                "temperature" : temperature, \
                "humidity" : humidity, \
                "pressure" : pressure, \
                "comx" : comx, \
                "comy" : comy, \
                "comz" : comz, \
                "gyrox" : gyrox, \
                "gyroy" : gyroy, \
                "gyroz" : gyroz, \
                "accx" : accx, \
                "accy" : accy, \
                "accz" : accz, \
                "drop" : drop_flg
                 }
    print accx, accy, accz, drop_flg
    return message
开发者ID:aquaviter,项目名称:sko2015-hackathon,代码行数:37,代码来源:sensor.py

示例2: readSensor

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
	def readSensor(self):
		from sense_hat import SenseHat
		senseHat = SenseHat()
		self.humidity   = senseHat.get_humidity()
		self.tempH      = senseHat.get_temperature_from_humidity()
		self.pressure   = senseHat.get_pressure() + PRESSURE_OFFSET
		self.tempP      = senseHat.get_temperature_from_pressure()
		self.mesureTime = time.time()
开发者ID:vrampal,项目名称:RpiWeather,代码行数:10,代码来源:SenseHat.py

示例3: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
class Sensor :
    def __init__(self) :
        self.sensor_id = "sensor hat"
        self.fileplace = 'tempplace.conf'
        self.total_count = 0
        self.device_file = "/dev/null"
        self.sense = SenseHat()
        self.place = self.readplacename()

    def reinit(self) :
        self.__init__()

    def sensorid(self) :
        return self.sensor_id

    def total_count(self) :
        return self.total_count

    def placename(self):
        return self.place

    def setplacename(self, name):
        self.place = setplace_db(name)

    def readplacename(self):
        self.place = getplace_db()
        return self.place

    def read_temp(self):
        temp = "null"
        tt = self.sense.get_temperature()
        th = self.sense.get_temperature_from_humidity()
        tf = self.sense.get_temperature_from_pressure()

        tf = float(tt)
        tf = tf - 10.0 # Fattore di correzione
        tt = round(tt, 2)
        tc = round(tf, 2)
        th = round(th, 2)
        tf = round(tf, 2)

        self.total_count += 1
        return str(tc)

    def read_pressure(self):
        p = self.sense.get_pressure()
        p = round(p, 2)
        self.total_count += 1
        return str(p)

    def read_humidity(self):
        h = self.sense.get_humidity()
        h = round(h, 2)
        self.total_count += 1
        return str(h)

    def sensordebug(self):
        return 'Sense Hat'
开发者ID:ernitron,项目名称:temperature-server,代码行数:60,代码来源:SensorHat.py

示例4: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
class SenseLogger:
    def __init__(self):
        self.sense = SenseHat()
        self.filename = "./logs/Senselogg-"+str(datetime.now())+".csv"
        self.file_setup(self.filename)

    def write_line(self, line):
        with open(self.filename, "a") as f:
            f.write(line + "\n")
        
    def log_data(self):
        sense_data = self.get_sense_data()
        line = ",".join(str(value) for value in sense_data)
        self.write_line(line)

    def file_setup(self, filename):
        header = ["datetime", "temp_h", "temp_p", "humidity", "pressure", "pitch",
                  "roll", "yaw", "mag_x", "mag_y", "mag_z",
                  "accel_x", "accel_y", "accel_z",
                  "gyro_x", "gyro_y", "gyro_z"]

        with open(filename, "w") as f:
            f.write(",".join(str(value) for value in header)+ "\n")

    def get_sense_data(self):
        sense_data = []
        sense_data.append(datetime.now())
        sense_data.append(self.sense.get_temperature_from_humidity())
        sense_data.append(self.sense.get_temperature_from_pressure())
        sense_data.append(self.sense.get_humidity())
        sense_data.append(self.sense.get_pressure())

        o = self.sense.get_orientation()
        yaw = o["yaw"]
        pitch = o["pitch"]
        roll = o["roll"]
        sense_data.extend([pitch, roll, yaw])

        mag = self.sense.get_compass_raw()
        x = mag["x"]
        y = mag["y"]
        z = mag["z"]
        sense_data.extend([x, y, z])    

        acc = self.sense.get_accelerometer_raw()
        x = acc["x"]
        y = acc["y"]
        z = acc["z"]
        sense_data.extend([x, y, z])  

        gyro = self.sense.get_gyroscope_raw()
        x = gyro["x"]
        y = gyro["y"]
        z = gyro["z"]
        sense_data.extend([x, y, z])

        return sense_data
开发者ID:PaulSolheim,项目名称:Robotkurs,代码行数:59,代码来源:senselogger.py

示例5: Hat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
class Hat(object):
    ''' `sensed` sensor module for the Raspberry Pi Sense HAT. This
        module returns a dictionary of all built in sensors. '''

    def __init__(self, config: DotMap) -> None:
        if config.sensed.test is not True:
            from sense_hat import SenseHat
            self.sense = SenseHat()

    def get_data(self) -> dict:
        # Environmental sensors
        humid = self.sense.humidity
        temp = self.sense.temperature
        temp_h = self.sense.get_temperature_from_humidity()
        temp_p = self.sense.get_temperature_from_pressure()
        press = self.sense.pressure

        # IMU (inertial measurement unit) sensors
        orient_r = self.sense.orientation_radians
        orient_d = self.sense.orientation
        compass = self.sense.compass
        compass_r = self.sense.compass_raw
        gyro = self.sense.gyroscope
        gyro_r = self.sense.gyroscope_raw
        accel = self.sense.accelerometer
        accel_r = self.sense.accelerometer_raw

        return {'environment': {'humidity': humid,
                                'temperature': temp,
                                'temperature_h': temp_h,
                                'temperature_p': temp_p,
                                'pressure': press},
                'imu': {'orientation_rad': orient_r,
                        'orientation_deg': orient_d,
                        'compass': compass,
                        'compass_r': compass_r,
                        'gyroscope': gyro,
                        'gyroscope_r': gyro_r,
                        'accelerometer': accel,
                        'accelerometer_raw': accel_r}}

    def test(self) -> dict:
        return {'environment': {'humidity': 1,
                                'temperature': 2,
                                'temperature_h': 3,
                                'temperature_p': 4,
                                'pressure': 5},
                'imu': {'orientation_rad': 6,
                        'orientation_deg': 7,
                        'compass': 8,
                        'compass_r': 9,
                        'gyroscope': 10,
                        'gyroscope_r': 11,
                        'accelerometer': 12,
                        'accelerometer_raw': 13}}
开发者ID:sli,项目名称:sensed,代码行数:57,代码来源:hat.py

示例6: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
class _SenseHat:
    def __init__(self, board_object, colour=""):
        self.board = board_object
        self.colour = colour
        self.sense = SenseHat()

    def magnetometer_on(self):
        self.sense.set_imu_config(True, False, False)  # gyroscope only

    @property
    def temp_c(self):
        return (self.sense.get_temperature_from_humidity() +
                self.sense.get_temperature_from_pressure())/2

    @property
    def pressure(self):
        return self.sense.pressure

    @property
    def humidity(self):
        return self.sense.humidity

    def led_all(self, colour):
        lcd = []
        for i in range(0, 64):
            lcd.append(colour)
        self.sense.set_pixels(lcd)

    def led_1(self, colour):
        self.sense.set_pixel(0, 0, colour)
        self.sense.set_pixel(0, 1, colour)
        self.sense.set_pixel(1, 0, colour)
        self.sense.set_pixel(1, 1, colour)

    def led_2(self, colour):
        self.sense.set_pixel(2, 2, colour)
        self.sense.set_pixel(2, 3, colour)
        self.sense.set_pixel(3, 2, colour)
        self.sense.set_pixel(3, 3, colour)

    def led_3(self, colour):
        self.sense.set_pixel(4, 4, colour)
        self.sense.set_pixel(4, 5, colour)
        self.sense.set_pixel(5, 4, colour)
        self.sense.set_pixel(5, 5, colour)

    def led_4(self, colour):
        self.sense.set_pixel(6, 6, colour)
        self.sense.set_pixel(6, 7, colour)
        self.sense.set_pixel(7, 6, colour)
        self.sense.set_pixel(7, 7, colour)

    def clear(self):
        self.sense.clear()
开发者ID:LozMarshall,项目名称:home_auto_year_one,代码行数:56,代码来源:sensehat.py

示例7: update

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
 def update(self):
     """Get the latest data from Sense HAT."""
     from sense_hat import SenseHat
     sense = SenseHat()
     temp_from_h = sense.get_temperature_from_humidity()
     temp_from_p = sense.get_temperature_from_pressure()
     t_cpu = get_cpu_temp()
     t_total = (temp_from_h + temp_from_p) / 2
     t_correct = t_total - ((t_cpu - t_total) / 1.5)
     t_correct = get_average(t_correct)
     self.temperature = t_correct
     self.humidity = sense.get_humidity()
     self.pressure = sense.get_pressure()
开发者ID:Teagan42,项目名称:home-assistant,代码行数:15,代码来源:sensehat.py

示例8: move_left

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
#HUMIDITY 4
d=humidity = my_weather[0]['humidity']

#RAINFALL 5
e=rainfall = my_weather[0]['rainfall']

#AIRPRESSURE 6
a=air_pressure = my_weather[0]['air_pressure']

#GROUNDTEMP 1
c=ground_temp = my_weather[0]['ground_temp']

#AMBIENTTEMP 2
b=ambient_temp = my_weather[0]['ambient_temp']

f=((sense.get_temperature_from_humidity()+sense.get_temperature_from_pressure())/2)

i=0

def move_left (event):
    if event.action=='pressed':
        global i
        i = i-1
        print(i)
        print(event)

def move_right (event):
    if event.action=='pressed':
        global i
        i = i+1
        print(i)
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:33,代码来源:Final_State_tilting_pages.py

示例9: get_sense_data

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
while True:
    sense_data = get_sense_data()

    if DELAY == 0:
        log_data()

    if len(batch_data) >= WRITE_FREQUENCY:
        print("Writing to file..")
        with open(filename,"a") as f:
            for line in batch_data:
                f.write(line + "\n")
            batch_data = []

        # also write to plotly
        now = datetime.now()
        temp = round(sense.get_temperature_from_pressure(), 5)
        temp2 = round(sense.get_temperature_from_humidity(), 5)
        point1 = {
            'x' : str(now),
            'y' : temp
        }
        plotly_stream1.write(point1)

        point2 = {
            'x' : str(now),
            'y' : temp2
        }
        plotly_stream2.write(point2)

plotly_stream.close()
开发者ID:Batrig,项目名称:temp-test,代码行数:32,代码来源:temp_log.py

示例10: round

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
#* set the sampling parameters
#*
#*********************************************

rate = 60               #sample frecuency in seconds
samples = 900           #number of samples
stabilization = True    #Allow for termometer to stabilize
report = True               #send email at the end of the process?
smtpUser = "email user"  #email account
smtpPass = "email password"                       #email password
fromAdd = smtpUser
toAdd = "recipient"         #completion email recipient

#initialization read from the sensor. This is neccesary since sometimes the sensors return
#a 0 value for pressure on the first read
t = round(sense.get_temperature_from_humidity(),1)            
p = round(sense.get_pressure(),1)                              
h = round(sense.get_humidity(),1)
sense.show_letter("W")
time.sleep(5)
sense.clear()

#stabilize temperature readings by waiting 7 min
if stabilization:
    sense.show_letter("W")
    time.sleep(420)
    sense.clear()
    
#open the sampling file
sensefile = open("sensefile.dat", "w")
开发者ID:steincastillo,项目名称:envlogger,代码行数:32,代码来源:envlogger_a.py

示例11: getTempValue

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
 def getTempValue(self):
     sense = SenseHat()
     temp = sense.get_temperature_from_humidity()
     return str(temp)
开发者ID:OpenSpaceProgram,项目名称:pyOSP,代码行数:6,代码来源:SenseHumidTemp.py

示例12: while

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
question_mark = [
O, O, O, O, O, O, O, O,
O, X, X, O, O, X, X, O,
O, X, X, O, O, X, X, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, X, O, O, O, O, X, O,
O, O, X, X, X, X, O, O,
O, O, O, X, X, O, O, O
]


while (1 == 1) :
    print("%s Temperature" % sense.temp)
    print("%s Temp - humidity sensor" % sense.get_temperature_from_humidity())
    print("%s Temp - pressure sensor" % sense.get_temperature_from_pressure())
    print("%s Pressure: in Millibars" % sense.get_pressure())
    print("%s Humidity" % sense.get_humidity())

    north = sense.get_compass()
    print("%s Degrees to north" % north)

    raw = sense.get_accelerometer_raw()
    print("Acc intensity in Gs x: {x}, y: {y}, z: {z}".format(**raw))

    m = '%.1f' % sense.temp
    sense.show_message(m, text_colour=[255, 0, 0])
    print("*********")
    sense.set_pixels(question_mark)
    time.sleep(1)
开发者ID:Statoil,项目名称:happyeye,代码行数:32,代码来源:dumphatsensors.py

示例13: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
class Reading:
    def __init__(self):
        # initialize sense hat
        self.sense = SenseHat()
        self.sense.clear()
    
    def getReading(self):
        # get temperature from humidity
        t1 = self.sense.get_temperature_from_humidity()
        # get temperature from pressure
        t2 = self.sense.get_temperature_from_pressure()
        # get cpu temperature
        t_cpu = self.get_cpu_temp()
        # average temperature from humidity and pressure
        t = (t1+t2)/2
        # normalize temperature with cpu temperature
        t_corr = t - ((t_cpu-t)/1.5)
        # smooth the normalization by averaging
        t_corr = self.get_smooth(t_corr)

        # get humidity
        humidity = self.sense.get_humidity()
        # get pressure
        pressure = self.sense.get_pressure()

        # return data for pushing into iot
        return {
            "deviceid": self.getserial(),
            "humidity": humidity,
            "pressure": pressure,
            "temperature": t_corr,
            "timestamp": int(round(time.time() * 1000)),
        }

    # code supplied from http://yaab-arduino.blogspot.com/2016/08/accurate-temperature-reading-sensehat.html
    # get CPU temperature
    def get_cpu_temp(self):
        res = os.popen("vcgencmd measure_temp").readline()
        t = float(res.replace("temp=","").replace("'C\n",""))
        return(t)

    # code supplied from http://yaab-arduino.blogspot.com/2016/08/accurate-temperature-reading-sensehat.html
    # use moving average to smooth readings
    def get_smooth(self, x):
        smoothing = [x,x,x]
        smoothing[2] =smoothing[1]
        smoothing[1] = smoothing[0]
        smoothing[0] = x
        # average smoothing
        xs = (smoothing[0]+smoothing[1]+smoothing[2])/3
        return(xs)

    # code supplied from https://www.raspberrypi-spy.co.uk/2012/09/getting-your-raspberry-pi-serial-number-using-python/
    def getserial(self):
        # Extract serial from cpuinfo file
        cpuserial = "0000000000000000"
        try:
            f = open('/proc/cpuinfo','r')
            for line in f:
                if line[0:6]=='Serial':
                    cpuserial = line[10:26]
            f.close()
        except:
            cpuserial = "ERROR000000000"
        
        return cpuserial
开发者ID:kkesley,项目名称:rpi-env-report-aws-iot,代码行数:68,代码来源:reading.py

示例14: PiSenseHat

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
class PiSenseHat(object):
    """Raspberry Pi 'IoT Sense Hat API Driver Class'."""

    # Constructor
    def __init__(self):
        self.sense = SenseHat()
        # enable all IMU functions
        self.sense.set_imu_config(True, True, True)

    # pixel display
    def set_pixel(self,x,y,color):
    # red = (255, 0, 0)
    # green = (0, 255, 0)
    # blue = (0, 0, 255)
        self.sense.set_pixel(x, y, color)

    # clear pixel display
    def clear_display(self):
        self.sense.clear()
        
    # Pressure
    def getPressure(self):
        return self.sense.get_pressure()

    # Temperature
    def getTemperature(self):
        return self.sense.get_temperature()

    # Humidity
    def getHumidity(self):
        return self.sense.get_humidity()

    def getHumidityTemperature(self):
        return self.sense.get_temperature_from_humidity()

    def getPressureTemperature(self):
        return self.sense.get_temperature_from_pressure()

    def getOrientationRadians(self):
        return self.sense.get_orientation_radians()

    def getOrientationDegrees(self):
        return self.sense.get_orientation_degrees()

    # degrees from North
    def getCompass(self):
        return self.sense.get_compass()

    def getAccelerometer(self):
        return self.sense.get_accelerometer_raw()

    def getEnvironmental(self):
        sensors = {'name' : 'sense-hat', 'environmental':{}}
        return sensors

    def getJoystick(self):
        sensors = {'name' : 'sense-hat', 'joystick':{}}
        return sensors

    def getInertial(self):
        sensors = {'name' : 'sense-hat', 'inertial':{}}

    def getAllSensors(self):
        sensors = {'name' : 'sense-hat', 'environmental':{}, 'inertial':{}, 'joystick':{}}
        sensors['environmental']['pressure'] = { 'value':self.sense.get_pressure(), 'unit':'mbar'}
        sensors['environmental']['temperature'] = { 'value':self.sense.get_temperature(), 'unit':'C'}
        sensors['environmental']['humidity'] = { 'value':self.sense.get_humidity(), 'unit': '%RH'}
        accel = self.sense.get_accelerometer_raw()
        sensors['inertial']['accelerometer'] = { 'x':accel['x'], 'y':accel['y'], 'z': accel['z'], 'unit':'g'}
        orientation = self.sense.get_orientation_degrees()
        sensors['inertial']['orientation'] = { 'compass':self.sense.get_compass(), 'pitch':orientation['pitch'], 'roll':orientation['roll'], 'yaw': orientation['yaw'], 'unit':'degrees'}
        return sensors
开发者ID:santhoshmeda,项目名称:iot-310,代码行数:74,代码来源:sense.py

示例15: sleep

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import get_temperature_from_humidity [as 别名]
mqttc.tls_set(caPath, certfile=certPath, keyfile=keyPath, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
mqttc.connect(awshost, awsport, keepalive=60)

mqttc.loop_start()

while True:

    message = {}

    device = {}
    device['cpuTemperature'] = os.popen('vcgencmd measure_temp').readline().replace("temp=","").replace("'C\n","")

    environment = {}

    temp = {}
    temp['basedOnHumidity'] = sense.get_temperature_from_humidity()
    temp['basedOnPressure'] = sense.get_temperature_from_pressure()
  
    environment['humidity'] = sense.get_humidity()
    environment['pressure'] = sense.get_pressure()
    environment['temperature'] = temp

    message['device'] = device
    message['environment'] = environment

    jsonData = json.dumps(message)

    if connflag == True:
        mqttc.publish("environmentData", jsonData, qos=1)
        print jsonData
        sleep(10)
开发者ID:joshdurbin,项目名称:aws-iot-rpi-sense-hat,代码行数:33,代码来源:awsiotpub.py


注:本文中的sense_hat.SenseHat.get_temperature_from_humidity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。