Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Noob problem with NodeMCU and OneWire

Noob problem with NodeMCU and OneWire

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 5 Posters 2.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    emme
    wrote on last edited by
    #1

    Ciao to all,
    I'm moving to MySensors network in my home to be used with Domoticz... after a first phase made by a gateway on a raspberry PI2, a rain (on/off), I'm now approaching to reorganize the entire network and move to a nodeMCU (12e) gateway which include the rain sensor and I would like to add a DS18B20 too (to gather external temp)
    While the gateway and the on/off switch works pretty fine, I'm having a bad problem with OneWire: even if the sketch is compiled with no error, I see no device, nr presented, nor updated, no device at all

    Wirings are ok: using D1 pin (no luck with other pins), with a 4k7 resistor... 3.3v are provided from an external 5v (2A) power supply and a AMS1117 3.3
    I checked the same sketch on a ATMega328p nano and it works... seems to be a NodeMCU device issue
    does anyone experienced the same?
    Is there a solution for this (which does not include to move to DHT22 :P :P )
    thanks
    ciao
    M

    mfalkviddM 1 Reply Last reply
    0
    • E emme

      Ciao to all,
      I'm moving to MySensors network in my home to be used with Domoticz... after a first phase made by a gateway on a raspberry PI2, a rain (on/off), I'm now approaching to reorganize the entire network and move to a nodeMCU (12e) gateway which include the rain sensor and I would like to add a DS18B20 too (to gather external temp)
      While the gateway and the on/off switch works pretty fine, I'm having a bad problem with OneWire: even if the sketch is compiled with no error, I see no device, nr presented, nor updated, no device at all

      Wirings are ok: using D1 pin (no luck with other pins), with a 4k7 resistor... 3.3v are provided from an external 5v (2A) power supply and a AMS1117 3.3
      I checked the same sketch on a ATMega328p nano and it works... seems to be a NodeMCU device issue
      does anyone experienced the same?
      Is there a solution for this (which does not include to move to DHT22 :P :P )
      thanks
      ciao
      M

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @emme welcome to the MySensors community. Are you still stuck on this? If so, could you post your sketch and describe all your wiring?

      1 Reply Last reply
      0
      • E Offline
        E Offline
        emme
        wrote on last edited by
        #3

        still unsolved, but workaround by replacing the onewire with a DHT22 :P :P

        this is my sketch:

        // Gateway MySensors on NodeMCU with some Devices 
        // OneWire for DS18B20 
        // Bounce for S_DOOR (Rain Sensor)
        #define MY_DEBUG
        #define MY_BAUD_RATE 115200
        #define MY_RADIO_NRF24
        
        // #define MY_GATEWAY_SERIAL
        #define MY_GATEWAY_ESP8266
        #define MY_ESP8266_SSID "myWiFi"
        #define MY_ESP8266_PASSWORD "******"
        #define MY_ESP8266_HOSTNAME "sensor-gateway"
        #define MY_PORT 5003
        #define MY_GATEWAY_MAX_CLIENTS 3
        #include <ESP8266WiFi.h>
        
        #define MY_INCLUSION_MODE_FEATURE
        
        #include <MySensors.h>
        #include <SPI.h>
        #include <DallasTemperature.h>
        #include <OneWire.h>
        
        #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
        #define ONE_WIRE_BUS D1 // Pin where dallase sensor is connected 
        #define MAX_ATTACHED_DS18B20 5
        
        unsigned long temp_Sleep = 30000; // Sleep time between reads (in milliseconds)
        unsigned long temp_nTime;
        
        OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices
        DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
        float lastTemperature[MAX_ATTACHED_DS18B20];
        int numSensors=0;
        bool receivedConfig = false;
        bool metric = true;
        // Initialize temperature message
        MyMessage msgTemp(0,V_TEMP);
        
        #include <Bounce2.h>
        // RAIN Sensor Definitions and settings
        #define CHILD_ID 10
        #define BUTTON_PIN D4  // Arduino Digital I/O pin for button/reed switch
        Bounce debouncer = Bounce(); 
        int oldValue=-1;
        MyMessage msgRain(CHILD_ID,V_TRIPPED);
        
        unsigned long cTime;  // Current Time
        void before()
        {
          // Startup up the OneWire library
          sensors.begin();
        }
        
        void setup()  
        { 
          // requestTemperatures() will not block current thread
          sensors.setWaitForConversion(false);
        
          pinMode(BUTTON_PIN,INPUT);
          digitalWrite(BUTTON_PIN,HIGH);
          debouncer.attach(BUTTON_PIN);
          debouncer.interval(5);
        }
        
        void presentation() {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Temperature Sensor", "1.1");
        
          // Fetch the number of attached temperature sensors  
          numSensors = sensors.getDeviceCount();
        
          // Present all sensors to controller
          for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
             present(i, S_TEMP);
          }
          
          present(CHILD_ID, S_DOOR);  
        }
        
        void loop()     
        {
          cTime = millis();  // Get current Timing
        
          if ((cTime - temp_nTime) >= temp_Sleep) {     // this is supposed to replace the sleep function 
            sensors.requestTemperatures();
            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
              float temperature = static_cast<float>(static_cast<int>(sensors.getTempCByIndex(i)));
              #if COMPARE_TEMP == 1
              if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
              #else
              if (temperature != -127.00 && temperature != 85.00) {
              #endif
                send(msgTemp.setSensor(i).set(temperature,1));
                lastTemperature[i]=temperature;
              }
            }
            temp_nTime = millis();
          }
          
          debouncer.update();
          int value = debouncer.read();
          if (value != oldValue) {
             // Send in the new value
             send(msgRain.set(value==HIGH ? 1 : 0));
             oldValue = value;
          }
          
        }
        

        if I enter a

        Serial.print("Sensors Count over 1W bus: ");
        Serial.println(sensors.getDeviceCount()); 
        

        I got 0 :(

        wirings are ok... I checked with the tester and I get correct voltage (3,3) and impedence (4,7k)
        DHT works fine at first try on the same PIN

        thanks for the help
        ciao
        Marco

        1 Reply Last reply
        1
        • B Offline
          B Offline
          bagou91
          wrote on last edited by
          #4

          Hello,
          I have exactly the same issue with ESP8266 nodemcu as Gateway + sensor DHT22.
          I tested with 2 different libraries DHT22.
          And I also tested with mySensors 2.1.0 and 2.1.1

          Console serial write out: Failed reading from DHT

          Otherwise the gateway works well without sensor (so alone) and with the DHT22 sensor on a node (arduino nano)

          1 Reply Last reply
          0
          • gohanG Offline
            gohanG Offline
            gohan
            Mod
            wrote on last edited by
            #5

            I'm moving to I2C sensors to avoid these kinds of problems 😀

            1 Reply Last reply
            0
            • sundberg84S Offline
              sundberg84S Offline
              sundberg84
              Hardware Contributor
              wrote on last edited by
              #6

              I tried with two different Dallas Onewire and checked out the library at github. Have build these sensors before but got -127 all the time. Just adding this here if it pops up alof of people having issues...

              Controller: Proxmox VM - Home Assistant
              MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
              MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
              RFLink GW - Arduino Mega + RFLink Shield, 433mhz

              1 Reply Last reply
              1
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              33

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular