Python开发板DIY小型家庭气象站的方法是什么
这篇文章主要介绍“Python开发板DIY小型家庭气象站的方法是什么”,在日常操作中,相信很多人在Python开发板DIY小型家庭气象站的方法是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Python开发板DIY小型家庭气象站的方法是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
在长兴等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、成都做网站 网站设计制作按需定制制作,公司网站建设,企业网站建设,品牌网站设计,营销型网站,外贸网站建设,长兴网站建设费用合理。
BMP180是一直常见的气压传感器,BMP180是一款高精度、小体积、超低能耗的压力传感器,可以应用在移动设备中,它的性能卓越,精度最低可以达到0.03hPa,并且耗电极低,只有3μA;BMP180采用强大的8-pin陶瓷无引线芯片承载(LCC)超薄封装,可以通过I2C总线直接与各种微处理器相连。
BMP180实物图
硬件接线图
TPYBoard v702 | BMP180 |
3.3V | VIN |
GND | GND |
Y9 | SCL |
Y10 | SDA |
效果展示图
连接完毕后,将font.py,upcd8544.py与bmp180的库导入,就可以通过以下方法分别读取温度、气压、海拔高度了。
导入需要的类库,编辑好main.py,直接运行就ok了,下面是main.py的程序源码
# main.py -- put your code here! import pyb import upcd8544 from machine import SPI,Pin from ubinascii import hexlify from ubinascii import * from bmp180 import BMP180 bmp=BMP180(2) SPI = pyb.SPI(1) #DIN=>X8-MOSI/CLK=>X6-SCK #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in) #CLK =>SPI(1).SCK 'X6' SPI clock RST = pyb.Pin('X20') CE = pyb.Pin('X19') DC = pyb.Pin('X18') LIGHT = pyb.Pin('X17') lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT) while True: tem=bmp.getTemp() press=bmp.getPress() altitude=bmp.getAltitude() lcd_5110.lcd_write_string('Tem:',0,0) lcd_5110.lcd_write_string(str(tem),0,1) lcd_5110.lcd_write_string('C',65,1) lcd_5110.lcd_write_string('Press:',0,2) lcd_5110.lcd_write_string(str(press),0,3) lcd_5110.lcd_write_string('Pa',65,3) lcd_5110.lcd_write_string('Hight:',0,4) lcd_5110.lcd_write_string(str(altitude),0,5) lcd_5110.lcd_write_string('M',65,5) bmp180.py库的源码 import pyb from pyb import I2C BMP180_I2C_ADDR = const(0x77) class BMP180(): def __init__(self, i2c_num): self.i2c = I2C(i2c_num, I2C.MASTER, baudrate = 100000) self.AC1 = self.short(self.get2Reg(0xAA)) self.AC2 = self.short(self.get2Reg(0xAC)) self.AC3 = self.short(self.get2Reg(0xAE)) self.AC4 = self.get2Reg(0xB0) self.AC5 = self.get2Reg(0xB2) self.AC6 = self.get2Reg(0xB4) self.B1 = self.short(self.get2Reg(0xB6)) self.B2 = self.short(self.get2Reg(0xB8)) self.MB = self.short(self.get2Reg(0xBA)) self.MC = self.short(self.get2Reg(0xBC)) 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/(1<<15) self.X2 = self.MC * (1<<11) / (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/(1<<12))) / (1<<11) self.X2 = (self.AC2 * self.B6)/(1<<11) self.X3 = self.X1 + self.X2 self.B3 = ((self.AC1*4+self.X3) + 2)/4 self.X1 = self.AC3 * self.B6 / (1<<13) self.X2 = (self.B1 * (self.B6*self.B6/(1<<12))) / (1<<16) self.X3 = (self.X1 + self.X2 + 2)/4 self.B4 = self.AC4 * (self.X3 + 32768)/(1<<15) 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/(1<<8))*(p/(1<<8)) self.X1 = (self.X1 * 3038)/(1<<16) self.X2 = (-7357*p)/(1<<16) 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
到此,关于“Python开发板DIY小型家庭气象站的方法是什么”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
网页名称:Python开发板DIY小型家庭气象站的方法是什么
链接URL:http://ybzwz.com/article/jgdpsc.html