树莓派论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 10|回复: 0
收起左侧

ESP32使用GY-39四合一气象站代码及接线图

[复制链接]
发表于 3 天前 | 显示全部楼层 |阅读模式
# Micropython version
#
# ESP Pin  --  GY39 Pin
# ---------------------
# S0       --  GND
# 3.3v     --  VCC
# GPIO_22  --  CT
# GPIO_21  --  DR
# GND      --  GND   

from machine import Pin, SoftI2C

MCU_I2C_ADDR = 0X5b

i2c = SoftI2C(scl=Pin(22), sda=Pin(21))

h_lux_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x00, 1), 'big', False)
h_lux_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x01, 1), 'big', False)
l_lux_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x02, 1), 'big', False)
l_lux_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x03, 1), 'big', False)
lux = ((h_lux_h << 24) | (h_lux_l << 16) | (l_lux_h << 8) | l_lux_l) / 100
print(f'lux = {lux} lux')

t_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x04, 1), 'big', False)
t_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x05, 1), 'big', False)
temperature = ((t_h << 8) | t_l) / 100
print(f'temperature = {temperature} c')

h_p_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x06, 1), 'big', False)
h_p_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x07, 1), 'big', False)
l_p_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x08, 1), 'big', False)
l_p_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x09, 1), 'big', False)
pressure = ((h_p_h << 24) | (h_p_l << 16) | (l_p_h << 8) | l_p_l) / 100
print(f'pressure = {pressure} pa')

hum_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x0a, 1), 'big', False)
hum_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x0b, 1), 'big', False)
humidity = ((hum_h << 8) | hum_l) / 100
print(f'humidity = {humidity} %')

e_h = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x0c, 1), 'big', False)
e_l = int.from_bytes(i2c.readfrom_mem(MCU_I2C_ADDR, 0x0d, 1), 'big', False)
elevation = ((e_h << 8) | e_l)
print(f'elevation = {elevation} m')

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|树莓派论坛 ( 粤ICP备15075382号-1  

GMT+8, 2024-10-23 02:47 , Processed in 1.109375 second(s), 25 queries , Gzip On.

Powered by Shumeipai.net! X3.2

© 2001-2015 树莓派论坛安全联盟

快速回复 返回顶部 返回列表