今天拿到一个温湿度传感器,型号是SHT2x,通讯接口是I2C,要照往常学习的顺序是,先找arduino库,然后运行demo,这次之所以先用了stm是因为传感器要求3.3V,而arduino一般都是5V
测试代码,串口输出温度和湿度
#include "mbed.h"
#include "SHT21_ncleee.h"
DigitalOut myled(LED1);
I2C i2c(D14, D15);
SHT21 sht(&i2c);
int main() {
printf("Hello World...\n Testing temperature and humidity sensor\n");
float temperature;
float humidity;
while(1) {
temperature = sht.readTemp();
humidity = sht.readHumidity();
printf("Temperature=%.1f Humidity=%.1f%%\n",temperature,humidity);
myled = 1;
wait(2.5);
myled = 0;
wait(2.5);
}
}
我要赚赏金打赏帖 |
|
|---|---|
| 一种有效完成脚本程序测试的方法被打赏¥28元 | |
| WorkBuddy搭配SolidCraft给开发板做两件式外壳被打赏¥33元 | |
| 开箱一块k230被打赏¥33元 | |
| 【瑞萨RA8D1测评】RA8D1+lwIP网络验证与TCPOTA的实验记录被打赏¥33元 | |
| 28BYJ-48机械臂实现人脸跟随被打赏¥24元 | |
| 基于RK3506B的片温识读功能的实现被打赏¥25元 | |
| 【瑞萨RA8D1测评】基于FreeRTOS的lvgl移植教程被打赏¥29元 | |
| 电子价签墨水屏开发被打赏¥35元 | |
| 【Ozone】RTT 打印终端使用被打赏¥29元 | |
| BMS保护板绝缘检测功能-不平衡电桥技术绝缘电阻检测设计与实现被打赏¥34元 | |