DS18B20 w Arduino IDE

cino111
Posty: 714
Rejestracja: pn maja 07, 2018 8:00 pm

Witam
Walczę o d kilku/kilkunastu dni z czujnikami temperatury DS18B20. Mam ich 10 szt gdyż chcę nimi mierzyć temperaturę przy piecu: Piec, wyjście na grzejniki, powrót, wyjście na bojler, powrót, podłogówka itp. itd. Mam jednak problem z wyświetlaniem temperatury, a mianowicie przy wgraniu programu czy do NodeMcu, czy do Arduino Mega temperatura sie nie pokazuje. Dopiero po odcięciu zasilania do czujnika "zaskakuje pomiar" i po ponownym podłączeniu zasilania już jest ok. Co może być tego przyczyną. Nie chcę biegać do Arduino za każdym zanikiem napięcia w sieci. Może nowa wersja Clouda coś nie tak współgra z Arduino?
Dla Arduino Mega pokazuje cały czas 5 stopni a dla NodeMcu nic. :cry:
Bardzo mało jest informacji na temat programowania przez ArduinoIDE - Może ktoś obcykany by zrobił jakiegoś tutoriala? :mrgreen:


Moj program z Arduino Mega

Kod: Zaznacz cały

/*
Copyright (C) AC SOFTWARE SP. Z O.O.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SuplaDevice.h>

/*
 * This example requires Dallas Temperature Control library installed. 
 * https://github.com/milesburton/Arduino-Temperature-Control-Library
 */

 
// Setup a oneWire instance
OneWire oneWire(24); // 24 - Pin number

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


// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {

    double t = -275;
    
    if ( sensors.getDeviceCount() > 0 )
      {
         sensors.requestTemperatures();
         t = sensors.getTempCByIndex(0);
      };

    return t;  
}

void setup() {

  Serial.begin(9600);

  // Init DS18B20 library 
  sensors.begin();
  
  // Set temperature callback
  SuplaDevice.setTemperatureCallback(&get_temperature);
 
  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {0x2F,0xF9,0xF2,0x22,0x97,0xC7,0xD7,0x7E,0xE6,0xF1,0x95,0x93,0xCF,0xA9,0x7D,0x71};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid


  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x01, 0x02, 0x04, 0x03, 0x05};

  /*
   * Having your device already registered at cloud.supla.org,
   * you want to change CHANNEL sequence or remove any of them,
   * then you must also remove the device itself from cloud.supla.org.
   * Otherwise you will get "Channel conflict!" error.
   */
    
  // CHANNEL0 - RELAY
  SuplaDevice.addRelay(44, true);           // 44 - Pin number where the relay is connected      
                                      // Call SuplaDevice.addRelay(44, true) with an extra "true" parameter 
                                      // to enable "port value inversion"
                                      // where HIGH == LOW, and LOW == HIGH   

  // CHANNEL1 - RELAY
  SuplaDevice.addRelay(45, true);           // 45 - Pin number where the relay is connected   

  // CHANNEL3 - TWO RELAYS (Roller shutter operation)
  SuplaDevice.addRelay(46, true);           // 46 - Pin number where the relay is connected  

  // CHANNEL4 - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(A0); // A0 - Pin number where the sensor is connected
                               // Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
                               // to enable the internal pull-up resistor


  // CHANNEL5 - Opening sensor (Normal Open)
  SuplaDevice.addSensorNO(A1); // A1 - Pin number where the sensor is connected


  // CHANNEL6 - Thermometer DS18B20
  SuplaDevice.addDS18B20Thermometer();


  /*
   * SuplaDevice Initialization.
   * Server address, LocationID and LocationPassword are available at https://cloud.supla.org 
   * If you do not have an account, you can create it at https://cloud.supla.org/account/create
   * SUPLA and SUPLA CLOUD are free of charge
   * 
   */

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "svr.supla.org",  // SUPLA server address
                    ,                 // Location ID 
                    " ");               // Location Password
    
}

void loop() {
  SuplaDevice.iterate();
}
Awatar użytkownika
shimano73
Posty: 1976
Rejestracja: ndz lut 28, 2016 12:27 pm
Lokalizacja: Orzesze
Kontakt:

Brakuje obsługi wielu czujników , masz zadeklarowany tylko jeden .
Chcesz obsługiwać 10 czujników musisz wpisać 10 razy instrukcje i zmodyfikować metodę get_temperature dla odczytu z różnych kanałów
W elektronice jak nie wiadomo o co chodzi to zwykle chodzi o zasilanie

Wezmę udział w Supla Offline Party 2024 :)
cino111
Posty: 714
Rejestracja: pn maja 07, 2018 8:00 pm

shimano73 pisze: sob cze 09, 2018 2:55 pm Brakuje obsługi wielu czujników , masz zadeklarowany tylko jeden .
Chcesz obsługiwać 10 czujników musisz wpisać 10 razy instrukcje i zmodyfikować metodę get_temperature dla odczytu z różnych kanałów
Wiem, wiem. Problem mam nawet z jednym, więc narazie nie rozbudowuję.
cino111
Posty: 714
Rejestracja: pn maja 07, 2018 8:00 pm

A może tu jest jakaś wskazówka?

Pokazują się takie komunikaty jak niżej, ale program się wgrywa i sterowanie bramami działa.

Kod: Zaznacz cały

In file included from C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:21:0:

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice/SuplaDevice.h:108:1: warning: 'typedef' was ignored in this declaration

 };

 ^

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice/SuplaDevice.h:116:1: warning: 'typedef' was ignored in this declaration

 };

 ^

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice/SuplaDevice.h:124:1: warning: 'typedef' was ignored in this declaration

 };

 ^

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice/SuplaDevice.h:156:1: warning: 'typedef' was ignored in this declaration

 };

 ^

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino: In function 'void setup()':

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '249' from 'int' to 'char' inside { } [-Wnarrowing]

   char GUID[SUPLA_GUID_SIZE] = {0x2F,0xF9,0xF2,0x22,0x97,0xC7,0xD7,0x7E,0xE6,0xF1,0x95,0x93,0xCF,0xA9,0x7D,0x71};

                                                                                                                ^

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '242' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '151' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '199' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '215' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '230' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '241' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '149' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '147' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '207' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\Mega_temperatura_i_przekazniki\Mega_temperatura_i_przekazniki.ino:61:112: warning: narrowing conversion of '169' from 'int' to 'char' inside { } [-Wnarrowing]

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice\SuplaDevice.cpp: In function 'float2DoublePacked.constprop':

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice\SuplaDevice.cpp:76:29: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations]

             bar[i] = dbl.b[i];

                             ^

C:\Users\01005603\Documents\Arduino\libraries\SuplaDevice\SuplaDevice.cpp:74:9: note: containing loop

         for (int i=0; i<8; i++)

         ^

Szkic używa 34448 bajtów (13%) pamięci programu. Maksimum to 253952 bajtów.
Zmienne globalne używają 2523 bajtów (30%) pamięci dynamicznej, pozostawiając 5669 bajtów dla zmiennych lokalnych. Maksimum to 8192 bajtów.
Awatar użytkownika
wojtas567
Posty: 2214
Rejestracja: ndz kwie 03, 2016 7:16 pm
Lokalizacja: Olsztyn

Czy jest górna granica temperatury?
Mam jeszcze jedno pytanie w odległości na chmurze pokazuje mi wartości ujemne ale w aplikacji już nie.
Przemku gdzieś jest ograniczenie?
Pozdrawiam
Wojtek
Awatar użytkownika
pzygmunt
Posty: 18335
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

Temperatury z zakresu
>= -273
<= 1000

uznawane są za dopuszczalne
Awatar użytkownika
wojtas567
Posty: 2214
Rejestracja: ndz kwie 03, 2016 7:16 pm
Lokalizacja: Olsztyn

Kurczę, nie dużo brakuje ale ciśnienie się nie załapie.
A można to gdzieś w bibliotece zwiększyć?
Pozdrawiam
Wojtek
Awatar użytkownika
pzygmunt
Posty: 18335
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

wojtas567 pisze: pt lip 06, 2018 1:25 pm Kurczę, nie dużo brakuje ale ciśnienie się nie załapie.
A można to gdzieś w bibliotece zwiększyć?
To wycina serwer
tgaweda
Posty: 91
Rejestracja: pn lis 13, 2017 9:21 pm

pzygmunt pisze: pt lip 06, 2018 1:57 pm To wycina serwer
Kiedyś mówiłeś coś o specjalnym kanale pogodowym...
Awatar użytkownika
pzygmunt
Posty: 18335
Rejestracja: wt sty 19, 2016 9:26 am
Lokalizacja: Paczków
Kontakt:

Tak. Nadal jest przewidziany. Póki co sugeruję zrobić jakiś dzielnik albo użyć kanału czujnika wysokości/odległości.
ODPOWIEDZ

Wróć do „Pomoc”