dcexpert 发表于 2019-12-24 21:09

用ESP8266读取SHT3x

<p>社区正在进行SHT31开发板的活动,正好在网上看到一个SHT3x(应该和SHT31兼容)的帖子,顺便就分享给大家。</p>

<p>&nbsp;</p>

<p>原文:<a href="https://www.hackster.io/BuiHao96/control-led-and-sht3x-via-blynk-0740b9">https://www.hackster.io/BuiHao96/control-led-and-sht3x-via-blynk-0740b9</a></p>

<p>&nbsp;</p>

<p><img alt="Control Led and SHT3x via Blynk" src="https://hackster.imgix.net/uploads/attachments/1042963/_bO6lV9458S.blob?auto=compress%2Cformat&amp;w=900&amp;h=675&amp;fit=min" /></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p></p>

<p>&nbsp;</p>

<p>单片机程序是使用arduino开发的</p>

<p>&nbsp;</p>

<pre>
<code class="language-cpp">// Robo India Tutorial
// Digital Output on LED
// Hardware: NodeMCU Blynk Board


#define BLYNK_PRINT Serial

#include &lt;ESP8266WiFi.h&gt;
#include &lt;BlynkSimpleEsp8266.h&gt;
#include &lt;SimpleTimer.h&gt;
#include &lt;Arduino.h&gt;
#include &lt;Wire.h&gt;
#include "Adafruit_SHT31.h"
Adafruit_SHT31 sht31 = Adafruit_SHT31();
SimpleTimer timer;
char auth[] = "YourAuthToken";            // You should get Auth Token in the Blynk App.
char ssid[] = "YourNetworkName";    // Your WiFi credentials.
char pass[] = "YourPassword";// Set password to "" for open networks.
void setup()
{
    Serial.begin(9600);// Debug console
    Blynk.begin(auth, ssid, pass);
      if (! sht31.begin(0x44))
      {   // Set to 0x45 for alternate i2c addr
    Serial.println("Couldn't find SHT31");
    while (1) delay(1);
   }
    timer.setInterval(2000, sendUptime);
}
void sendUptime()
{
    float t = sht31.readTemperature();
    float h = sht31.readHumidity();
   //Serial.print("Temp *C = "); Serial.println(t);
   //Serial.print("Hum. % = "); Serial.println(h);
    Blynk.virtualWrite(V0, t);
    Blynk.virtualWrite(V1, h);
}

void loop()
{
Blynk.run();
timer.run();
}</code></pre>

<p>&nbsp;</p>

caizhiwei 发表于 2020-1-1 09:13

<p>效果如何?</p>

dcexpert 发表于 2020-1-1 12:26

caizhiwei 发表于 2020-1-1 09:13
效果如何?

<p>没有板子不能试,发出来给大家参考一下</p>
页: [1]
查看完整版本: 用ESP8266读取SHT3x