Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the method of DIY small family weather station on Python development board

Shulou Source: shulou.com Published: 2022-06-01 04:05:28 09月26日 Update

This article mainly introduces "what is the method of Python development board DIY small family weather station". In daily operation, I believe many people have doubts about the method of DIY small family weather station on Python development board. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the method of DIY small family weather station on Python development board". Next, please follow the editor to study!

BMP180 has always been a common air pressure sensor. BMP180 is a pressure sensor with high precision, small volume and ultra-low energy consumption, which can be used in mobile devices. It has excellent performance, the lowest accuracy can reach 0.03hPa, and the power consumption is only 3 μ A; BMP180 uses powerful 8-pin ceramic leadless chip carrier (LCC) ultra-thin package, which can be directly connected to a variety of microprocessors through the I2C bus.

BMP180 physical diagram

Hardware wiring diagram

TPYBoard v702

BMP180

3.3V

VIN

GND

GND

Y9

SCL

Y10

SDA

Effect display diagram

After the connection is completed, import the library of font.py,upcd8544.py and bmp180, and you can read the temperature, air pressure and altitude respectively by the following methods.

Import the required class library, edit main.py, and run ok directly. Here is the program source code of main.py.

# main.py-- put your code hereafter imports pybimport upcd8544from machine import SPI,Pinfrom ubinascii import hexlifyfrom ubinascii import * from bmp180 import BMP180bmp=BMP180 (2) SPI = pyb.SPI (1) # DIN= > X8 Mosi data flow CLK = > X6-SCK#DIN = > SPI (1). MOSI 'X8' data flow (Master out) Slave in) # CLK = > SPI (1). SCK 'X6' SPI clockRST = 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) lcd_5110.lcd_write_string (str (tem), 0 lcd_5110.lcd_write_string 1) lcd_5110.lcd_write_string ('lcd_5110.lcd_write_string (' Press:',0,2) lcd_5110.lcd_write_string (str (press), 0) lcd_5110.lcd_write_string ('Pa',65,3) lcd_5110.lcd_write_string (' Hight:') 0self 4) lcd_5110.lcd_write_string (str (altitude), 0je 5) lcd_5110.lcd_write_string ('Maurejia 65 page5) the source code of bmp180.py library import pybfrom pyb import I2CBMP180_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.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 aura 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

Tags: Methods homes meteorology weather stations development learning sensors can pass more air pressure source code help excellent practical powerful minimum and then pressure only in kind Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS Shulou Tech Info NVidia Apple