欢迎来到 黑吧安全网 聚焦网络安全前沿资讯,精华内容,交流技术心得!

MicroPython开发实例之自制小型家庭气象站

来源:本站整理 作者:佚名 时间:2018-06-30 TAG: 我要投稿
        self.MD = self.short(self.get2Reg(0xBE))
        self.UT = 0
        self.UP = 0
        self.B3 = 0
        self.B4 = 0
        self.B5 = 0
        self.B6 = 0
        self.B7 = 0
        self.X1 = 0
        self.X2 = 0
        self.X3 = 0
    def short(self, dat):
        if dat > 32767:
            return dat - 65536
        else:
            return dat
    def setReg(self, dat, reg):
        buf = bytearray(2)
        buf[0] = reg
        buf[1] = dat
        self.i2c.send(buf, BMP180_I2C_ADDR)
    def getReg(self, reg):
        buf = bytearray(1)
        buf[0] = reg
        self.i2c.send(buf, BMP180_I2C_ADDR)
        t = self.i2c.recv(1, BMP180_I2C_ADDR)
        return t[0]
    def get2Reg(self, reg):
        a = self.getReg(reg)
        b = self.getReg(reg + 1)
        return a*256 + b
    def measure(self):
        self.setReg(0x2E, 0xF4)
        pyb.delay(5)
        self.UT = self.get2Reg(0xF6)
        self.setReg(0x34, 0xF4)
        pyb.delay(5)
        self.UP = self.get2Reg(0xF6)
    def getTemp(self):
        self.measure()
        self.X1 = (self.UT - self.AC6) * self.AC5/(115)
        self.X2 = self.MC * (111) / (self.X1 + self.MD)
        self.B5 = self.X1 + self.X2
        return (self.B5 + 8)/160
    def getPress(self):
        self.getTemp()
        self.B6 = self.B5 - 4000
        self.X1 = (self.B2 * (self.B6*self.B6/(112))) / (111)
        self.X2 = (self.AC2 * self.B6)/(111)
        self.X3 = self.X1 + self.X2
        self.B3 = ((self.AC1*4+self.X3) + 2)/4
        self.X1 = self.AC3 * self.B6 / (113)
        self.X2 = (self.B1 * (self.B6*self.B6/(112))) / (116)
        self.X3 = (self.X1 + self.X2 + 2)/4
        self.B4 = self.AC4 * (self.X3 + 32768)/(115)
        self.B7 = (self.UP-self.B3) * 50000
        if self.B7 0x80000000:
            p = (self.B7*2)/self.B4
        else:
            p = (self.B7/self.B4) * 2
        self.X1 = (p/(18))*(p/(18))
        self.X1 = (self.X1 * 3038)/(116)
        self.X2 = (-7357*p)/(116)
        p = p + (self.X1 + self.X2 + 3791)/16
        return p
    def getAltitude(self):
        p = self.getPress()
        return (44330*(1-(p/101325)**(1/5.255)))
    def get(self):
        t = []
        t.append(self.getPress())
        t.append(self.getAltitude())
        t.append(self.getTemp())
        return t
 

上一页  [1] [2] 

【声明】:黑吧安全网(http://www.myhack58.com)登载此文出于传递更多信息之目的,并不代表本站赞同其观点和对其真实性负责,仅适于网络安全技术爱好者学习研究使用,学习中请遵循国家相关法律法规。如有问题请联系我们,联系邮箱admin@myhack58.com,我们会在最短的时间内进行处理。
  • 最新更新
    • 相关阅读
      • 本类热门
        • 最近下载