https://blog.csdn.net/qq_34803821/article/details/86238387
1 serial port
Raspberry Pi Code (python): need to install python serial port to read the library file: PIP install pyserial (If you have already installed the then ignored) found Arduino serial port address: / dev / ttyACM0
Arduino Code:
If you run newspaper / x86 or ASCII code can not resolve the error. You can replace all the code in Chinese English, you can not go wrong, probably because they can not recognize Chinese
#include <DHT.h> #define DHTPIN. 3 #define DHTTYPE DHT11 the DHT DHT (DHTPIN, DHTTYPE); void Setup () { // Setup your code here Wallpaper PUT, to RUN Once: Serial.begin (9600); dht.begin (); Serial.println ( "IS running the Arduino Vcancy the Hi ...."); } / ** the Arduino Loop @param none @return none * / char target [] = "the GET TH"; void Loop () { / / wait 2 seconds before each output (here must be greater than 1 second and the like, or inaccurate) Delay (2000); // read the data from the serial port and determines IF (Serial.available ()> 0) { IF (Serial.find (target)) { // Get temperature or humidity needs 250 ms! // acquired sensor temperature and humidity may be 2 seconds float h = dht.readHumidity (); // read the current humidity float t = dht.readTemperature (); // read the current temperature, the unit C a float F = dht.readTemperature (to true); // read the current the temperature in F // quit if fails to read, then read again IF (isNaN (H) || isNaN (t) || isNaN (f)) { Serial.println ( "failed to DHT from the read the Sensor! "); return; } sensible temperature // reading unit F. a float dht.computeHeatIndex HIF = (F, H); sensible temperature // reading unit C a float dht.computeHeatIndex HIC = (T, H, to false); Serial.print ( "humidity:"); Serial.print (H); Serial.print ( "% \ T"); Serial.print ( "temperature:"); Serial.print (T); Serial.print ( " * C "); Serial.print (F ); Serial.print(" *F\t"); Serial.print("体感温度: "); Serial.print(hic); Serial.print(" *C "); Serial.print(hif); Serial.println(" *F"); } } }
2