def mlx9061_init(): global mlx90614Dev i2cObj1 = I2C() i2cObj1.open("mlx90614") print("mlx90614 inited!") mlx90614Dev = mlx90614.MLX90614(i2cObj1)
def oled_init(): global oled i2cObj = I2C() i2cObj.open("ssd1306") print("ssd1306 inited!") oled = SSD1306_I2C(128, 64, i2cObj) oled.fill(0) #清屏背景黑色 oled.text('2022-01-03', 30, 5) oled.text('12:00:00', 30, 22) oled.text(str('----------------------'), 3, 32) oled.text('connecting', 30, 40) oled.show()
if __name__ == "__main__": ''' The below i2c configuration is needed in your board.json. "mpu6050": { "type": "I2C", "port": 1, "addrWidth": 7, "freq": 100000, "mode": "master", "devAddr": 105 } ''' print("Testing mpu6050 ...") i2cDev = I2C() i2cDev.open("mpu6050") mpu6050Dev = MPU6050(i2cDev) t = mpu6050Dev.getTemperature() print("The temperature is:", t) acc = mpu6050Dev.getAcceleration() print("The Acceleration data is:", acc) gyro = mpu6050Dev.getGyro() print("The Gyro data is: ", gyro) data = mpu6050Dev.getData()
from driver import I2C print("-------------------i2c test--------------------") i2c = I2C() i2c.open("pca9544") regval = bytearray(1) regval[0] = 0x5 print(regval) ret = i2c.write(regval) print(ret) i2c.close() print("-------------------i2c test--------------------")
# 生成上报到物联网平台的属性值字串 prop = ujson.dumps({ 'CurrentTemperature': data[0], 'CurrentHumidity': data[1] }) print('uploading data: ', prop) upload_data = {'params': prop} # 上传温度和湿度信息到物联网平台 device.postProps(upload_data) utime.sleep(2) if __name__ == '__main__': # 硬件初始化 i2cObj = I2C() i2cObj.open( "sht3x" ) # 按照board.json中名为"sht3x"的设备节点的配置参数(主设备I2C端口号,从设备地址,总线频率等)初始化I2C类型设备对象 print("sht3x inited!") humitureDev = sht3x.SHT3X(i2cObj) # 初始化SHT3X-DIS传感器 # 初始化 GPIO airconditioner = GPIO() humidifier = GPIO() humidifier.open('led_g') # 加湿器使用board.json中led_g节点定义的GPIO,对应esp32外接的的绿灯 airconditioner.open( 'led_b') # 空调使用board.json中led_b节点定义的GPIO,对应esp32外接的上的蓝灯
def open(self, devid): self.i2cDev = I2C() self.i2cDev.open(devid)