当前位置:网站首页>Raspberry pie 18b20 temperature
Raspberry pie 18b20 temperature
2022-04-23 18:52:00 【Brick Porter】
One 、 modify /boot/config.txt Add... To the last line dtoverlay=w1-gpio
Or use GUI operation
Plug in the module after shutdown , The default module reads GPIO.7, namely BCM Of 4 foot , If everything is normal, you can see a 28- Aligned equipment . The temperature value can be obtained by reading the file under a device , I will not go into details here .
#pragma once
#include <fstream>
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
class CDTH22
{
public:
static std::string GetTemp()
{
std::string ret;
fs::path str("/sys/bus/w1/devices");
if (!fs::exists(str))
return ret;
fs::directory_entry entry(str);
if (entry.status().type() == fs::file_type::directory)
{
fs::directory_iterator list(str);
for (auto& it : list)
{
if (it.is_directory()&&(it.path().filename().string().find("28-")==0))
{
std::ifstream tfile(it.path().string()+"/w1_slave");
if (tfile.is_open())
{
std::string buf;
std::getline(tfile,buf);
//CRC ok
if (buf.rfind("YES") != std::string::npos)
{
std::getline(tfile, buf);
std::size_t pos=buf.rfind("t=");
if(pos!= std::string::npos)
try {
ret=std::to_string(std::atoi(buf.data() + pos + 2)/1000);
}
catch (...)
{
}
}
}
}
}
}
return ret;
}
};
The above code needs CPP17 Support .
版权声明
本文为[Brick Porter]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210603257146.html
边栏推荐
- Loop path
- ESP32 LVGL8. 1 - label (style 14)
- Nacos cluster construction and MySQL persistence configuration
- How about CICC wealth? Is it safe to open an account up there
- 在渤海期货办理开户安全吗。
- Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
- Actual combat of Nacos as service configuration center
- listener.log
- The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
- os_authent_prefix
猜你喜欢
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
MVVM模型
[mathematical modeling] - analytic hierarchy process (AHP)
ESP32 LVGL8. 1 - label (style 14)
昇腾 AI 开发者创享日全国巡回首站在西安成功举行
【数学建模】—— 层次分析法(AHP)
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
七、DOM(下) - 章节课后练习题及答案
iptables -L执行缓慢
随机推荐
QT curve / oscilloscope customplot control
mysql_linux版本的下载及安装详解
After CANopen starts PDO timing transmission, the heartbeat frame time is wrong, PDO is delayed, and CANopen time axis is disordered
Domestic GD chip can filter
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
从技术体系到商业洞察,中小研发团队架构实践之收尾篇
Simplified path (force buckle 71)
12个例子夯实promise基础
CANopen STM32 transplantation
How to virtualize the video frame and background is realized in a few simple steps
Keil RVMDK compiled data type
Simple use of navigation in jetpack
Coolweather is revised and connected to the wind weather interface to realize the broken line diagram of temperature
ESP32 LVGL8. 1 - slider slider (slider 22)
os_ authent_ Prefix
#yyds干货盘点#stringprep --- 因特网字符串预备
【数学建模】—— 层次分析法(AHP)
The type initializer for ‘Gdip‘ threw an exception
How can programmers quickly develop high-quality code?
Get a list of recent apps