树莓派2代(RaspberryPi2)配合温度传感器DHT11获取温度和湿度

OrangePi ZERO 2 外设应用程序开发之温湿度传感器(DHT11) DHT11 是 DHTxx 系列中使用最广泛的传感器之一,DHT11 可以以 ±2.0°C 的精度测量 0°C 至 50°C 的温度,以 5% 的精度测量 20 至 80% 的湿度。需要注意的是,DHT11 的采样率为 1Hz,这意味着它只能每秒提供一次新数据。具体规格如下表;工作电压3-5V最大工作电流2.5mA max湿度范围温度范围采样率1 Hz (每秒读取一次)体积大小优势超低成本VCC和GND分别为 DHT11 的电源正负极,OUT引脚用于传感器和控制器之间的通信。 阅读详情

DHT11可以同时测量空气的温度和湿度,精度如下:

型号测量范围测湿精度测温精度分辨力封装
DHT1120-90%RH0-50℃±5%RH±2℃14针单排直插

电压适配:3.3v~5.5V DC,具体参数查看百度百科

我在淘宝买到的是一个三个引脚的,引脚顺序是:有格子那面为正面,正面对着自己,左边第一个引脚为1号

引脚号说明
1电源电压
2数据输入输出
3接地

构建这个例子需要下面的零件:

一个树莓派2
一个DHT11温湿度传感器
一个10K欧的电阻
一些安装线
当然得先让树莓派能够正常工作

树莓派2代的引脚有40个:

这里写图片描述

树莓派关机断电,将DHT11与树莓派连接,这里将数据引脚连接到树莓派的GPIO18上,(如果DHT11有四个引脚的请忽略掉引脚3,引脚4号即为下图的3号)

这里写图片描述

连接好后开机,DHT11需要程序来读取数据,使用python语言读取,也可以使用C语言读取,另外还可以使用adafruit提供的DHT11库来读取。(都为网络上参考而来,在本文的最后提供了网站链接)

方法一,使用python代码读取
安装Python GPIO:

# 更新源
sudo apt-get update
# 开始安装
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
# 创建脚本文件
nano dht11.py

在编辑器中键入下面内容:

#!/usr/bin/python
import RPi.GPIO as GPIO
import time

channel = 18
data = []
j = 0

GPIO.setmode(GPIO.BCM)

time.sleep(1)

GPIO.setup(channel, GPIO.OUT)
GPIO.output(channel, GPIO.LOW)
time.sleep(0.02)
GPIO.output(channel, GPIO.HIGH)
GPIO.setup(channel, GPIO.IN)

while GPIO.input(channel) == GPIO.LOW:
  continue
while GPIO.input(channel) == GPIO.HIGH:
  continue

while j < 40:
  k = 0
  while GPIO.input(channel) == GPIO.LOW:
    continue
  while GPIO.input(channel) == GPIO.HIGH:
    k += 1
    if k > 100:
      break
  if k < 8:
    data.append(0)
  else:
    data.append(1)

  j += 1

print "sensor is working."
print data

humidity_bit = data[0:8]
humidity_point_bit = data[8:16]
temperature_bit = data[16:24]
temperature_point_bit = data[24:32]
check_bit = data[32:40]

humidity = 0
humidity_point = 0
temperature = 0
temperature_point = 0
check = 0

for i in range(8):
  humidity += humidity_bit[i] * 2 ** (7-i)
  humidity_point += humidity_point_bit[i] * 2 ** (7-i)
  temperature += temperature_bit[i] * 2 ** (7-i)
  temperature_point += temperature_point_bit[i] * 2 ** (7-i)
  check += check_bit[i] * 2 ** (7-i)

tmp = humidity + humidity_point + temperature + temperature_point

if check == tmp:
  print "temperature :", temperature, "*C, humidity :", humidity, "%"
else:
  print "wrong"
  print "temperature :", temperature, "*C, humidity :", humidity, "% check :", check, ", tmp :", tmp

GPIO.cleanup()

按ctrl+o保存,回车,ctrl+x退出。
然后,输入命令:

sudo chmod u+x dht11.py
sudo ./dth11.py

如果一切顺利,温度和湿度就显示在屏幕上了。

方法二,C代码读取
# 如果没有更新过源,现在更新一下
sudo apt-get update
# 下载 wiringPi (它是用C语言控制和使用树莓派端口的一个类库)
git clone git://git.drogon.net/wiringPi
# 编译 wiringPi
cd wiringPi
./build

安装好后

# 查看GPIO版本号
gpio -v
# 显示GPIO信息
gpio readall

这里写图片描述
新建dht11.c文件

nano dht11.c

键入代码,注意:以上IO的编号方式略有不同,采用wiring编码方式。

/*
 *  dht11.c:
 *  Simple test program to test the wiringPi functions
 *  DHT11 test
 */

#include <wiringPi.h>

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define MAXTIMINGS  85
#define DHTPIN      1
int dht11_dat[5] = { 0, 0, 0, 0, 0 };

void read_dht11_dat()
{
    uint8_t laststate   = HIGH;
    uint8_t counter     = 0;
    uint8_t j       = 0, i;
    float   f; /* fahrenheit */

    dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;

    /* pull pin down for 18 milliseconds */
    pinMode( DHTPIN, OUTPUT );
    digitalWrite( DHTPIN, LOW );
    delay( 18 );
    /* then pull it up for 40 microseconds */
    digitalWrite( DHTPIN, HIGH );
    delayMicroseconds( 40 );
    /* prepare to read the pin */
    pinMode( DHTPIN, INPUT );

    /* detect change and read data */
    for ( i = 0; i < MAXTIMINGS; i++ )
    {
        counter = 0;
        while ( digitalRead( DHTPIN ) == laststate )
        {
            counter++;
            delayMicroseconds( 1 );
            if ( counter == 255 )
            {
                break;
            }
        }
        laststate = digitalRead( DHTPIN );

        if ( counter == 255 )
            break;

        /* ignore first 3 transitions */
        if ( (i >= 4) && (i % 2 == 0) )
        {
            /* shove each bit into the storage bytes */
            dht11_dat[j / 8] <<= 1;
            if ( counter > 16 )
                dht11_dat[j / 8] |= 1;
            j++;
        }
    }

    /*
     * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte
     * print it out if data is good
     */
    if ( (j >= 40) &&
         (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) )
    {
        f = dht11_dat[2] * 9. / 5. + 32;
        printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",
            dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f );
    }else  {
        printf( "Data not good, skip\n" );
    }
}

int main( void )
{
    printf( "Raspberry Pi wiringPi DHT11 Temperature test program\n" );

    if ( wiringPiSetup() == -1 )
        exit( 1 );

    while ( 1 )
    {
        read_dht11_dat();
        delay( 1000 ); /* wait 1sec to refresh */
    }

    return(0);
}

保存ctrl+o,回车,ctrl+x退出。
然后编译(-lwiringPi 表示动态加载 wiringPi 共享库)、运行

gcc -Wall -o dht11c dht11.c -lwiringPi
sudo ./dht11c

这时,温度和湿度会每隔1秒刷新显示一次。

方法三,使用adafruit提供的库

首先

sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl

然后,下载adafruit提供的库

git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT

安装

sudo python setup.py install

好了,现在可以测试了

cd examples
# 11为传感器型号,18为引脚编号
sudo ./AdafruitDHT.py 11 18

引用参考:
http://www.uugear.com/portfolio/dht11-humidity-temperature-sensor-module/
https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/software-install-updated
http://shumeipai.nxez.com/2015/03/17/saks-diy-tutorials-gpio-development-environment.html
http://shumeipai.nxez.com/2013/10/03/raspberry-pi-temperature-sensor-monitors.html
http://surenpi.com/2015/03/17/树莓派连接dht11/#codesyntax_1
http://www.tuicool.com/articles/AZfUfy

树莓派基础实验17:温度传感器实验 一、介绍    温度传感器是检测温度并将其转换为输出信号的组件。根据材料和部件的特点,温度传感器可分为热电阻和热电偶两种,热敏电阻是前者的一种,他由半导体材料制成。大多数热敏电阻是负温度系数(NTC),其电阻随温度升高而降低,由于它们的电阻随温度变化剧烈变化,所以热敏电阻是最敏感的温度传感器。    模拟温度传感器模块使用NTC热敏电阻,因此可以对温度进行敏感测量。它还有一个内置比较器LM393,它可以使模块同时输出数字和模拟信号。该模块可用于温度报警和温度测量。 二、组件 ★Raspberry Pi主板 阅读详情

相关推荐

Raspberry Pi2/3引脚介绍

Raspberry Pi3引脚介绍

EAIBOT的博客 2万+

【树莓派】树莓派+DHT11+onenet云平台

功能:树莓派采集温湿度通过HTTP协议传输到云平台 一、准备: 树莓派3 B、dht11温湿度传感器、onenet平台 二、onenet云平台配置 1、进入官网,点击开发者中心 2、添加产品 3、点击上一步创建的产品,进入界面如下,记录Mastr-APIkey(后面会用到) 4、添加设备,记录设备ID(后面会用到) 5、添加数据...

Jason的技术探索与分享 8355

树莓派DHT11温湿度采集

一个简单的练习项目,利用树莓派实现DHT11温湿度采集,并用存储到TXT文件,利用Django在读取TXT数据。

树莓派 串口如何使用 以及树莓派引脚对照表

本文档为个人博客文档系统的备份版本、作者:小游、作者博客:点击访问 树莓派引脚图如下: 默认情况下,树莓派的串口有两个一个分配给蓝牙,另一个是miini串口,不过这个串口几乎不能正常使用(树莓派1和树莓派2中没有内置的蓝牙模块),我这个是树莓派2B所以没有蓝牙,我们可以直接使用这个串口 确保串口功能激活 查看 /boot/config.txt 文件,查看是否有enable_uart=1,如果没有就自己手动添加。放下面这个地方 禁用串口控制台功能 输入下面两个命令来禁用控制台 sudo systemc.

小游 6073

10BASE-T1S协议中的PLCA机制:实现无碰撞网络传输的关键

本文深入解析了10BASE-T1S协议中的PLCA(物理层冲突避免)机制。作为IEEE 802.3cg标准的关键部分,PLCA通过循环调度与机会传递,从根源上避免了网络碰撞,为工业与汽车等场景提供了确定性的低延迟传输保障,是实现可靠实时通信的核心技术。

weixin_29250403的博客 215

5G NR 帧结构

本节主要介绍5G NR中的帧结构[38.211-4.3]。5G帧结构(Frame Structure)为时域结构。其设计比其4G LTE更为灵活,这种灵活性使5G能够根据应用需求(如增强移动宽带eMBB,超高可靠低时延通信URLLC)进行调整,同时支持差异化的应用场景,提高了5G的利用效率与响应能力。具体而言,5G帧结构是基于时隙和OFDM符号设计的,且5G网络能够根据服务需求动态调整各时隙持续时长。

夫子喵的博客 5303

树莓派2代B的GPIO与实物关系图及入门教程

实物,注意图中标注的脚号: 上图标注的脚号与下图的脚号的圈住的对应 右上角有左右两排共40根针脚,并不是所有的针脚都是GPIO针脚。 硬件连接 原理图 选择开发语言 控制GPIO口有很多方式,比如 shell直接控制raspberry-gpio-python库(Python语言)wiringPi库(C语言)BCM2835 C Lib

rocklee的专栏 1万+

合规批量下载美国上市公司年报数据的一些经验和总结

本文总结了使用Python脚本批量下载和处理美国上市公司SEC报告的技术经验。通过CIK代码查询SEC EDGAR系统,生成特定日期和报告类型的URL,并使用Selenium和Requests库下载报告内容。流程包括数据获取、文件下载、Excel处理和多线程优化,确保高效处理几百条数据。关键技术挑战包括SEC访问限制、动态网页内容和数据完整性,解决方案包括设置合规的User-Agent、使用Selenium模拟浏览器行为以及错误日志记录。最佳实践包括模块化设计、多线程优化和严格遵守SEC合规性。该自动化流程

jyfool的博客 1643

OrangePi PC2 H5 驱动GPIO利用DTH11获取温湿度

去OrangePi官网寻找了一会还是没找到H5 GPIO(PC2)驱动的方法,但是在Armbian一位朋友帮忙编译最新的4.10 pc2 系统的时候发现了H5 的GPIO选项,我在GitHub寻找了一会发现还是H3的GPIO启动很多,没找到H5的GPIO驱动,但是目前解决了驱动,但是支持C语言的支持,还没有...

weixin_33738555的博客 441

ESP32基于Arduino环境开发128*160 TFT_LCD屏幕显示照片

ESP32基于Arduino环境开发128*160 TFT_LCD屏幕显示照片

weixin_42854045的博客 2062

用 ABAP EML 驾驭 RAP 业务对象:从事务缓冲区到落库提交的一条龙实践

摘要:ABAP EML(Entity Manipulation Language)是SAP RAP框架的核心语言能力,为ABAP开发者提供强类型、批处理友好的方式操作RAP业务对象。EML通过事务缓冲区管理数据变更,支持读取(READ ENTITIES)、修改(MODIFY ENTITIES)及事务控制(COMMIT/ROLLBACK ENTITIES)。其特点包括:基于BDEF派生类型确保类型安全,%control和%cid等特殊字段实现精细控制,统一的消息模型便于错误处理。相比传统ABAP数据访问方式,

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 959

树莓派实现dht11温湿度传感器

dht11温湿度传感器使用方法总结 本文章仅作个人笔记,心得。如有错漏之处,敬请指正 一、温湿度传感器是什么? DHT11是一款有已校准数字信号输出的温湿度传感器。它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性。 1.了解dht11的如何使用 使用一种传感器,一定会用到他的数据手册。dht11温湿度传感器也不例外,但并不需要全部浏览,我们只需要看他重要的点。 如: DHT11引脚说明 传感器性能说明 接口说明 数据格式(重要) 这里主要记录如何读取数据格式。 2

vals666的博客 3321

嵌入式AI实战:基于RK3588部署YOLOv11并集成OpenCV实现实时推理(全流程详解)

本文详细介绍了在RK3588芯片上部署YOLOv11目标检测模型的全流程,包括环境搭建、模型转换和实时推理实现。主要内容为:1)通过YOLOv11官方工具将PyTorch模型转为ONNX格式;2)使用RKNN Toolkit2将ONNX模型转换为适配RK3588的RKNN格式;3)在RK3588上结合OpenCV实现实时视频推理功能。教程提供了完整的代码示例和详细步骤说明,帮助开发者快速在边缘设备上部署目标检测模型,实现AI视觉应用的落地。

LXY_LOVE36的博客 219

几种操作树莓派2B GPIO的方法附参考代码

硬件:树莓派2B 系统:Raspbian Debian Wheezy 2014-02-16 环境:wiringPi、BCM2835 C Library、Python2.7、C 注意:以下操作均在root权限下操作 这里总结下操作GPIO的几种方法,希望给新手做个参考,首先准备系统环境,安装系统什么的这里就略过了,Python,C系统自带,wiringPi、BCM2835 C L

NCTU_to_prove_safety的博客 3119

如何给K8S配置一个具有永久有效的kubeconfig

在 Amazon EKS 环境中,Kubernetes 的认证机制与 AWS IAM 深度集成,通过aws-iam-authenticator动态生成临时凭证。这种设计虽然增强了安全性,但给需要持久化凭证的工具链(如 CI/CD 系统中的 KubeVela)带来了挑战。具体表现为:临时凭证失效​​:默认 Token 有效期为 15 分钟至 1 小时;​​IAM 角色限制​​:直接使用aws eks get-token生成的凭证无法持久化

小杨同学的博客 665

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

树莓派2代(RaspberryPi2)配合温度传感器DS18B20获取温度

构建这个例子你需要下面的零件: 一个树莓派2 一个DS18B20温度传感器 一个4.7K欧的电阻 一些安装线 当然你得先让树莓派能够正常工作 DS18B20传感器温度监测范围在-55*C ~ 125*C之间,和三极管的大小和外形差不多,一面圆形一面是平的,平的那一面为正面,从正面看左数第一个引脚为1号引脚, 引脚号|功能 1            接地 2

4402

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

如何获得树莓派CPU实时温度值

如何获得树莓派CPU实时温度值 【前言】         任何的电子设备在工作过程中必定会产生发热的现象,而不控制好设备的温度的话,很有可能会损坏设备,或者照成设备的性能下降,本文将通过学习如何读取树莓派CPU温度值,方便后期对树莓派做一些相应的控制措施。        在树莓派操作系统中,有一个读取温度值的入口,通过读取这个入口返回的值来获得树莓派实时的温度值,具体入口为:/sys/cla

一个分享技术的个人博客 2万+

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Raspberry Pi 引脚说明

除了供电针脚(包括GND,3.3V和5V),所有的GPIO针脚均可被用于数字输入或输出。 标记为SCL(串行时钟)和SDA(串行数据)的针脚可被用于 I2C。 标记为MOSI,MISO和SCKL的针脚可以用于连接高速 SPI 设备。 树莓派2代,3代B版本接口图 树莓派2代B版本接口说明图 需要特别注意,标注为 ID EEPROM...

simple_star_80的博客 4805

树莓派开发之旅 (十四)【树莓派驱动DHT11的几种方法】

树莓派读取DHT11传感器温湿度值的几种方法

ZZQ的博客 1993

树莓派 40Pin 引脚对照表

注:本表格适用于树莓派B+、树莓派2B、树莓派A+,并且兼容树莓派B,树莓派B为26Pin,其引脚对应于上表的前26Pin。本文来自:树莓派实验室链接地址:http://shumeipai.nxez.com/raspberry-pi-pins-version-40 转载于:https://blog.51cto.com/twoears/1652435...

weixin_34127717的博客 489

基础篇——树莓派通用引脚定义

背景故事 树莓派主板集成了丰富的IO口,可以用于输入输出,通信等功能,常常用于物联网控制、传感器数据交互等方面,这里我们讲解一下怎么使用IO口作为输入输出,并控制一些简单的电路。 引脚直观图 我在网上找到一张非常直观的引脚对应图,树莓派3B、3B+、4B、zero全系列IO定义均相同,都可以参考。图片如下: 命令行查看引脚 如果没有图片,也可以直接在树莓派的shell窗口中输入指令 pinout来显示引脚定义,以及相关版本号,操作如下图(这里以3B为例): ...

玩转智能机器人 3万+

树莓派raspberry 2b 继电器控制、GPIO环境设置

1.首先确定GPIO库已经安装,可以参考: https://blog.csdn.net/sxhexin/article/details/94889079 2.用2种方式测试: 1)wiringpi 库测试 目前该库已经不维护了,官网无法下载。 安装包 gpio readall 代码如下:使用了GPIO29. #include <wiringPi.h> #include <stdio.h> #define GPIO_NUM 29 int main() { int c

dgj8300的专栏 882

【手把手教你树莓派3 (五)】DHT11传感器

连线方式: 先贴一张树莓派3b的引脚图: 在连线的时候注意编码方式,注意树莓派引脚图的方向,如上图所示。我用的是三个头的dht11传感器,因此连线方式是: VCC(或正极) --- 树莓派的3v电源 GND (地线或者负极)--- 树莓派的gnd接口 DATA (D或者out) ---树莓派的GPIO引脚 注意自己的传感器的接口的顺序。 python脚本 pytho

u010900754的专栏 2万+

树莓派通过GPIO口获取温度以及控制LED灯

预备知识 硬件端的连接 首先介绍DHT11(温度传感器)的连接,DHT11如图所示,有三个引脚.VCC,GND,以及DATA, VCC代表的是电源,一般连接的是3.3v,对于40Pin的GPIO的1号引脚,DATA引脚是用来传递数据的,连接树莓派的12号引脚.GND是接地的,可以连接着树莓派任意的GND引脚.下面给出树莓派40pin的引脚图. 先给出DHT11的实物连接图. 现

Chen_dSir的博客 3546

树莓派各版本引脚及参数

树莓派参数 树莓派各版本比较: 树莓派3B参数(表格参考): 名称 参数 备注 SOC 博通 BCM2837 CPU ARM Cortex-A53 1.2GHz 64-bit 四核 ARMv8 CPU 较2代提高50% GPU Broadcom VideoCrore IV,OpenGL ES 2.0,1080p 30 h....

星迹 2万+
上一篇: 树莓派2代(RaspberryPi2)配合温度传感器DS18B20获取温度
下一篇: Raspberry PI2 and both i2c busses 打开RaspberryPi2的第二个i2c口 (i2c-0)
netccy
博客等级 码龄19年 4粉丝 8原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值