from micropython import const
from machine import I2C
(相关资料图)
BMP280_I2C_ADDR = const(0x76)
class BMP280():
def __init__(self, i2c):
= i2c
= bytearray(1)
= bytearray(1)
_T1 = (0x88)
_T2 = ((0x8A))
_T3 = ((0x8C))
_P1 = (0x8E)
_P2 = ((0x90))
_P3 = ((0x92))
_P4 = ((0x94))
_P5 = ((0x96))
_P6 = ((0x98))
_P7 = ((0x9A))
_P8 = ((0x9C))
_P9 = ((0x9E))
= 3
_p = 3
_t = 1
(0xF4, 0x2F)
(0xF5, 0x0C)
= 3
= 0
= 0
= ''
defshort(self,dat):
if dat > 32767:
return dat - 65536
else:
return dat
# set reg
defsetReg(self, reg, dat):
[0] = dat
_mem(BMP280_I2C_ADDR, reg, )
# get reg
defgetReg(self, reg):
_mem_into(BMP280_I2C_ADDR, reg, )
return [0]
# get two reg
defget2Reg(self, reg):
return (reg) + (reg+1) * 256
def get(self):
adc_T = ((0xFA)<<12) + ((0xFB)<<4) + ((0xFC)>>4)
var1 = (((adc_T>>3)-(_T1<<1))*_T2)>>11
var2 = (((((adc_T>>4)-_T1)*((adc_T>>4) - _T1))>>12)*_T3)>>14
t = var1+var2
= ((t * 5 + 128) >> 8)/100
var1 = (t>>1) - 64000
var2 = (((var1>>2) * (var1>>2)) >> 11 ) * _P6
var2 = var2 + ((var1*_P5)<<1)
var2 = (var2>>2)+(_P4<<16)
var1 = (((_P3*((var1>>2)*(var1>>2))>>13)>>3) + (((_P2) * var1)>>1))>>18
var1 = ((32768+var1)*_P1)>>15
if var1 == 0:
return # avoid exception caused by division by zero
adc_P = ((0xF7)<<12) + ((0xF8)<<4) + ((0xF9)>>4)
p=((1048576-adc_P)-(var2>>12))*3125
if p < 0x80000000:
p = (p << 1) // var1
else:
p = (p // var1) * 2
var1 = (_P9 * (((p>>3)*(p>>3))>>13))>>12
var2 = (((p>>2)) * _P8)>>13
= p + ((var1 + var2 + _P7) >> 4)
return [, ]
# get Temperature in Celsius
def getTemp(self):
()
return
# get Pressure in Pa
def getPress(self):
()
return
# Calculating absolute altitude
defgetAltitude(self):
return 44330*(1-(()/101325)**(1/))
# sleep mode
def poweroff(self):
(0xF4, 0)
# normal mode
def poweron(self):
(0xF4, 0x2F)
===================================================================<<<<<<<
import time
from machine import Pin,I2C
import _thread
import bmp280
def run():
i2c = I2C(sda=Pin(6), scl=Pin(7))
b = (i2c)
da = 0
t=0
try:
while(1):
da=da+1
f = open("date"+str(da)+".txt",'r')
()
except:
f = open("date"+str(da)+".txt",'a')
('气压计数据记录\n')
("记录时间: 原始温度和气压: 高度:\n")
()
while(True):
_ms(100)
f = open("date"+str(da)+".txt",'a')
t=t+1
y = ()
p = ()
h = (101325-p)*9/100
dat = (str(t/10)+" "+str(y)+" "+str(h)+"\n")
(dat)
#print(h)
()
pboot = Pin(9,)
def bled():
led4 = Pin(12,)
led5 = Pin(13,)
while(True):
()
_ms(500)
()
()
_ms(500)
()
#__new_thread(bled,())
while(1):
_ms(100)
if(()==0):
__new_thread(bled,())
run()
break
关于接线图
SDA=IO06 SCL=IO07 VCC= GND=GND
========== ========== ========== ==========
电池 正极=+5v 负极=GND
========== ========== ========== ==========
最后模块接到usb的5伏电源或者
把正5伏和gnd接到一块满电1s电池上
切记其他电池(2s-6s)只能插平衡头来获取1s电压
否则直接看烟花
标签:
Copyright © 2015-2023 港澳财富网版权所有 备案号:京ICP备2023022245号-31 联系邮箱:435 226 40 @qq.com