树莓派使用DS18B20模块测量温度
2016-12-11 21:14
507 查看
参考:
http://shumeipai.nxez.com/2013/10/03/raspberry-pi-temperature-sensor-monitors.html
第一步,允许单总线接口
第二步,接线
接BCM编码为4即图上物理引脚7
第三步,升级内核
第四步,查看当前温度
python
打印结果:
http://shumeipai.nxez.com/2013/10/03/raspberry-pi-temperature-sensor-monitors.html
第一步,允许单总线接口
sudo raspi-config 进入interfacingoptions enable one-wire interface
第二步,接线
接BCM编码为4即图上物理引脚7
第三步,升级内核
sudo apt-get update sudo apt-get upgrade
pi@raspberrypi:~$ cd /sys/bus/w1/devices/ pi@raspberrypi:/sys/bus/w1/devices$ ls 28-00000xxxxxx w1_bus_master1
第四步,查看当前温度
cd 28-00000xxxxxx cat w1_slave 显示: 46 01 4b 46 7f ff 0c 10 2f : crc=2f YES 46 01 4b 46 7f ff 0c 10 2f t=20375 第二行的t=20375就是当前的温度值,要换算成摄氏度,除以1000,即当前温度为20375/1000=20.375摄氏度。
python
#!/usr/bin/python3 import os,time device_file ='/sys/bus/w1/devices/28-031681e171ff/w1_slave' def read_temp_raw(): f = open(device_file,'r') lines = f.readlines() f.close() return lines def read_temp(): lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos+2:] temp_c = float(temp_string)/1000.0 return temp_c while True: print('temp C = %f'%read_temp()) time.sleep(1)
打印结果:
pi@raspberrypi:~/myPython $ ./temp_ds18b20.py temp C = 20.687000 temp C = 20.687000 temp C = 20.687000 temp C = 20.750000 temp C = 20.750000 temp C = 20.750000
相关文章推荐
- 树莓派使用DS18B20模块测量温度
- 树莓派进阶之路 (015) - 树莓派使用DS18B20模块测量温度
- DS18B20的温度测量
- Ruby Benchmark 模块提供了测量和报告Ruby代码运行使用时间的方法。
- 使用GY89的BMP180模块获取温度和压强(海拔)
- 基于迅为Itop4412开发板上控制ds18b20测量温度
- 温度传感器--DS18B20的使用
- 单片机练习 - 使用1602LCD显示DS18B20的温度值
- Raspberry Pi 树莓派连接温度传感器DS18B20
- 树莓派2代(RaspberryPi2)配合温度传感器DS18B20获取温度
- (13)树莓派B+ 读取DHT11温度湿度模块的数值
- 单片机ds18b20测量温度
- DS18B20温度传感器使用简介
- 51+DS18B20测量温度(续)
- 51+DS18B20测量温度(续)
- 树莓派 HC-SR04 模块使用
- DS18B20温度模块.C
- 树莓派使用python获取GY-85九轴模块信息
- LPC213x ARM板子的DS18B20温度传感器模块添加
- 树莓派:4. 树莓派搭建美观的物联网温度服务器-ECharts、HTML5、JavaScript / ECharts gauge使用示例