Benutzer-Werkzeuge

Webseiten-Werkzeuge


elektronik:arduino_dallas_max72xx_temperature_messung

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 DS18B20 und dem DS18S20 abfragen und die gemessene Temperatur auf einen 7Segment Display mit dem MAX7219 als Treiber Baustein anzeigen.

Bauteile für das Experiment:


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 "LedControl" beschreibt die Programmierung und ist einfach über die Library Funktion in der IDE einbindbar

LED Control für den MAX72xxx einbinden


Anschluss der beiden Temperatur Sensoren DS18B20

Die Anschlüsse im TO92 Gehäuse:

DS18B20

Anschluss mit 3 Leitungen - 1-Wire

 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:

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 .-)

arduino dallas temperatur anzeige

Wie man sieht ist es gerade Sommer in der Dachgeschosswohung ….


Sketch

temp.ino
// Libraries for the Dallas Sensor
#include <OneWire.h>
#include <DallasTemperature.h>
//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<deviceCount;i++) {
 
   Serial.print("Sensor Device :: ");
   Serial.print(i);
   Serial.println();
 
    // get the adress of the sensor
    if (!sensors.getAddress(term[i], i)) {
        Serial.print("Unable to find address for Device");
        Serial.println(i,DEC);
    } 
    else {
       Serial.print("Sensor Device ");
       Serial.print(i,DEC);
       Serial.print(" Address is     :: ");
       printAddress(term[i]);
       Serial.println();
    }
 
    //uint8_t* deviceAddress;
    //Serial.println(sensors.getAddress(deviceAddress, 1),HEX);
 
     Serial.print(" +Resolution Byte :: ");
     Serial.println(sensors.getResolution(term[i]),DEC);
     Serial.print(" +getLowAlarmTemp :: ");
     Serial.println(sensors.getLowAlarmTemp(term[i]),DEC);
     Serial.print(" +HighAlarmTemp   :: ");
     Serial.println(sensors.getHighAlarmTemp(term[i]),DEC);
     Serial.println("-----------------------");       
  }
 
 
  //The MAX72XX is in power-saving mode on startup,
  //we have to do a wakeup call
  seg71.shutdown(0,false);  
  //Set the brightness to a medium values
  seg71.setIntensity(0,8);
  //clear the display
  seg71.clearDisplay(0);
 
}
 
 
void loop() {  
 
  Serial.println("Read tempertaur ---------------");
  sensors.requestTemperatures(); // Send the command to get temperatures
 
  //progress dots
  printProgress(30);
 
  int deviceCount=sensors.getDeviceCount();
  //loop over all sensors
  for (int i=0;i<deviceCount;i++) {
    // read the first sensor on the bus
    //tf =sensors.getTempCByIndex(i);
    tf =sensors.getTempC(term[i]);
    integerPart = (int)tf;
    decimalPart = ((int)(tf*N_DECIMAL_POINTS_PRECISION)%N_DECIMAL_POINTS_PRECISION);
 
    Serial.print("Sensor Device temperature ");
    Serial.print(i);
    Serial.print(" :: ");
    Serial.println(tf,4);
 
    //write to 7Segment
    seg71.clearDisplay(0);
    printDigit(integerPart,decimalPart);
    delay(3000);
  } 
}
 
//progress dots
void printProgress(int t){
   //progress dot's 
   seg71.clearDisplay(0);
  for (int i=0;i<9;i++){
    seg71.setChar(0,i,'.',false);
    delay(t);
  }
}
 
//print digits
void printDigit(int t,int p) {  
    int tones;  
    int ttens;  
    int thundreds; 
 
    int pones;  
    int ptens;  
    int phundreds; 
 
    boolean negative=false;
 
    if(t < -999 || t > 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

Diese Website verwendet Cookies. Durch die Nutzung der Website stimmen Sie dem Speichern von Cookies auf Ihrem Computer zu. Außerdem bestätigen Sie, dass Sie unsere Datenschutzbestimmungen gelesen und verstanden haben. Wenn Sie nicht einverstanden sind, verlassen Sie die Website.Weitere Information
elektronik/arduino_dallas_max72xx_temperature_messung.txt · Zuletzt geändert: 2022/07/29 20:58 von gpipperr