DHT22和gpio的工作方式如何? [英] How do DHT22 and gpio's work?

查看:151
本文介绍了DHT22和gpio的工作方式如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是给我自己一个用于温度和湿度的传感器DHT22,我对此有些疑问:
-该设备仅可用于arduino或Rpi吗?
-如果答案为否,那么它如何与GPIO配合使用?据我了解,gpio有2个选项:-Direcion(输入或输出)和Value(0或1)。因此,据此,我在arduino和Rpi上查看了许多有关如何使用此设备的示例,所有示例均附接到gpio的端口上。那么这是如何工作的呢? c / c ++是否具有更大的处理这些读数的能力?
-如果传感器可以与更多设备一起使用,是否有任何Linux标准库/代码可以处理该设备?



谢谢。

解决方案

DHT22如您所述,可以通过GPIO引脚工作。这意味着任何具有GPIO的设备都可以使用它。



关于库。有两个主要的库,用于通过编写的GPIO进行通信,一个用于C ++,另一个用于Python。这意味着任何具有GPIO且可以运行Python或C ++的设备都可以使用您的DHT22。



基于C ++,Python和Java的库怎么办? ?嗯,没有没有 Linux标准库用于通过GPIO进行通信。当然,如果您渴望学习和探索,则可以用Assembly或Bash编写一个库,该库将尽可能地接近LSL。这样,您就可以通过Linux shell上的GPIO进行本地通信,而无需任何其他编程语言。如果您对Bash感兴趣,请查看

>

Linux在只能读取0和1时如何知道温度和湿度?请考虑两件事:


  1. 计算机的存储号码 32 如何?计算机仅知道 0 1 ,因此他需要将 32 转换为二进制。什么是 32 = 2 ^ 6 (十进制),什么是 100000 (二进制)。

  2. 计算机如何读取温度和湿度?当执行诸如

      get_temperature()


    向DHT22请求温度,实际上发生的是您的计算机向DHT22发送信号(它通过DHT22上的IN通过GPIO通过GPIO写入到DHT22,这与OUT上的相同电脑)。然后DHT22感测温度并将数据发送回去。 如何发送?它通过GPIO(计算机上的GPIO IN和DHT22上的GPIO OUT)创建一系列电荷。在我们的例子中,如果温度为 32 ,则它将发送下一个序列: 1-0-0-0-0-0 。计算机会读取序列,当您尝试将其打印到屏幕时,会将其转换为十进制。


希望我得到了我很清楚,这就是您想要的。



在此链接,如果您要查找DHT22温度和湿度,则会找到一个C代码。请让我知道您总体上想做什么(通过库读取温度和嗡嗡声,编写用于通过GPIO进行通信的新库,为DHT22用另一种语言编写新库...)。


I just got myself a sensor DHT22 for temperature and humidity and I have some doubts: - Is this device only usable with arduino or Rpi? - If the answer is No, how does it work with the GPIO? As far as I understand, gpio has2 options: -Direcion (in or out) and Value (0 or 1). So according to this, I was checking a lot of examples for arduino and Rpi on how to use this devices, and all are attached to gpio's port. So how is this working? Does c/c++ has bigger capacity to handle this readings? - If the sensor can be used with more devices, is there any linux standard library/code to handle this device?

Thanks.

解决方案

The DHT22 is, as you described, made to work over GPIO pins. That means that any device with GPIO can use it.

About the libraries. There are two major libraries for communicating via GPIO written, one for C++ and one for Python. That means that any device that has GPIO and can run Python or C++ can use your DHT22.

What about no C++, Python, Java... based libraries? Well, there is no Linux standard library for communicating over GPIO. Of course, if you are eager to learn and explore, you can write a library in Assembly or Bash, which would be as close to LSL as you can get. By doing that you can natively communicate over GPIO from Linux shell without any other programming language. If you are interested in Bash, take a look at this.

How does Linux know the temperature and humidity when it can only read 0s and 1s? Consider two things:

  1. How does computer store number 32? The computer only knows 0's and 1's so he needs to convert 32 to binary. What is 32 = 2^6 in decimal, is 100000 in binary.
  2. How does computer read temperature and humidity? When you execute a function like

    get_temperature()
    

    which requests temperature from DHT22, what actually happens is that your computer sends signal to DHT22 (it "writes" to DHT22 over GPIO through IN on DHT22, which is the same as OUT on computer). Then the DHT22 senses the temperature and "sends" data back. How does it send it? It creates a sequence of electric charges through GPIO (GPIO IN on computer and GPIO OUT on DHT22). In our case, if temperature is 32, then it sends the next sequence: 1-0-0-0-0-0. The computer reads the sequence and when you try to print it to screen it converts it into decimal.

Hope I got myself clear and this is what you wanted.

In this link you find a C code for reading DHT22 temperature and humidity if that is what you want. Please let me know what you want to do in general (read temp. and hum. via library, write new library for communicating over GPIO, write new library in another language for DHT22...).

这篇关于DHT22和gpio的工作方式如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆