Ai
1 Star 0 Fork 0

vuitech/M5FactoryTest

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sht30.cpp 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
李辉 提交于 2022-11-08 16:24 +08:00 . 创建初始版本
#include <Wire.h>
#include <Arduino.h>
#define Addr_SHT30 0x44
#define SDA_PIN 21
#define SCL_PIN 22
int read_temp()
{
unsigned int data[6];
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
Wire.beginTransmission(Addr_SHT30);
Wire.write(0x2C);
Wire.write(0x06);
Wire.endTransmission();
delay(100);
Wire.requestFrom(Addr_SHT30, 6);
if (Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
int Temp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
// float Humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);
return Temp;
// Serial.print("相对湿度:");
// Serial.print(Humidity);
// Serial.println(" %RH");
Serial.print("温度:");
Serial.print(Temp);
Serial.println(" °C");
delay(100);
/* */
}
int read_humi()
{
unsigned int data[6];
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
Wire.beginTransmission(Addr_SHT30);
Wire.write(0x2C);
Wire.write(0x06);
Wire.endTransmission();
delay(100);
Wire.requestFrom(Addr_SHT30, 6);
if (Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
//float Temp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45;
int Humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);
return Humidity;
/*
Serial.print("相对湿度:");
Serial.print(Humidity);
Serial.println(" %RH");
Serial.print("温度:");
Serial.print(Temp);
Serial.println(" °C");
delay(1000);
*/
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/vuitech/FactoryTest.git
git@gitee.com:vuitech/FactoryTest.git
vuitech
FactoryTest
M5FactoryTest
master

搜索帮助