As we all know, Iphone6/6plus built-in barometric pressure sensor, but we are still very unfamiliar with the barometric pressure sensor. As the literal meaning, barometric pressure sensor is used to measure the pressure, but the measurement of air pressure for ordinary mobile phone users have what role?
Altitude measurement
For those who like to climb the mountain, they are very concerned about their height. Altitude measurement methods, commonly used in 2 ways, one through the GPS Global Positioning system, the second is to measure the atmospheric pressure, and then calculate the altitude according to the air pressure value. Due to technical and other limitations, GPS calculates an altitude error of 10 meters or so, and sometimes not even a GPS satellite signal if it is in the woods or under a cliff. The air pressure can be selected in a wide range of ways, and can be cost-controlled relatively low. On the basis of the original GPS of the mobile phone to increase the function of air pressure sensor, can make three-dimensional positioning more accurate.
Recently found a fun Development Board--tpyboardv702, this board can locate, send text messages, telephone, and on-board temperature and humidity sensors, photosensitive sensors and buzzer, can DIY a lot of interesting things, below we can use this board and a pressure sensor to do a small weather station, To get a real picture:
TPYBoardv702
Positioning function I will not say more, if necessary, you can refer to
http://docs.tpyboard.com/zh/latest/tpyboard/tutorial/v702/latitude/.
So we use this board with the BMP180 barometric pressure sensor to make a small home weather station, to detect local temperature and local pressure and altitude, if you want to do something more fun, you can pick up other sensors or add a relay to control other equipment.
BMP180 is a common barometric pressure sensor, the BMP180 is a high-precision, small-volume, ultra-low energy consumption of the force sensor, can be applied in mobile devices, it has excellent performance, The accuracy can be up to 0.03hPa, and the power consumption is very low, only 3μa;bmp180 using a powerful 8-pin ceramic leadless chip carrier (LCC) ultra-thin package, can be directly connected to various microprocessors via the I²C bus.
BMP180 Physical Map
Hardware wiring Diagram
Effect Display diagram
After the connection is finished, the font.py,upcd8544.py and bmp180 libraries are imported, and the temperature, air pressure and altitude can be read separately by the following methods.
Source
of the foot.py,upcd8544.py Library
Http://www.tpyboard.com/support/studyexample14/206.html
Import the required class library, edit good main.py, directly run on OK, the following is the main.py program source code
# main.py--Put your code here!import pybimport upcd8544from Machine import spi,pinfrom ubinascii import Hexlifyfrom Ubin ASCII import *from bmp180 import bmp180bmp=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 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,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 Library Source Import pybfrom PYB Import i2cbmp180_i2c_addr = Const (0X77) class BMP180 (): Def __init__ (sel F, I2c_num): SELF.I2C = I²c (I2c_num, I²c. 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.G Etreg (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* (p/101325) * * (1/5.255)) def get (self): t = [] T.append (Self.getpress ()) T.append (Self.getaltitude ()) t . Append (Self.gettemp ()) return T
Micropython Tutorial Tpyboard Development Board DIY small Home weather station