当前位置:网站首页>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
边栏推荐
- mysql_ Download and installation of Linux version
- os_ authent_ Prefix
- On iptables
- Actual combat of Nacos as service configuration center
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- Nacos as service registry
- STM32: LCD display
- mysql_linux版本的下载及安装详解
- MySQL statement
- Esp32 (UART 485 communication) - 485 communication of serial port (3)
猜你喜欢
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
os_ authent_ Prefix
ctfshow-web361(SSTI)
iptables -L执行缓慢
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
Use Chenxi bookkeeping book to analyze the balance of revenue and expenditure of each account in a certain period of time
C: generic reflection
微搭低代码零基础入门课(第三课)
ESP32 LVGL8. 1 - textarea text area (textarea 26)
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
随机推荐
微搭低代码零基础入门课(第三课)
22年字节跳动飞书人力套件三面面经
简化路径(力扣71)
listener. log
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
K210串口通信
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Esp32 (UART ecoh) - serial port echo worm learning (2)
ESP32 LVGL8. 1 - img picture (IMG 20)
STM32: LCD显示
Configure iptables
ESP32 LVGL8. 1 - textarea text area (textarea 26)
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
STM32: LCD display
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
Practice of Druid SQL and security in meituan review
os_authent_prefix
The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure