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
WoekaW

Woeka

@Woeka
About
Posts
6
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Combining DS18B20 and relay..
    WoekaW Woeka

    Hi, not long ago I did the same.

    Looking at your code I notice you got 16 DS18B20's. When using so many it is probably better to also fix the ID's otherwise when a DS18B20 is not responding the order of the sensors is shifted. See for code to get the ID's: https://forum.mysensors.org/topic/4143/about-ds18b20-onewire

    I also changed the pin assignment for the relay's a tiny bit.

    My sketch:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>  
    #include <DallasTemperature.h>
    #include <OneWire.h>
    
    const int PINS[] = {4, 5, 6, 7, 8, 14, 15}; // I/O pins 4, 5, 6, 7, 8, A0, A1 for the relays 
    #define NUMBER_OF_RELAYS 7 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    #define COMPARE_TEMP 0 // Send temperature only if changed? 1 = Yes 0 = No
    
    #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
    #define MAX_ATTACHED_DS18B20 5
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    // Generally, you should use "unsigned long" for variables that hold time
    // The value will quickly become too large for an int to store
    unsigned long previousMillis = 0;        // will store last time LED was updated
    
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
    DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
    
    byte D[5][8] = {
    { 0x28, 0xF2, 0xAB, 0x0F, 0x07, 0x00, 0x00, 0xA1 },
    { 0x28, 0x23, 0x29, 0xDB, 0x05, 0x00, 0x00, 0x5A },
    { 0x28, 0xAB, 0x2A, 0xDB, 0x05, 0x00, 0x00, 0x5F },
    { 0x28, 0x49, 0xAF, 0x0F, 0x07, 0x00, 0x00, 0x41 },
    { 0x28, 0x1D, 0x2F, 0x10, 0x07, 0x00, 0x00, 0xDA }
    };
    
    float lastTemperature[MAX_ATTACHED_DS18B20];
    int numSensors=0;
    bool receivedConfig = false;
    bool metric = true;
    // Initialize temperature message
    MyMessage msg(0,V_TEMP);
    
    void before()
    {
        for (int sensor=1; sensor<=NUMBER_OF_RELAYS; sensor++) {
            // Then set relay pins in output mode
            pinMode(PINS[sensor-1], OUTPUT);
            // Set relay to last known state (using eeprom storage)
            digitalWrite(PINS[sensor-1], loadState(sensor)?RELAY_ON:RELAY_OFF);     
        }
        
        // Startup up the OneWire library
        sensors.begin();
    }
    
    void setup()  
    { 
      // requestTemperatures() will not block current thread
      sensors.setWaitForConversion(false);
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay and Temp", "1.0");
    
        for (int sensor=1; sensor<=NUMBER_OF_RELAYS+MAX_ATTACHED_DS18B20; sensor++) {
            // Register all sensors to gw (they will be created as child devices)
    
            if (sensor<=NUMBER_OF_RELAYS){  
              present(sensor, S_BINARY);       
            }
            else {
              present(sensor, S_TEMP);          
            }
        }
    }
    
    void loop()     
    {     
      unsigned long currentMillis = millis();
    
      if (currentMillis - previousMillis >= SLEEP_TIME) {
        // save the last time you blinked the LED
        previousMillis = currentMillis;
    
        // Fetch temperatures from Dallas sensors
        sensors.requestTemperatures();
      
        // query conversion time and sleep until conversion completed
        int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
        // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
        sleep(conversionTime);
      
        // Read temperatures and send them to controller 
        for (int i=0; i<MAX_ATTACHED_DS18B20; i++) {
      
          // Fetch and round temperature to one decimal
          // float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
          float temperature = sensors.getTempC(D[i]);
          
          // Only send data if temperature has changed and no error
          if (COMPARE_TEMP == 1) {
            if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                // Send in the new temperature
                send(msg.setSensor(i+NUMBER_OF_RELAYS+1).set(temperature,1));
                // Save new temperatures for next compare
                lastTemperature[i]=temperature;
            }
          }
          else {
            if (temperature != -127.00 && temperature != 85.00) {
                // Send in the new temperature
                send(msg.setSensor(i+NUMBER_OF_RELAYS+1).set(temperature,1));
                // Save new temperatures for next compare
                lastTemperature[i]=temperature;
            }
          }
        }
      }
    }
    
    void receive(const MyMessage &message)
    {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
            // Change relay state
            digitalWrite(PINS[message.sensor-1], message.getBool()?RELAY_ON:RELAY_OFF);
            // Store state in eeprom
            saveState(message.sensor, message.getBool());
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.sensor);
            Serial.print(", New status: ");
            Serial.println(message.getBool());
        }
    }
    
    Troubleshooting

  • What did you build today (Pictures) ?
    WoekaW Woeka

    @woeka .... and the enclosure is from Surtronics.

    General Discussion

  • What did you build today (Pictures) ?
    WoekaW Woeka

    I've build this temperature & humidity node.

    It uses a Si7021 for the temperature and humidity, a power converter from a Li-ion cell to 3,3v. Voltage measurement with a voltage divider on pin A0.

    I've removed the led and converter from the mini pro and also the power converter from the Si7021 (next time I will buy one for 3.3v instead of 5v). This really prolong your battery time, more then 4 times in my case. Looks like the node can run approximately half a year on a full Li-ion cell, scavenged from an old laptop battery.

    Temp-Hum node

    General Discussion

  • 💬 Building a Raspberry Pi Gateway
    WoekaW Woeka

    Got mysensors gateway working on gpio of my Pi again using ./configure --my-transport=nrf24 --my-rf24-irq-pin=15 --my-leds-err-pin=12 --my-leds-rx-pin=16 --my-leds-tx-pin=18 --my-gateway=ethernet --my-port=5003

    However on tx or tx always the two leds connected to pin 16 and 18 are lit. More people with the same problem?

    Announcements

  • 💬 Temperature Sensor
    WoekaW Woeka

    I had some problems with Domoticz triggering an event based on a certain temperature. When using multiple DS18B20 it is a good idea to use the ID of the sensors to always get the same order of sensors. If one is not read, for example B of A, B, C then C becomes B. See: https://forum.mysensors.org/topic/4143/about-ds18b20-onewire for more info. You maybe need to adjust the sketch a bit for your number of sensors.

    Announcements

  • 💬 Relay
    WoekaW Woeka

    I did not get the example working properly with my 8 channel SSR. So here is my updated version of the example.

    I have changed the way the pins are assigned by using a array. The current example tries to connect relays 7 and 8 to pins 9 and 10 when you select an 8 channel relays. This won't work because those pins are used by the radio module.

    I think you can connect a relays to any pin which is not used. If so this will make it possible to connect up to 14 relays to the mini pro when also the pins A5-A7 are available.

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <MySensors.h>
    
    const int PINS[] = {3, 4, 5, 6, 7, 8, 14, 15}; // I/O pins 3, 4, 5, 6, 7, 8, A0, A1 for the relays 
    #define NUMBER_OF_RELAYS 8 // Total number of attached relays
    #define RELAY_ON 0  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
    
    
    void before()
    {
        for (int sensor=1; sensor<=NUMBER_OF_RELAYS; sensor++) {
            // Then set relay pins in output mode
            pinMode(PINS[sensor-1], OUTPUT);
            // Set relay to last known state (using eeprom storage)
            digitalWrite(PINS[sensor-1], loadState(sensor)?RELAY_ON:RELAY_OFF);
            
        }
    }
    
    void setup()
    {
    
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay", "1.0");
    
        for (int sensor=1; sensor<=NUMBER_OF_RELAYS; sensor++) {
            // Register all sensors to gw (they will be created as child devices)
            present(sensor, S_BINARY);
        }
    }
    
    
    void loop()
    {
    
    }
    
    void receive(const MyMessage &message)
    {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
            // Change relay state
            digitalWrite(PINS[message.sensor-1], message.getBool()?RELAY_ON:RELAY_OFF);
            // Store state in eeprom
            saveState(message.sensor, message.getBool());
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.sensor);
            Serial.print(", New status: ");
            Serial.println(message.getBool());
        }
    }
    
    Announcements
  • Login

  • Don't have an account? Register

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