veranstaltungen:hessen20162:arduino-workshop-notizen

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
veranstaltungen:hessen20162:arduino-workshop-notizen [04.10.2016 10:51] – [Arduino Sketch (Programm):] ipsecguyveranstaltungen:hessen20162:arduino-workshop-notizen [04.10.2016 11:01] (aktuell) – [Arduino Sketch (Programm):] ipsecguy
Zeile 49: Zeile 49:
  
 <file text arduino-freifunk.ino> <file text arduino-freifunk.ino>
 +#include <OneWire.h> 
 OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary)  OneWire  ds(10);  // on pin 10 (a 4.7K resistor is necessary) 
 +
 +#include "DHT.h" 
 +#define DHTPIN 2     // what digital pin we're connected to 
 +#define DHTTYPE DHT11   // DHT 11 
 +//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321 
 +//#define DHTTYPE DHT21   // DHT 21 (AM2301) 
 +DHT dht(DHTPIN, DHTTYPE); 
 +
 +bool running = false; 
 +
 +void setup(void) { 
 +  pinMode(13, OUTPUT); 
 +  digitalWrite(13, HIGH); 
 +  Serial.begin(9600); 
 +  Serial.setTimeout(1000); 
 +  dht.begin(); 
 +  digitalWrite(13, LOW); 
 +
 +
 +void loop(void) { 
 +  byte i; 
 +  byte present = 0; 
 +  byte type_s; 
 +  byte data[12]; 
 +  byte addr[8]; 
 +  float celsius, fahrenheit; 
 +  float h,t; 
 +
 +  if( !running ){ 
 +    digitalWrite(13, LOW); 
 +    Serial.flush(); //flush all previous received and transmitted data 
 +    while(!Serial.available()){ 
 +      delay(500); 
 +    } 
 +    digitalWrite(13, HIGH); 
 +
 +    Serial.readString(); 
 +    Serial.flush(); //flush all previous received and transmitted data 
 +
 +    running = true; // start execution 
 +  } 
 +
 +if ( !ds.search(addr)) { 
 +    ds.reset_search(); 
 +
 +    //DHT11 Code 
 +    h = dht.readHumidity(); 
 +    t = dht.readTemperature(); 
 +    if (!isnan(h) && !isnan(t)) { 
 +      Serial.print("DHT "); 
 +      Serial.print(t); 
 +      Serial.print(" "); 
 +      Serial.println(h); 
 +    } 
 +    Serial.println("EOF"); 
 +
 +    running = false; // done with this cycle, wait again 
 +    return; 
 +  } 
 +
 +  if (OneWire::crc8(addr, 7) != addr[7]) { 
 +      Serial.println("CRC is not valid!"); 
 +      return; 
 +  }
 +  
 +  // the first ROM byte indicates which chip 
 +  switch (addr[0]) { 
 +    case 0x10: 
 +//      Serial.println("  Chip = DS18S20");  // or old DS1820 
 +      type_s = 1; 
 +      break; 
 +    case 0x28: 
 +//      Serial.println("  Chip = DS18B20"); 
 +      type_s = 0; 
 +      break; 
 +    case 0x22: 
 +//      Serial.println("  Chip = DS1822"); 
 +      type_s = 0; 
 +      break; 
 +    default: 
 +//      Serial.println("Device is not a DS18x20 family device."); 
 +      return; 
 +  }
 +  
 +  ds.reset(); 
 +  ds.select(addr); 
 +  ds.write(0x44, 1); // start conversion, without parasite power 
 + Serial.println(celsius); 
 +
 +
 </file> </file>
  
  • veranstaltungen/hessen20162/arduino-workshop-notizen.1475578278.txt.gz
  • Zuletzt geändert: 04.10.2016 10:51
  • von ipsecguy