当前位置:网站首页>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
边栏推荐
- 教你用简单几个步骤快速重命名文件夹名
- Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
- os_authent_prefix
- K210 serial communication
- Use of kotlin collaboration in the project
- 实战业务优化方案总结---主目录---持续更新
- Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
- Ctfshow - web362 (ssti)
- QT error: no matching member function for call to ‘connect‘
- Introduction to ROS learning notes (I)
猜你喜欢
ESP32 LVGL8. 1 - slider slider (slider 22)
Simplified path (force buckle 71)
Esp32 (UART event) - serial port event learning (1)
Iptables - L executes slowly
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
Machine learning practice - naive Bayes
STM32: LCD display
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
ESP32 LVGL8. 1 - label (style 14)
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
随机推荐
RPM package management
深入理解 Golang 中的 new 和 make 是什么, 差异在哪?
How about CICC wealth? Is it safe to open an account up there
Teach you to quickly rename folder names in a few simple steps
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
ESP32 LVGL8. 1 - arc (arc 19)
ESP32 LVGL8. 1 - checkbox (checkbox 23)
About the operation of unit file reading (I)
特征选择feature_selection--SelectKBest
Machine learning practice - naive Bayes
从技术体系到商业洞察,中小研发团队架构实践之收尾篇
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
Download xshell 6 and xftp6 official websites
ESP32 LVGL8. 1 - event (event 17)
ESP32 LVGL8. 1 - bar progress bar (bar 21)
22 year flying Book manpower Kit
机器学习实战 -朴素贝叶斯
ESP32 LVGL8. 1 - roller rolling (roller 24)
电路在线模拟
After opening the original normal project, the dependency package displays red and does not exist.