MicroPython
简单、方便、快速开发嵌入式实时系统——MicroPytho
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| from pyb import uart
from pyb import I2C
GlobalTemp = 0.0
GlobalBarometer = 0.0
#初始化和实例化I2C外设2
I2C2 = I2C(2,I2C.MASTER,波特率= 100000)
#配置Uart1进行通信
Uart1 = pyb.UART(1,115200)
Uart1.init(115200,bits = 8,parity = None,stop = 1)
while True:
SampleSensor()
pyb.delay(1000)
def SensorSample():
#读取温度数据
TempSample = I2C2.readfrom_mem(119,0xFA,3)
#读取压力数据
PressureSample = I2C2.readfrom_mem(119,0xF7,3)
将样本数据转换为字符串
data =“#,temperature =”str(TempSample)+“,pressure”+ str(PressureSample)+“,#,\ n \ r”
#将数据写入蓝牙
Uart1.write(data)
|