ESP-01, DS18B20, Arduino IDE

Awatar użytkownika
Goral64
Posty: 3131
Rejestracja: pt gru 27, 2019 6:22 pm
Lokalizacja: Żerniki Wrocławskie
Kontakt:

Moje podstawowe pytanie to ile można podpiąć czujników w trybie OneWire do GPIO2, żeby wszystko działało?
Ile czujników obsłuży Supla?
Czy korzystanie z Arduino IDE w jakiś sposób wpływa na tę ilość?

A teraz problem.

Gdy podłącze 1, góra 2 czujniki program zachowuje się normalnie. Wszystko chodzi.
Gdy podłączę ich więcej 3 czy 5 (a chcę podłączyć 21), program wariuje...
Co chwilę pojawia się Soft WDT Reset lub Exception(0) albo Exception(29) i tak w kółko.

Układ na razie jest na płytce stykowej i zasilany jest z zasilacza laboratoryjnego napięciem 3.3V (pobiera od 6mA do 10mA).

Programik jest prościutki, na razie tylko testuję sobie te czujniki.

Kod: Zaznacz cały

/**
 * Supla.org NodeMCU WiFi minimal example
 * Author: Programistyk - Kamil Kaminski <kamil@programistyk.pl>
 * 
 * This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
 */
#include <OneWire.h>
#include <DallasTemperature.h>

#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>

OneWire oneWire(2);
DallasTemperature sensors(&oneWire);
WiFiClient client;

// Setup Supla connection
const char* ssid     = "XXXXXXXX";
const char* password = "********";

// DS18B20 Sensor read implementation
double get_temperature(int channelNumber, double last_val) {
    double t = -275;
    if ( sensors.getDeviceCount() > 0 )
      {
         sensors.requestTemperatures();
         t = sensors.getTempCByIndex(channelNumber);
      };
    return t;  
}

void setup() {
  Serial.begin(74880);
  delay(10);

  // Replace the falowing GUID
  char GUID[SUPLA_GUID_SIZE] = {0xF1,0x9B,0x71,0xC3,0x1C,0xD2,0x4C,0xD7,0x71,0x2E,0x1C,0x01,0xCB,0x19,0x9C,0x80};
  // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid

  // Ethernet MAC address
  uint8_t mac[6] = {0x3c, 0xf4, 0x31, 0x14, 0xfb, 0x17};

  /*
   * 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.
   */
   // Init DS18B20 library
  sensors.begin();
  
  // CHANNEL0 - RELAY
  //SuplaDevice.addRelay(2, 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.addRollerShutterRelays(46,     // 46 - Pin number where the 1st relay is connected   
//                                     47, true);    // 47 - Pin number where the 2nd relay is connected  

    SuplaDevice.addDS18B20Thermometer();

    SuplaDevice.addDS18B20Thermometer();
    SuplaDevice.addDS18B20Thermometer();
    SuplaDevice.addDS18B20Thermometer();
    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
    
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();

//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();

//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
//    SuplaDevice.addDS18B20Thermometer();
// 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(2); // 2 - Pin number where the sensor is connected


  // CHANNEL6 - DHT22 Sensor
  // SuplaDevice.addDHT11();
  // SuplaDevice.addAM2302();
  // SuplaDevice.addDHT22();

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

}

void loop() {
  SuplaDevice.iterate();
}

// Supla.org ethernet layer
    int supla_arduino_tcp_read(void *buf, int count) {
        _supla_int_t size = client.available();
       
        if ( size > 0 ) {
            if ( size > count ) size = count;
            return client.read((uint8_t *)buf, size);
        };
    
        return -1;
    };
    
    int supla_arduino_tcp_write(void *buf, int count) {
        return client.write((const uint8_t *)buf, count);
    };
    
    bool supla_arduino_svr_connect(const char *server, int port) {
          return client.connect(server, 2015);
    }
    
    bool supla_arduino_svr_connected(void) {
          return client.connected();
    }
    
    void supla_arduino_svr_disconnect(void) {
         client.stop();
    }
    
    void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

        Serial.println("WiFi init");
        WiFi.begin(ssid, password);

        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
        }

        Serial.print("\nlocalIP: ");
        Serial.println(WiFi.localIP());
        Serial.print("subnetMask: ");
        Serial.println(WiFi.subnetMask());
        Serial.print("gatewayIP: ");
        Serial.println(WiFi.gatewayIP());
    }

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
          SuplaDeviceCallbacks cb;
          
          cb.tcp_read = &supla_arduino_tcp_read;
          cb.tcp_write = &supla_arduino_tcp_write;
          cb.eth_setup = &supla_arduino_eth_setup;
          cb.svr_connected = &supla_arduino_svr_connected;
          cb.svr_connect = &supla_arduino_svr_connect;
          cb.svr_disconnect = &supla_arduino_svr_disconnect;
          cb.get_temperature = &get_temperature;
          cb.get_temperature_and_humidity = NULL;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          
          return cb;
}
Restart następuje w dowolnym miejscu poniżej zaznaczonego <<<<<<<

Kod: Zaznacz cały

15:18:30.314 -> localIP: 172.16.144.100
15:18:30.314 -> subnetMask: 255.255.255.0
15:18:30.348 -> gatewayIP: 172.16.144.1 <<<<<<<
15:18:32.606 -> SuplaDevice initialized
15:18:32.606 -> Not connected
15:18:32.641 -> Register in progress
15:18:32.641 -> Registered and ready.
15:18:33.187 -> Value changed
15:18:33.732 -> Value changed
15:18:34.282 -> Value changed
15:18:34.420 -> 
15:18:34.420 -> Soft WDT reset
15:18:34.420 -> 
15:18:34.420 -> >>>stack>>>
15:18:34.420 -> 
15:18:34.420 -> ctx: cont
No i ciekawy jestem co może być nie tak?
Widzimy się na Supla Offline Party Season 2 :D

Obrazek
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

Spróbuj użyć tej wersji biblioteki: https://github.com/klew/arduino

Jest tam przykład na 4 DS-y. Można dodać "dowolną" ilość. Od strony oprogramowania nie ma problemów z 20-30 czujnikami.
Od storny HW (czyli ile zasilanie uciągnie, jakie rezystory, zasilacze itp) to nie pomogę ;)

Jeśli nie znasz adresów DS-ów, to uruchom program z biblioteki z jednym DS-em (może być bez adresu) i program na starcie wyświetli adresy wszystkich znaleziony urządzeń.
Widzimy się na Supla Offline Party vol. 2 :!:
Awatar użytkownika
Goral64
Posty: 3131
Rejestracja: pt gru 27, 2019 6:22 pm
Lokalizacja: Żerniki Wrocławskie
Kontakt:

Dzięki @klew w wolnej chwili sprawdzę to.

Na razie sprawdziłem na 3 innych ESP-01 i mam to samo restartowanie.
Widzimy się na Supla Offline Party Season 2 :D

Obrazek
Awatar użytkownika
Goral64
Posty: 3131
Rejestracja: pt gru 27, 2019 6:22 pm
Lokalizacja: Żerniki Wrocławskie
Kontakt:

OK, z nową biblioteką jest lepiej, ale pojawia się ograniczenie po stronie OneWire (chyba) do 16 czujników.

Kod: Zaznacz cały

Creating OneWire bus for pin: 2
Initializing OneWire bus at pin 2
OneWire(pin 2) Parasite power is OFF
OneWire(pin 2) Found 21 devices:
Index 0 - address {0x28, 0x80, 0xD2, 0x16, 0xA8, 0x01, 0x3C, 0x12}
Index 1 - address {0x28, 0x18, 0x96, 0x16, 0xA8, 0x01, 0x3C, 0xF4}
Index 2 - address {0x28, 0x84, 0xB9, 0x16, 0xA8, 0x01, 0x3C, 0xAF}
Index 3 - address {0x28, 0x1C, 0x95, 0x16, 0xA8, 0x01, 0x3C, 0x66}
Index 4 - address {0x28, 0xFC, 0x8B, 0x16, 0xA8, 0x01, 0x3C, 0x91}
Index 5 - address {0x28, 0x32, 0x74, 0x79, 0x97, 0x05, 0x03, 0x9B}
Index 6 - address {0x28, 0x96, 0xDD, 0x16, 0xA8, 0x01, 0x3C, 0x94}
Index 7 - address {0x28, 0x56, 0x04, 0x16, 0xA8, 0x01, 0x3C, 0xA6}
Index 8 - address {0x28, 0xCE, 0x0F, 0x16, 0xA8, 0x01, 0x3C, 0xC6}
Index 9 - address {0x28, 0xAE, 0xA3, 0x16, 0xA8, 0x01, 0x3C, 0x17}
Index 10 - address {0x28, 0xC9, 0xA2, 0x16, 0xA8, 0x01, 0x3C, 0x9C}
Index 11 - address {0x28, 0xE9, 0xF2, 0x16, 0xA8, 0x01, 0x3C, 0xBF}
Index 12 - address {0x28, 0x39, 0x34, 0x16, 0xA8, 0x01, 0x3C, 0xC5}
Index 13 - address {0x28, 0x15, 0xD2, 0x16, 0xA8, 0x01, 0x3C, 0x48}
Index 14 - address {0x28, 0x2D, 0x8F, 0x16, 0xA8, 0x01, 0x3C, 0x7D}
Index 15 - address {0x28, 0x43, 0xB1, 0x16, 0xA8, 0x01, 0x3C, 0x8B}

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffce0 end: 3fffffc0 offset: 01b0
3ffffe90:  3fffff50 00000010 3fff0ecc 40205136  
3ffffea0:  3fffff50 00000001 00000002 00000001  
3ffffeb0:  00000000 3ffffed0 00000008 40204ac4  
3ffffec0:  3fff0ee4 66a5a57f 3fffffb4 00000010  
3ffffed0:  3fffff50 3fff0eb0 0000000c 4020481e  
3ffffee0:  00000000 00000000 3ffe8ded 3ffeeb90  
3ffffef0:  3ffe86b1 00000010 3fff0eb0 40201948  
3fffff00:  000000a8 00000001 0000003c 0000008b  
3fffff10:  3278307b 30202c38 2c333478 42783020  
3fffff20:  30202c31 2c363178 41783020 30202c38  
3fffff30:  2c313078 33783020 30202c43 7d423878  
3fffff40:  00000000 feefeffe 00000002 c0713000  
3fffff50:  16f2e928 bf3c01a8 0000003c 402120e4  
3fffff60:  3fff0ea4 00000000 3fff0e64 40201b64  
3fffff70:  4e69f7e1 6e27ae2b 2fb51236 6e31c09d  
3fffff80:  c67a9afa d740d61a 011c2e71 809c19cb  
3fffff90:  feefeffe feefeffe feefeffe 3ffefb20  
3fffffa0:  3fffdad0 00000000 3ffefae0 40209d4c  
3fffffb0:  feefeffe feefeffe 3ffe84f8 40100cad  
<<<stack<<<
Zdebugowany stack komunikuje:

Kod: Zaznacz cały

Decoding stack results
0x40205136: OneWire::search(unsigned char*, bool) at D:\_profile\dokumenty\Arduino\libraries\OneWire\OneWire.cpp line 449
0x40204ac4: DallasTemperature::setResolution(unsigned char const*, unsigned char, bool) at D:\_profile\dokumenty\Arduino\libraries\DallasTemperature\DallasTemperature.cpp line 251
0x4020481e: DallasTemperature::getAddress(unsigned char*, unsigned char) at D:\_profile\dokumenty\Arduino\libraries\DallasTemperature\DallasTemperature.cpp line 132
0x40201948: Supla::Sensor::OneWireBus::OneWireBus(unsigned char) at D:\_profile\dokumenty\Arduino\libraries\SuplaDevice/supla/sensor/DS18B20.h line 53
0x402120e4: operator new(unsigned int) at /workdir/repo/gcc/libstdc++-v3/libsupc++/new_op.cc line 52
0x40201b64: setup() at D:\_profile\dokumenty\Arduino\libraries\SuplaDevice/supla/sensor/DS18B20.h line 127
0x40209d4c: loop_wrapper() at C:\Users\Mariusz\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 177
Po pozostawieniu 15 czujników ruszyło:

Kod: Zaznacz cały

Creating OneWire bus for pin: 2
Initializing OneWire bus at pin 2
OneWire(pin 2) Parasite power is OFF
OneWire(pin 2) Found 15 devices:
Index 0 - address {0x28, 0x80, 0xD2, 0x16, 0xA8, 0x01, 0x3C, 0x12}
Index 1 - address {0x28, 0x32, 0x74, 0x79, 0x97, 0x05, 0x03, 0x9B}
Index 2 - address {0x28, 0x56, 0x04, 0x16, 0xA8, 0x01, 0x3C, 0xA6}
Index 3 - address {0x28, 0xAE, 0xA3, 0x16, 0xA8, 0x01, 0x3C, 0x17}
Index 4 - address {0x28, 0xC9, 0xA2, 0x16, 0xA8, 0x01, 0x3C, 0x9C}
Index 5 - address {0x28, 0xE9, 0xF2, 0x16, 0xA8, 0x01, 0x3C, 0xBF}
Index 6 - address {0x28, 0x39, 0x34, 0x16, 0xA8, 0x01, 0x3C, 0xC5}
Index 7 - address {0x28, 0x15, 0xD2, 0x16, 0xA8, 0x01, 0x3C, 0x48}
Index 8 - address {0x28, 0x2D, 0x8F, 0x16, 0xA8, 0x01, 0x3C, 0x7D}
Index 9 - address {0x28, 0x43, 0xB1, 0x16, 0xA8, 0x01, 0x3C, 0x8B}
Index 10 - address {0x28, 0xE3, 0xA7, 0x16, 0xA8, 0x01, 0x3C, 0x37}
Index 11 - address {0x28, 0x93, 0xC0, 0x16, 0xA8, 0x01, 0x3C, 0xEF}
Index 12 - address {0x28, 0xB3, 0xD7, 0x16, 0xA8, 0x01, 0x3C, 0x74}
Index 13 - address {0x28, 0xBB, 0x43, 0x16, 0xA8, 0x01, 0x3C, 0x7D}
Index 14 - address {0x28, 0x67, 0xC0, 0x16, 0xA8, 0x01, 0x3C, 0x41}
Device address not provided. Using device from index 0
WIFI: establishing connection with SSID: "SSID"
Using protocol version 8
Channel(0) value changed to 18.500000
Current status: SuplaDevice initialized
local IP: 172.16.144.80
subnetMask: 255.255.255.0
gatewayIP: 172.16.144.1
Signal Strength (RSSI): -61 dBm
Current status: Not connected
Establishing connection with: supla.******** (port: 2015)
Connected
Current status: Register in progress
Device registered (activity timeout 120 s, server version: 10, server min version: 10)
Current status: Registered and ready.
Changing activity timeout to 30
Activity timeout set to 30 s
Channel(0) value changed to 18.437500
Ostatnio zmieniony czw sty 16, 2020 5:20 pm przez Goral64, łącznie zmieniany 3 razy.
Widzimy się na Supla Offline Party Season 2 :D

Obrazek
elmaya
Posty: 1482
Rejestracja: śr cze 27, 2018 5:48 pm
Lokalizacja: El Saucejo - Sevilla

Prawdopodobnie wpływa to również na rozdzielczość używaną przez czujniki.
Przy rozdzielczości 10 możesz użyć więcej niż przy rozdzielczości 12.
Awatar użytkownika
Goral64
Posty: 3131
Rejestracja: pt gru 27, 2019 6:22 pm
Lokalizacja: Żerniki Wrocławskie
Kontakt:

Udało mi się jeszcze podłączyć 2 czujniki więcej. Czyli łącznie 17. Jednak musiałem użyć do tego celu 2 portów.
W maksymalnej konfiguracji do portu 2 mam podpięte 11 czujników i 6 czujników do portu 0.

Nie mam pojęcia dlaczego tak jest :(
Widzimy się na Supla Offline Party Season 2 :D

Obrazek
Awatar użytkownika
Goral64
Posty: 3131
Rejestracja: pt gru 27, 2019 6:22 pm
Lokalizacja: Żerniki Wrocławskie
Kontakt:

Po pobraniu ID maksymalnie 17 czujnika wywala się Soft WDT reset

Kod: Zaznacz cały

Decoding stack results
0x401002cc: delayMicroseconds(unsigned int) at C:\Users\Mariusz\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_wiring.cpp line 210
0x402050dc: OneWire::write_bit(unsigned char) at D:\_profile\dokumenty\Arduino\libraries\OneWire\OneWire.cpp line 220
0x40205148: OneWire::read_bit() at D:\_profile\dokumenty\Arduino\libraries\OneWire\OneWire.cpp line 242
0x40204dd8: DallasTemperature::isConversionComplete() at D:\_profile\dokumenty\Arduino\libraries\DallasTemperature\DallasTemperature.cpp line 360
0x40204e2c: DallasTemperature::blockTillConversionComplete(unsigned char) at D:\_profile\dokumenty\Arduino\libraries\DallasTemperature\DallasTemperature.cpp line 407
0x40204e80: DallasTemperature::requestTemperatures() at D:\_profile\dokumenty\Arduino\libraries\DallasTemperature\DallasTemperature.cpp line 374
0x402019b1: Supla::Sensor::OneWireBus::OneWireBus(unsigned char) at D:\_profile\dokumenty\Arduino\libraries\SuplaDevice/supla/sensor/DS18B20.h line 73
0x4020b2a1: uart_set_debug(int) at C:\Users\Mariusz\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\uart.cpp line 933
0x4021233c: operator new(unsigned int) at /workdir/repo/gcc/libstdc++-v3/libsupc++/new_op.cc line 52
0x40201a72: Supla::Sensor::DS18B20::DS18B20(unsigned char, unsigned char*) at D:\_profile\dokumenty\Arduino\libraries\SuplaDevice/supla/sensor/DS18B20.h line 127
0x40201d75: setup() at D:\_profile\dokumenty\Arduino\ESP-01_DS18B20/ESP-01_DS18B20.ino line 119
0x40209fa8: loop_wrapper() at C:\Users\Mariusz\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266\core_esp8266_main.cpp line 177
Widzimy się na Supla Offline Party Season 2 :D

Obrazek
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

elmaya pisze: czw sty 16, 2020 5:02 pm Prawdopodobnie wpływa to również na rozdzielczość używaną przez czujniki.
Przy rozdzielczości 10 możesz użyć więcej niż przy rozdzielczości 12.
Dlaczego? Jaki wpływ ma rozdzielczość na ilość czujników?
Widzimy się na Supla Offline Party vol. 2 :!:
elmaya
Posty: 1482
Rejestracja: śr cze 27, 2018 5:48 pm
Lokalizacja: El Saucejo - Sevilla

czas potrzebny na czytanie
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

elmaya pisze: czw sty 16, 2020 6:26 pm czas potrzebny na czytanie
To raczej nie ma znaczenia. Biblioteka wysyła zapytanie o odczyt i dopiero po 5 s odczytuje wartości z termometru. Robi to nieblokująco.
Widzimy się na Supla Offline Party vol. 2 :!:
ODPOWIEDZ

Wróć do „Pomoc”