===== Arduino - Mit dem Dallas DS18B20 die Temperatur messen und auf einem 7 digit 8 segment digital LED display mit dem MAX7219 darstellen=====
**2016/08/**
Ziel: Über OneWire mit dem Dallas [[https://www.maximintegrated.com/en/products/analog/sensors-and-sensor-interface/DS18B20.html|DS18B20]] und dem [[https://www.maximintegrated.com/en/products/analog/sensors-and-sensor-interface/DS18S20.html|DS18S20]] abfragen und die gemessene Temperatur auf einen 7Segment Display mit dem [[https://www.maximintegrated.com/en/products/power/display-power-control/MAX7219.html|MAX7219]] als Treiber Baustein anzeigen.
Bauteile für das Experiment:
* 7 digit 8 segment digital LED display mit dem MAX7219, kaskadierbar (US$2.79)=> http://www.smartarduino.com/view.php?id=94824
* Arduino Uno (orginal) - Heise Verlag (25 Euro) => https://shop.heise.de/make-arduino-special-inkl-arduino-uno
* 2* DS18B20 - von Reichelt (1,85 €) => https://www.reichelt.de/DS-18B20/3/index.html?&ACTION=3&LA=446&ARTICLE=58169&artnr=DS+18B20
* 4,7 K Wiederstand aus der Bastelkiste
* Bread Board + ein paar Steckkabel
* MakerBeam für den Aufbau => www.chartup.com/index.php?cPath=126 , damit das nicht immer so auf den Tisch herumfliegt ... teuer aber praktisch .-)
----
=== Unterschied zwischen den DS18B20 und DS18S20 ===
DS18S20
* Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
* ±0.5°C Accuracy from -10°C to +85°C
* 9-Bit Resolution
DS18B20
* Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
* ±0.5°C Accuracy from -10°C to +85°C
* Programmable Resolution from 9 Bits to 12 Bits
Siehe auch => https://www.maximintegrated.com/en/app-notes/index.mvp/id/4377
----
==== Aufbau====
=== Anschluss der 7 Segment Anzeige MAX72xxx ===
Durch den MAX7219 Chip können mit wenig Verkabelungsaufwand 8 Ziffern dargestellt werden.
5 Anschlussleitung und schon kann es loss gehen:
Modul => Arduino
CLK --------> Pin 11 - Takt
CS --------> Pin 10 - Cip Select
DIN --------> Pin 12 - Data In
GND --------> GND
VCC --------> 5V
Die Library [[http://wayoda.github.io/LedControl/pages/software|"LedControl"]] beschreibt die Programmierung und ist einfach über die Library Funktion in der IDE einbindbar
{{ :elektronik:import_lib_git_ledcontrol.png?400 |LED Control für den MAX72xxx einbinden}}
----
=== Anschluss der beiden Temperatur Sensoren DS18B20 ===
Die Anschlüsse im TO92 Gehäuse:
{{ :elektronik:ds18b20.png?200 |DS18B20 }}
Anschluss mit 3 Leitungen - 1-Wire
{{ :elektronik:ds18b20-anschluss-normal_v01.png | DS18B20 Anschluss mit 3 Leitungen - 1-Wire}}
3 Anschlussleitung und schon kann es loss gehen:
ds18b20 => Arduino
GND --------> GND
DQ --------> Pin 2 - Daten
VDD --------> 5V
Alternativ nur über zwei Leitungen - 1-Wire:
{{ :elektronik:ds18b20-anschluss-parasite_power_mode_v01.png?300 |DS18B20 Parasite Power Mode - Anschluss mit 2 Leitungen }}
ds18b20 => Arduino
GND --------> GND
VDD ____|
DQ --------> Pin 2 - Daten
5V über 4,7K Auf Pin 2
=== Übersicht===
Demnächst mehr .-)
{{ :elektronik:arduino_dallas_temperatur_anzeige_v01.png |arduino dallas temperatur anzeige}}
Wie man sieht ist es gerade Sommer in der Dachgeschosswohung ....
----
==== Sketch====
// Libraries for the Dallas Sensor
#include
#include
//Control the MAX7219
#include "LedControl.h"
//----------------------
//to create int values from the float temperature value
#define N_DECIMAL_POINTS_PRECISION (1000) // n = 3. Three decimal points.
#define TEMPERATURE_PRECISION 12
//----------------------
// Data wire is plugged to pin 2
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//remember the devices for max 5 devices
DeviceAddress term[5];
//----------------------
// add the 7 Segment LED
// pin 12 is connected to the DataIn
// pin 11 is connected to the CLK
// pin 10 is connected to LOAD
// only one MAX72xx Chip
// LedControl(dataPin,clockPin,csPin,numDevices)
LedControl seg71=LedControl(12,11,10,1);
//----------------------
// globals
float tf=0;
int integerPart = 0;
int decimalPart = 0;
//----------------------
void setup() {
// Open serial communications
Serial.begin(57600);
// wait for serial port to connect. Needed for native USB port only
while (!Serial) {
;
}
Serial.println("Start reading temperature");
// Start the Dallas Library
sensors.begin();
// set to asyncron
sensors.setWaitForConversion(false);
//set the resolution
sensors.setResolution(TEMPERATURE_PRECISION);
//Power Mode
Serial.print("Sensors Power Mode :: ");
if ( sensors.isParasitePowerMode() ) {
Serial.println("Parasite Power Mode");
}
else {
Serial.println("Power line connected");
}
//show settings
int deviceCount=sensors.getDeviceCount();
//sensor Count
Serial.print("Sensors :: ");
Serial.print(deviceCount, DEC);
Serial.println(" connected");
//loop over all sensors
for (int i=0;i 999)
return;
if(t<0) {
negative=true;
t=t*-1;
}
tones=t%10;
pones=p%10;
t=t/10;
p=p/10;
ttens=t%10;
ptens=p%10;
t=t/10;
thundreds=t;
p=p/10;
phundreds=p;
if(negative) {
//print character '-' in the leftmost column
seg71.setChar(0,7,'-',false); }
else {
//print a blank in the sign column
seg71.setChar(0,7,' ',false);
}
seg71.setDigit(0,6,(byte)thundreds,false);
seg71.setDigit(0,5,(byte)ttens,false);
seg71.setDigit(0,4,(byte)tones,true);
seg71.setDigit(0,3,(byte)phundreds,false);
seg71.setDigit(0,2,(byte)ptens,false);
seg71.setDigit(0,1,(byte)pones,false);
seg71.setChar(0,0,'C',false);
}
// function to print a device address
// from https://github.com/adafruit/MAX31850_DallasTemp/blob/master/examples/Multiple/Multiple.pde
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++){
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
==== Quellen ====
Dallas DS18B20 und Ardunio
* https://milesburton.com/Dallas_Temperature_Control_Library
* http://www.tweaking4all.com/hardware/arduino/arduino-ds18b20-temperature-sensor/
* http://www.best-microcontroller-projects.com/ds18b20.html
* https://github.com/adafruit/MAX31850_DallasTemp/blob/master/examples/Multiple/Multiple.pde
LED ansteuern
* http://wayoda.github.io/LedControl/pages/software
Sleep Mode:
* http://www.engblaze.com/hush-little-microprocessor-avr-and-arduino-sleep-mode-basics/
1-Wire
* https://www.engineersgarage.com/what-is-the-1-wire-protocol/