Close

Odpověď na: DS18B20 – LCD, vypsani adresy

Úvodní stránka Fórum Hardware Senzory DS18B20 – LCD, vypsani adresy Odpověď na: DS18B20 – LCD, vypsani adresy

#9133
Kaniiisek
Účastník

Ano zkoušel, zatím mám tohle:

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 8
OneWire  ds(8);
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

void setup(void)
{
  // set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("DS18B20 adress:");
  
  
  // Start up the library
  sensors.begin();
}

void getDeviceAddress(void) {
  byte i;
  byte addr[8];

while(ds.search(addr)) {
   lcd.setCursor(0, 1);
 
    
    for( i = 0; i < 8; i++) {
      lcd.print("0x");
      if (addr[i] < 16) {
        lcd.print('0');
      }
      // print each byte in the address array in hex format
      lcd.print(addr[i], HEX);
      if (i < 7) {
        lcd.print(", ");
      }
    }
    // a check to make sure that what we read is correct.
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        lcd.print("CRC is not valid!\n");
        return;
    }
  }
  ds.reset_search();
  return;
}

void loop(void)
{ 

}
  /*
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  sensors.requestTemperatures(); // Send the command to get temperatures
    // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);

  lcd.print(sensors.getTempFByIndex(0)); 
  lcd.print((char)223);
  lcd.print("F  ");
   
  lcd.print(sensors.getTempCByIndex(0));
  lcd.print((char)223); 
  lcd.print("C");
  
  delay(500);
}
  */