KY-001 Temperatur Sensor Modul: Unterschied zwischen den Versionen
Aus Linkerkit.de
Zeile 7: | Zeile 7: | ||
==Pin-Belegung== | ==Pin-Belegung== | ||
[[Datei:3_S_V_G.png|none]] | [[Datei:3_S_V_G.png|none]] | ||
+ | |||
==Codebeispiel Arduino== | ==Codebeispiel Arduino== | ||
− | <pre class="brush:cpp"># Include | + | Das Programm |
+ | |||
+ | <pre class="brush:cpp"> | ||
+ | # Include | ||
OneWire ds (10); / / on pin 10 | OneWire ds (10); / / on pin 10 | ||
void setup (void) { | void setup (void) { | ||
Zeile 42: | Zeile 46: | ||
ds.reset (); | ds.reset (); | ||
} | } | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | '''Anschlussbelegung Arduino:''' | ||
+ | |||
+ | {| style="height: 58px; padding-left: 30px;" width="228" | ||
+ | |- | ||
+ | ||LED + | ||
+ | ||= | ||
+ | ||[Pin 13] | ||
+ | |- | ||
+ | ||LED - | ||
+ | ||= | ||
+ | ||[Pin GND] | ||
+ | |- | ||
+ | ||Sensor Signal | ||
+ | ||= | ||
+ | ||[Pin 10] | ||
+ | |- | ||
+ | ||Sensor +V | ||
+ | ||= | ||
+ | ||[Pin 5V] | ||
+ | |- | ||
+ | ||Sensor - | ||
+ | ||= | ||
+ | ||[Pin GND] | ||
+ | |} | ||
+ | |||
+ | '''Beispielprogramm Download''' | ||
+ | |||
+ | [[Medium:SensorTest_Arduino.zip|SensorTest_Arduino.zip]] | ||
+ | |||
+ | ==Codebeispiel Raspberry Pi== | ||
+ | Programmierbeispiel in der Programmiersprache Python | ||
+ | |||
+ | <pre class="brush:py"># Benoetigte Module werden importiert und eingerichtet | ||
+ | import RPi.GPIO as GPIO | ||
+ | import time | ||
+ | |||
+ | GPIO.setmode(GPIO.BCM) | ||
+ | |||
+ | # Hier wird der Eingangs-Pin deklariert, an dem der Sensor angeschlossen ist. Zusaetzlich wird auch der PullUP Widerstand am Eingang aktiviert | ||
+ | GPIO_PIN = 24 | ||
+ | GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP) | ||
+ | |||
+ | print "Sensor-Test [druecken Sie STRG+C, um den Test zu beenden]" | ||
+ | |||
+ | # Diese AusgabeFunktion wird bei Signaldetektion ausgefuehrt | ||
+ | def ausgabeFunktion(null): | ||
+ | print("Signal erkannt") | ||
+ | |||
+ | # Beim Detektieren eines Signals (fallende Signalflanke) wird die Ausgabefunktion ausgeloest | ||
+ | GPIO.add_event_detect(GPIO_PIN, GPIO.FALLING, callback=ausgabeFunktion, bouncetime=100) | ||
+ | |||
+ | # Hauptprogrammschleife | ||
+ | try: | ||
+ | while True: | ||
+ | time.sleep(1) | ||
+ | |||
+ | # Aufraeumarbeiten nachdem das Programm beendet wurde | ||
+ | except KeyboardInterrupt: | ||
+ | GPIO.cleanup() | ||
+ | |||
+ | </pre> | ||
+ | '''Anschlussbelegung Raspberry Pi:''' | ||
+ | |||
+ | {| style="height: 58px; padding-left: 30px;" width="228" | ||
+ | |- | ||
+ | ||Signal | ||
+ | ||= | ||
+ | ||GPIO24 | ||
+ | ||[Pin 18] | ||
+ | |- | ||
+ | ||+V | ||
+ | ||= | ||
+ | ||3,3V | ||
+ | ||[Pin 1] | ||
+ | |- | ||
+ | ||GND | ||
+ | ||= | ||
+ | ||Masse | ||
+ | ||[Pin 6] | ||
+ | |} | ||
+ | |||
+ | '''Beispielprogramm Download''' | ||
+ | |||
+ | [[Medium:SensorTest_RPi.zip|SensorTest_RPi.zip]] | ||
+ | |||
+ | Zu starten mit dem Befehl: | ||
+ | |||
+ | <pre class="brush:bash">sudo python SensorTest_RPi.py | ||
</pre> | </pre> |
Version vom 8. April 2016, 17:24 Uhr
Inhaltsverzeichnis
Bild
Technische Daten / Kurzbeschreibung
Chipsatz: DS18B20 | Kommunikationsprotokoll: 1-Wire
9- 12Bit genaue Temperaturmessung im Meßbereich von –55°C bis +125°C
Pin-Belegung
Codebeispiel Arduino
Das Programm
# Include OneWire ds (10); / / on pin 10 void setup (void) { // Initialize inputs / outputs // Start serial port Serial.begin (9600); } void loop (void) { byte i; byte present = 0; byte data [12]; byte addr [8]; int Temp; if (! ds.search (addr)) { // Serial.print ("No more addresses."); ds.reset_search (); return; } Serial.print ("R ="); // R = 28 Not sure what this is for (i = 0; i <8; i ) { Serial.print (addr [i], HEX); Serial.print (""); } if (OneWire :: crc8 (addr, 7)! = addr [7]) { Serial.print ("CRC is not valid!"); return; } if (addr [0]! = 0x28) { Serial.print ("Device is not a DS18S20 family device."); return; } ds.reset (); }
Anschlussbelegung Arduino:
LED + | = | [Pin 13] |
LED - | = | [Pin GND] |
Sensor Signal | = | [Pin 10] |
Sensor +V | = | [Pin 5V] |
Sensor - | = | [Pin GND] |
Beispielprogramm Download
Codebeispiel Raspberry Pi
Programmierbeispiel in der Programmiersprache Python
# Benoetigte Module werden importiert und eingerichtet import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # Hier wird der Eingangs-Pin deklariert, an dem der Sensor angeschlossen ist. Zusaetzlich wird auch der PullUP Widerstand am Eingang aktiviert GPIO_PIN = 24 GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP) print "Sensor-Test [druecken Sie STRG+C, um den Test zu beenden]" # Diese AusgabeFunktion wird bei Signaldetektion ausgefuehrt def ausgabeFunktion(null): print("Signal erkannt") # Beim Detektieren eines Signals (fallende Signalflanke) wird die Ausgabefunktion ausgeloest GPIO.add_event_detect(GPIO_PIN, GPIO.FALLING, callback=ausgabeFunktion, bouncetime=100) # Hauptprogrammschleife try: while True: time.sleep(1) # Aufraeumarbeiten nachdem das Programm beendet wurde except KeyboardInterrupt: GPIO.cleanup()
Anschlussbelegung Raspberry Pi:
Signal | = | GPIO24 | [Pin 18] |
+V | = | 3,3V | [Pin 1] |
GND | = | Masse | [Pin 6] |
Beispielprogramm Download
Zu starten mit dem Befehl:
sudo python SensorTest_RPi.py