{"id":1175921,"date":"2025-01-15T17:38:38","date_gmt":"2025-01-15T09:38:38","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1175921.html"},"modified":"2025-01-15T17:38:40","modified_gmt":"2025-01-15T09:38:40","slug":"python%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%b8%a9%e6%b9%bf%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1175921.html","title":{"rendered":"python\u5982\u4f55\u83b7\u53d6\u6e29\u6e7f\u5ea6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25111239\/5f3ee387-101c-458f-8ce6-56dab6e55d2b.webp\" alt=\"python\u5982\u4f55\u83b7\u53d6\u6e29\u6e7f\u5ea6\" \/><\/p>\n<p><p> <strong>Python\u83b7\u53d6\u6e29\u6e7f\u5ea6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u4f20\u611f\u5668\u6a21\u5757\u3001\u8c03\u7528\u5916\u90e8API\u3001\u4f7f\u7528Raspberry Pi\u548cArduino\u7b49\u5fae\u63a7\u5236\u5668\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u4f7f\u7528\u4f20\u611f\u5668\u6a21\u5757<\/strong> \u662f\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\u4e4b\u4e00\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u4f7f\u7528\u4f20\u611f\u5668\u6a21\u5757\u83b7\u53d6\u6e29\u6e7f\u5ea6\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u4f20\u611f\u5668\u6a21\u5757<\/h3>\n<\/p>\n<p><h4>1\u3001DHT11\/DHT22\u4f20\u611f\u5668<\/h4>\n<\/p>\n<p><p>DHT11\u548cDHT22\u662f\u4e24\u79cd\u5e38\u89c1\u7684\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\uff0c\u5177\u6709\u4ef7\u683c\u4f4e\u5ec9\u3001\u6613\u4e8e\u4f7f\u7528\u7684\u7279\u70b9\u3002DHT22\u7684\u7cbe\u5ea6\u548c\u8303\u56f4\u4f18\u4e8eDHT11\u3002\u5b83\u4eec\u90fd\u53ef\u4ee5\u901a\u8fc7\u6570\u5b57\u4fe1\u53f7\u63a5\u53e3\u4e0e\u5fae\u63a7\u5236\u5668\u901a\u4fe1\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u548cRaspberry Pi\u8bfb\u53d6DHT\u4f20\u611f\u5668\u6570\u636e\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5Adafruit_DHT\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo pip3 install Adafruit_DHT<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u4f20\u611f\u5668\u5230Raspberry Pi\uff1a<\/p>\n<\/p>\n<ul>\n<li>VCC\u8fde\u63a5\u52305V\u7535\u6e90<\/li>\n<li>GND\u8fde\u63a5\u5230\u5730<\/li>\n<li>Data\u8fde\u63a5\u5230GPIO\u5f15\u811a<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import Adafruit_DHT<\/p>\n<h2><strong>\u9009\u62e9DHT\u4f20\u611f\u5668\u578b\u53f7<\/strong><\/h2>\n<p>DHT_SENSOR = Adafruit_DHT.DHT22  # \u6216\u8005DHT11<\/p>\n<p>DHT_PIN = 4  # \u8fde\u63a5\u6570\u636e\u5f15\u811a\u7684GPIO\u7f16\u53f7<\/p>\n<p>def read_dht_sensor():<\/p>\n<p>    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)<\/p>\n<p>    if humidity is not None and temperature is not None:<\/p>\n<p>        print(f&quot;Temp={temperature:.1f}C  Humidity={humidity:.1f}%&quot;)<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;F<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led to retrieve data from humidity sensor&quot;)<\/p>\n<p>read_dht_sensor()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u8c03\u7528\u5916\u90e8API<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528OpenWeatherMap API<\/h4>\n<\/p>\n<p><p>OpenWeatherMap\u63d0\u4f9b\u4e86\u5168\u7403\u5929\u6c14\u6570\u636e\u7684API\uff0c\u4f7f\u7528\u8be5API\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u4efb\u4f55\u57ce\u5e02\u7684\u6e29\u6e7f\u5ea6\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u8c03\u7528OpenWeatherMap API\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u6ce8\u518c\u5e76\u83b7\u53d6API\u5bc6\u94a5\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u8bbf\u95eeOpenWeatherMap\u5b98\u7f51\u6ce8\u518c\u8d26\u53f7\u5e76\u83b7\u53d6API\u5bc6\u94a5<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b89\u88c5\u8bf7\u6c42\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u8c03\u7528API\u5e76\u5904\u7406\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>API_KEY = &quot;your_api_key&quot;<\/p>\n<p>CITY = &quot;London&quot;<\/p>\n<p>URL = f&quot;http:\/\/api.openweathermap.org\/data\/2.5\/weather?q={CITY}&amp;appid={API_KEY}&amp;units=metric&quot;<\/p>\n<p>def get_weather_data():<\/p>\n<p>    response = requests.get(URL)<\/p>\n<p>    if response.status_code == 200:<\/p>\n<p>        data = response.json()<\/p>\n<p>        temperature = data[&#39;main&#39;][&#39;temp&#39;]<\/p>\n<p>        humidity = data[&#39;main&#39;][&#39;humidity&#39;]<\/p>\n<p>        print(f&quot;Temperature: {temperature}\u00b0C&quot;)<\/p>\n<p>        print(f&quot;Humidity: {humidity}%&quot;)<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;Error in the HTTP request&quot;)<\/p>\n<p>get_weather_data()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528Raspberry Pi\u548cArduino<\/h3>\n<\/p>\n<p><h4>1\u3001Raspberry Pi<\/h4>\n<\/p>\n<p><p>Raspberry Pi\u662f\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5fae\u63a7\u5236\u5668\uff0c\u53ef\u4ee5\u8f7b\u677e\u8fde\u63a5\u5404\u79cd\u4f20\u611f\u5668\u3002\u7ed3\u5408\u4e0a\u6587\u4ecb\u7ecd\u7684DHT\u4f20\u611f\u5668\uff0c\u53ef\u4ee5\u5b9e\u73b0\u6e29\u6e7f\u5ea6\u6570\u636e\u7684\u83b7\u53d6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5\u76f8\u5173\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt-get update<\/p>\n<p>sudo apt-get install python3-pip<\/p>\n<p>sudo pip3 install Adafruit_DHT<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import Adafruit_DHT<\/p>\n<p>DHT_SENSOR = Adafruit_DHT.DHT22<\/p>\n<p>DHT_PIN = 4<\/p>\n<p>def read_dht_sensor():<\/p>\n<p>    humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)<\/p>\n<p>    if humidity is not None and temperature is not None:<\/p>\n<p>        print(f&quot;Temp={temperature:.1f}C  Humidity={humidity:.1f}%&quot;)<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;Failed to retrieve data from humidity sensor&quot;)<\/p>\n<p>read_dht_sensor()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>2\u3001Arduino<\/h4>\n<\/p>\n<p><p>Arduino\u662f\u4e00\u79cd\u5f00\u6e90\u7684\u7535\u5b50\u539f\u578b\u5e73\u53f0\uff0c\u7ed3\u5408DHT\u4f20\u611f\u5668\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u6e29\u6e7f\u5ea6\u6570\u636e\u7684\u83b7\u53d6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5DHT\u5e93\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00Arduino IDE\uff0c\u70b9\u51fb\u201c\u5e93\u7ba1\u7406\u5668\u201d\uff0c\u641c\u7d22\u201cDHT\u201d\u5e76\u5b89\u88c5Adafruit DHT\u5e93<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f16\u5199Arduino\u4ee3\u7801\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-c\">#include &quot;DHT.h&quot;<\/p>\n<p>#define DHTPIN 2    \/\/ \u8fde\u63a5DHT\u4f20\u611f\u5668\u7684\u6570\u636e\u5f15\u811a<\/p>\n<p>#define DHTTYPE DHT22   \/\/ DHT 22 (AM2302)<\/p>\n<p>DHT dht(DHTPIN, DHTTYPE);<\/p>\n<p>void setup() {<\/p>\n<p>  Serial.begin(9600);<\/p>\n<p>  dht.begin();<\/p>\n<p>}<\/p>\n<p>void loop() {<\/p>\n<p>  float humidity = dht.readHumidity();<\/p>\n<p>  float temperature = dht.readTemperature();<\/p>\n<p>  if (isnan(humidity) || isnan(temperature)) {<\/p>\n<p>    Serial.println(&quot;Failed to read from DHT sensor!&quot;);<\/p>\n<p>    return;<\/p>\n<p>  }<\/p>\n<p>  Serial.print(&quot;Humidity: &quot;);<\/p>\n<p>  Serial.print(humidity);<\/p>\n<p>  Serial.print(&quot; %\\t&quot;);<\/p>\n<p>  Serial.print(&quot;Temperature: &quot;);<\/p>\n<p>  Serial.print(temperature);<\/p>\n<p>  Serial.println(&quot; *C&quot;);<\/p>\n<p>  delay(2000);<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5176\u4ed6\u4f20\u611f\u5668\u6a21\u5757<\/h3>\n<\/p>\n<p><h4>1\u3001BME280\u4f20\u611f\u5668<\/h4>\n<\/p>\n<p><p>BME280\u662f\u4e00\u6b3e\u96c6\u6210\u4e86\u6e29\u5ea6\u3001\u6e7f\u5ea6\u548c\u6c14\u538b\u4f20\u611f\u5668\u7684\u6a21\u5757\uff0c\u5177\u6709\u9ad8\u7cbe\u5ea6\u548c\u4f4e\u529f\u8017\u7684\u7279\u70b9\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u8bfb\u53d6BME280\u4f20\u611f\u5668\u6570\u636e\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo pip3 install adafruit-circuitpython-bme280<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u4f20\u611f\u5668\u5230Raspberry Pi\uff1a<\/p>\n<\/p>\n<ul>\n<li>VCC\u8fde\u63a5\u52303.3V\u7535\u6e90<\/li>\n<li>GND\u8fde\u63a5\u5230\u5730<\/li>\n<li>SCL\u8fde\u63a5\u5230I2C\u65f6\u949f\u5f15\u811a<\/li>\n<li>SDA\u8fde\u63a5\u5230I2C\u6570\u636e\u5f15\u811a<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import board<\/p>\n<p>import busio<\/p>\n<p>import adafruit_bme280<\/p>\n<p>i2c = busio.I2C(board.SCL, board.SDA)<\/p>\n<p>bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)<\/p>\n<p>def read_bme280_sensor():<\/p>\n<p>    temperature = bme280.temperature<\/p>\n<p>    humidity = bme280.humidity<\/p>\n<p>    pressure = bme280.pressure<\/p>\n<p>    print(f&quot;Temperature: {temperature:.1f}C&quot;)<\/p>\n<p>    print(f&quot;Humidity: {humidity:.1f}%&quot;)<\/p>\n<p>    print(f&quot;Pressure: {pressure:.1f} hPa&quot;)<\/p>\n<p>read_bme280_sensor()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>2\u3001SHT31\u4f20\u611f\u5668<\/h4>\n<\/p>\n<p><p>SHT31\u662f\u4e00\u6b3e\u9ad8\u7cbe\u5ea6\u7684\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\uff0c\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u7cbe\u5ea6\u73af\u5883\u76d1\u6d4b\u7684\u5e94\u7528\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u8bfb\u53d6SHT31\u4f20\u611f\u5668\u6570\u636e\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo pip3 install adafruit-circuitpython-sht31d<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u4f20\u611f\u5668\u5230Raspberry Pi\uff1a<\/p>\n<\/p>\n<ul>\n<li>VCC\u8fde\u63a5\u52303.3V\u7535\u6e90<\/li>\n<li>GND\u8fde\u63a5\u5230\u5730<\/li>\n<li>SCL\u8fde\u63a5\u5230I2C\u65f6\u949f\u5f15\u811a<\/li>\n<li>SDA\u8fde\u63a5\u5230I2C\u6570\u636e\u5f15\u811a<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import board<\/p>\n<p>import busio<\/p>\n<p>import adafruit_sht31d<\/p>\n<p>i2c = busio.I2C(board.SCL, board.SDA)<\/p>\n<p>sht31d = adafruit_sht31d.SHT31D(i2c)<\/p>\n<p>def read_sht31d_sensor():<\/p>\n<p>    temperature = sht31d.temperature<\/p>\n<p>    humidity = sht31d.relative_humidity<\/p>\n<p>    print(f&quot;Temperature: {temperature:.1f}C&quot;)<\/p>\n<p>    print(f&quot;Humidity: {humidity:.1f}%&quot;)<\/p>\n<p>read_sht31d_sensor()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u6570\u636e\u5904\u7406\u4e0e\u53ef\u89c6\u5316<\/h3>\n<\/p>\n<p><p>\u83b7\u53d6\u6e29\u6e7f\u5ea6\u6570\u636e\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u5904\u7406\u548c\u53ef\u89c6\u5316\uff0c\u4ee5\u4fbf\u66f4\u76f4\u89c2\u5730\u5206\u6790\u548c\u5c55\u793a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u6570\u636e\u5904\u7406\u548c\u53ef\u89c6\u5316\u5e93\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001Pandas<\/h4>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u5e93\uff0c\u9002\u7528\u4e8e\u5904\u7406\u65f6\u95f4\u5e8f\u5217\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Pandas\u5904\u7406\u6e29\u6e7f\u5ea6\u6570\u636e\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5Pandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u5904\u7406\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {<\/p>\n<p>    &#39;timestamp&#39;: [&#39;2023-01-01 12:00&#39;, &#39;2023-01-01 13:00&#39;, &#39;2023-01-01 14:00&#39;],<\/p>\n<p>    &#39;temperature&#39;: [22.5, 23.0, 23.5],<\/p>\n<p>    &#39;humidity&#39;: [45.0, 46.0, 47.0]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;timestamp&#39;] = pd.to_datetime(df[&#39;timestamp&#39;])<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h4>2\u3001Matplotlib<\/h4>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u7ed8\u5236\u6e29\u6e7f\u5ea6\u53d8\u5316\u7684\u66f2\u7ebf\u56fe\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Matplotlib\u7ed8\u5236\u6e29\u6e7f\u5ea6\u6570\u636e\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p>\u5b89\u88c5Matplotlib\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p>\u7f16\u5199Python\u4ee3\u7801\u7ed8\u5236\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>data = {<\/p>\n<p>    &#39;timestamp&#39;: [&#39;2023-01-01 12:00&#39;, &#39;2023-01-01 13:00&#39;, &#39;2023-01-01 14:00&#39;],<\/p>\n<p>    &#39;temperature&#39;: [22.5, 23.0, 23.5],<\/p>\n<p>    &#39;humidity&#39;: [45.0, 46.0, 47.0]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;timestamp&#39;] = pd.to_datetime(df[&#39;timestamp&#39;])<\/p>\n<p>plt.figure(figsize=(10, 5))<\/p>\n<p>plt.plot(df[&#39;timestamp&#39;], df[&#39;temperature&#39;], label=&#39;Temperature (\u00b0C)&#39;)<\/p>\n<p>plt.plot(df[&#39;timestamp&#39;], df[&#39;humidity&#39;], label=&#39;Humidity (%)&#39;)<\/p>\n<p>plt.xlabel(&#39;Timestamp&#39;)<\/p>\n<p>plt.ylabel(&#39;Value&#39;)<\/p>\n<p>plt.title(&#39;Temperature and Humidity Over Time&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.grid(True)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u4e86\u89e3\u4e86<strong>Python\u83b7\u53d6\u6e29\u6e7f\u5ea6<\/strong> \u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u4f20\u611f\u5668\u6a21\u5757\u3001\u8c03\u7528\u5916\u90e8API\u3001\u4f7f\u7528Raspberry Pi\u548cArduino\u7b49\u5fae\u63a7\u5236\u5668\uff0c\u5e76\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Pandas\u548cMatplotlib\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u53ef\u89c6\u5316\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6848\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u73af\u5883\u76d1\u6d4b\uff0c\u8fd8\u662f\u590d\u6742\u7684\u7269\u8054\u7f51\u5e94\u7528\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u5e93\uff0c\u5e2e\u52a9\u6211\u4eec\u9ad8\u6548\u5730\u83b7\u53d6\u548c\u5904\u7406\u6e29\u6e7f\u5ea6\u6570\u636e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u901a\u8fc7Python\u8bfb\u53d6\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u7684\u6570\u636e\uff1f<\/strong><br \/>\u8981\u901a\u8fc7Python\u8bfb\u53d6\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\u7684\u6570\u636e\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u7279\u5b9a\u7684\u5e93\u548c\u786c\u4ef6\u63a5\u53e3\u3002\u6bd4\u5982\uff0cDHT11\u548cDHT22\u4f20\u611f\u5668\u53ef\u4ee5\u901a\u8fc7Raspberry Pi\u6216Arduino\u7b49\u5fae\u63a7\u5236\u5668\u83b7\u53d6\u6570\u636e\u3002\u53ef\u4ee5\u4f7f\u7528<code>Adafruit_DHT<\/code>\u5e93\u6765\u7b80\u5316\u6570\u636e\u8bfb\u53d6\u8fc7\u7a0b\u3002\u5b89\u88c5\u5e93\u540e\uff0c\u901a\u8fc7\u6307\u5b9a\u4f20\u611f\u5668\u7c7b\u578b\u548c\u5f15\u811a\u7f16\u53f7\u5373\u53ef\u83b7\u53d6\u6e29\u6e7f\u5ea6\u6570\u636e\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u83b7\u53d6\u6e29\u6e7f\u5ea6\u6570\u636e\u65f6\u9700\u8981\u54ea\u4e9b\u786c\u4ef6\u548c\u8f6f\u4ef6\u652f\u6301\uff1f<\/strong><br \/>\u83b7\u53d6\u6e29\u6e7f\u5ea6\u6570\u636e\u7684\u57fa\u672c\u786c\u4ef6\u5305\u62ec\u6e29\u6e7f\u5ea6\u4f20\u611f\u5668\uff08\u5982DHT11\u6216DHT22\uff09\u3001\u6811\u8393\u6d3e\u6216Arduino\u5f00\u53d1\u677f\uff0c\u4ee5\u53ca\u9762\u5305\u677f\u548c\u8df3\u7ebf\u7b49\u8fde\u63a5\u6750\u6599\u3002\u5728\u8f6f\u4ef6\u65b9\u9762\uff0c\u9700\u8981Python\u73af\u5883\u53ca\u76f8\u5173\u5e93\uff0c\u5982<code>Adafruit_DHT<\/code>\u6216<code>rPi.GPIO<\/code>\u7b49\u3002\u786e\u4fdd\u5b89\u88c5\u4e86\u8fd9\u4e9b\u5e93\u540e\uff0c\u53ef\u4ee5\u987a\u5229\u5730\u8fdb\u884c\u6570\u636e\u8bfb\u53d6\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u83b7\u53d6\u7684\u6e29\u6e7f\u5ea6\u6570\u636e\uff1f<\/strong><br \/>\u83b7\u53d6\u7684\u6e29\u6e7f\u5ea6\u6570\u636e\u901a\u5e38\u4ee5\u6570\u503c\u5f62\u5f0f\u5b58\u5728\u3002\u53ef\u4ee5\u901a\u8fc7Python\u4e2d\u7684\u6570\u636e\u5904\u7406\u5e93\uff08\u5982Pandas\uff09\u8fdb\u884c\u8fdb\u4e00\u6b65\u5206\u6790\u3002\u6bd4\u5982\uff0c\u53ef\u4ee5\u521b\u5efa\u6570\u636e\u6846\u6765\u5b58\u50a8\u5386\u53f2\u8bb0\u5f55\uff0c\u4f7f\u7528Matplotlib\u5e93\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316\uff0c\u6216\u8005\u8bbe\u5b9a\u9608\u503c\u8fdb\u884c\u62a5\u8b66\u3002\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u66f4\u597d\u5730\u7406\u89e3\u548c\u5229\u7528\u73af\u5883\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u83b7\u53d6\u6e29\u6e7f\u5ea6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528\u4f20\u611f\u5668\u6a21\u5757\u3001\u8c03\u7528\u5916\u90e8API\u3001\u4f7f\u7528Raspberry Pi\u548cAr [&hellip;]","protected":false},"author":3,"featured_media":1175924,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175921"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1175921"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175921\/revisions"}],"predecessor-version":[{"id":1175928,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175921\/revisions\/1175928"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1175924"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1175921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1175921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1175921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}