Pages: [1]   Go Down
Author Topic: DS 1820 library - help and modification  (Read 673 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear forum,

I'm new to arduino and this is my first topic here.

I have question about dallas 1-wire temperature sensors. I have code where i am reading 4 this DS1820 chips and displaying valuses with time stamps on serial monitor and lcd and also i am logging these data to SD card.
Everithing works OK mainly thanks to all great guys from several forums. Many thanks to them.

My only problem is that when i get temperature from DS1820 it is in format 19.25°C but i need 19,25°C. So i need decimal separator with comma not a dot ! ! !
Is this possible to fix this i my code or library, I need this because the other program I am using to analyze these data. And i trully need t fix this, so please guys hep me  smiley-confuse




Here is the coede:
// libraries
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>

//Connection through I2C
    LiquidCrystal_I2C lcd(0x20,20,4);  // set the LCD address to 0x20 for a 16 chars and 2 line display

// DS18B20 sensors on I/O pin 9
    #define ONE_WIRE_BUS 9
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
    DeviceAddress DS0 = { 0x10, 0x7C, 0xAD, 0x74, 0x02, 0x08, 0x00, 0x5E};
    DeviceAddress N05 = { 0x28, 0x80, 0x02, 0x24, 0x03, 0x00, 0x00, 0xED };
    DeviceAddress N10 = { 0x10, 0x5D, 0xAA, 0x74, 0x02, 0x08, 0x00, 0x8E };
   // DeviceAddress N17 = { 0x10, 0xBB, 0x1B, 0x57, 0x02, 0x08, 0x00, 0x6F };
    DeviceAddress N17 = { 0x10, 0xE2, 0xA5, 0x74, 0x02, 0x08, 0x00, 0xC2 };

//Constants
    long ID = 1;                //Use this to store the id # of our reading.
// RTC??
    RTC_DS1307 RTC; // define the Real Time Clock object
      uint32_t syncTime = 0; // time of last sync()
      const int chipSelect = 10;// for the data logging shield, we use digital pin 10 for the SD cs line
// Logfile ?     

void error(char *str)
{
  Serial.print("Chyba: ");
  Serial.println(str);
  while(1);// lock up if error
}

// main setup
void setup(void)
{
  Serial.begin(9600);
 
    // LCD I2C setup 
        lcd.init();                     // initialize the lcd
        lcd.backlight();                // blacklight of the lcd
        lcd.clear();                    // clear the LCD screen

    // Start up the library
        sensors.begin();
    // set the resolution to 10 bit (good enough?)
        sensors.setResolution(DS0, 12);
        sensors.setResolution(N05, 12);
        sensors.setResolution(N10, 12);
        sensors.setResolution(N17, 12);
 
      // RTC setup
        Wire.begin();
        RTC.begin();

        if (! RTC.isrunning()) {
            Serial.println("RTC is NOT running!");
            // following line sets the RTC to the date & time this sketch was compiled
            RTC.adjust(DateTime(__DATE__, __TIME__));
           }

            Serial.println("ID  Cas        Datum     DS0     N05     N10     N17  ");

       // DS1820 setup
     float TempC = 0;
    }
        void printTemperature(DeviceAddress deviceAddress)
     {
            float tempC = sensors.getTempC(deviceAddress);
            if (tempC == -127.00) {
            Serial.print("XX.X");
            lcd.print("XX.X");
            } else {
                     lcd.print(tempC,2);  // 2 means decimal places

                     Serial.print(tempC,2);  // 2 means decimal places
                     Serial.print(' ');
                   //lcd.print(tempC); 
                   }
                       
            }


void loop(void)
{
   DateTime now;
 
    delay(1000);
   
    // fetch the time
    now = RTC.now();

    Serial.print(ID); // ID na serial
    Serial.print("   ");
   
    //datum ve tvaru 19/02/2013
    if (now.day() < 10) {
     Serial.print("0"); //insert leading zero if day value is less than 10
     Serial.print(now.day(),DEC); //display current day
   }
   else Serial.print(now.day(),DEC); //display current day
    Serial.print('.');
   
     if (now.month() < 10) {
     Serial.print("0"); //insert leading zero if month value is less than 10
     Serial.print(now.month(),DEC); //display current month
   }
   else Serial.print(now.month(),DEC); //display current month
   Serial.print(".");
   
   Serial.print(now.year(), DEC);
   Serial.print(' ');
         
    //cas ve tvaru 09:50:02

    if (now.hour() < 10) {
     Serial.print("0"); //insert leading zero if hour value is less than 10
     Serial.print(now.hour(),DEC); //display current hour
   }
   else Serial.print(now.hour(),DEC); //display current hour
    Serial.print(':');
   
     if (now.minute() < 10) {
     Serial.print("0"); //insert leading zero if minute value is less than 10
     Serial.print(now.minute(),DEC); //display current minute
   }
   else Serial.print(now.minute(),DEC); //display current minute
   Serial.print(":");
   
   if (now.second() < 10) {
     Serial.print("0"); //insert leading zero if seconds value is less than 10
     Serial.print(now.second(),DEC); //display current seconds
   }
   else Serial.print(now.second(),DEC); //display current seconds
 
   
    lcd.clear();

    lcd.setCursor(0, 0);

//datum ve tvaru 19/02/2013
    if (now.day() < 10) {
     lcd.print("0"); //insert leading zero if day value is less than 10
     lcd.print(now.day(),DEC); //display current day
   }
   else lcd.print(now.day(),DEC); //display current day
    lcd.print('.');
   
     if (now.month() < 10) {
     lcd.print("0"); //insert leading zero if month value is less than 10
     lcd.print(now.month(),DEC); //display current month
   }
   else lcd.print(now.month(),DEC); //display current month
   lcd.print(".");
   
   lcd.print(now.year()-2000, DEC);
   lcd.print(' ');
         
         
         
    //cas ve tvaru 09:50:02

    lcd.setCursor(12, 0);


    if (now.hour() < 10) {
     lcd.print("0"); //insert leading zero if hour value is less than 10
     lcd.print(now.hour(),DEC); //display current hour
   }
   else lcd.print(now.hour(),DEC); //display current hour
    lcd.print(':');
   
     if (now.minute() < 10) {
     lcd.print("0"); //insert leading zero if minute value is less than 10
     lcd.print(now.minute(),DEC); //display current minute
   }
   else lcd.print(now.minute(),DEC); //display current minute
   lcd.print(":");
   
   if (now.second() < 10) {
     lcd.print("0"); //insert leading zero if seconds value is less than 10
     lcd.print(now.second(),DEC); //display current seconds
   }
   else lcd.print(now.second(),DEC); //display current seconds
 

 
        // Zde se vypisuje trvání celého záznamu v sekundách
         lcd.setCursor(9,1);        // move cursor to second line "1" and 9 spaces over
         lcd.print("Cas: "); // ID na serial
         lcd.print(millis()/60000);      // display seconds elapsed since power-up
         
       


         lcd.setCursor(0, 1);
         lcd.print("ID: "); // ID na serial
         lcd.print(ID); // ID na serial



    Serial.print(' ');
 // #endif //ECHO_TO_SERIAL
 
      {
      sensors.requestTemperatures();
     
       Serial.print(" ");
    //  delay(prodleva);
      lcd.setCursor(0,2);
      lcd.print("DS0:");
      printTemperature(DS0);
       Serial.print(" ");
      //delay(prodleva);
      lcd.setCursor(10,2);
      lcd.print("N05:");
      printTemperature(N05);
       Serial.print(" ");
      //delay(prodleva);
      lcd.setCursor(0,3);
      lcd.print("N10:");
      printTemperature(N10);
       Serial.print(" ");
     // delay(prodleva);
      lcd.setCursor(10,3);
      lcd.print("N17:");
      printTemperature(N17);
       Serial.print(" ");
       
    }
   
   

   Serial.println();

 //Increment ID number
  ID++;


}


* dsdatalogg.ino (0 KB - downloaded 4 times.)
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like you can "hack" your library files if you wish.  If that's what you do, start by copying the "official" version to the libraries folder in your sketch storage area.  Or you could drop down a level and get the raw data from the chips.  I don't know any thing about the library, never used it so I'd just get the info from the sensor and format it the way I wanted it to look.
Logged

Experience, it's what you get when you were expecting something else.

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't post code without code tags!

What you are looking for is in the Print.cpp file (hardware/arduino/cores/arduino/Print.cpp) at line 255:
Code:
    n += print(".");

change that to

Code:
    n += print(",");

and all your float get a comma instead of the decimal point.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

WOW

Thanks a lot pylon, that is the solution which i needed :-)
Thanks a lot again  smiley
Logged

Pages: [1]   Go Up
Jump to: