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
X

xypzo

@xypzo
About
Posts
11
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Combine several scetches to 1 node
    X xypzo

    IT WORKS, thank you very much!
    One thing, the interrupt (motion) status is only sent when the other data (temp hum) is being send. So once a minute it jumps from "on" to "off" in stead of every time the Sensor goes HI/LO.
    Is there a way to fix that?
    Thanks again, you are a HERO

    Development

  • Combine several scetches to 1 node
    X xypzo

    Hi
    I am having trouble combining multiple scetches into one node since the last mysensors library update.
    I have combined the DHT and RELAY scetches and they work great. I just want to add an interrupt sensor (door, motion, whatever) to pin 3.
    I think the problem is the sleep function. it is different in all 3 scetches, i am an absolute NOOB with programming, but simply cut/paste is not working anymore.

    Can somebody please be of any assistance? You would save the day! thanks!

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_REPEATER_FEATURE
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <DHT.h>
    
    static const uint64_t UPDATE_INTERVAL = 60000;
    static const uint8_t FORCE_UPDATE_N_READS = 10;
    
    #define CHILD_ID_HUM 3
    #define CHILD_ID_TEMP 4
    #define DHT_DATA_PIN 8
    #define SENSOR_TEMP_OFFSET 0
    
    #define RELAY_PIN 4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 2 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    float lastTemp;
    float lastHum;
    uint8_t nNoUpdatesTemp;
    uint8_t nNoUpdatesHum;
    bool metric = true;
    
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    DHT dht;
    
    
    void before()
    {
      for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);
        // Set relay to last known state (using eeprom storage)
        digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF);
      }
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("DHT & Relays", "2.0");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_HUM, S_HUM);
      present(CHILD_ID_TEMP, S_TEMP);
      for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
        // Register all sensors to gw (they will be created as child devices)
        present(sensor, S_BINARY);
    
        metric = getControllerConfig().isMetric;
      }
    }
    
    void setup()
    {
    
      dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
    
      // Sleep for the time of the minimum sampling period to give the sensor time to power up
      // (otherwise, timeout errors might occure for the first reading)
      sleep(dht.getMinimumSamplingPeriod());
    
    }
    
    void loop()
    {
      // Force reading sensor, so it works also after sleep()
      dht.readSensor(true);
    
      // Get temperature from DHT library
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
        Serial.println("Failed reading temperature from DHT!");
      } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
        // Only send temperature if it changed since the last measurement or if we didn't send an update for n times
        lastTemp = temperature;
    
        // apply the offset before converting to something different than Celsius degrees
        temperature += SENSOR_TEMP_OFFSET;
    
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        // Reset no updates counter
        nNoUpdatesTemp = 0;
        send(msgTemp.set(temperature, 1));
    
    #ifdef MY_DEBUG
        Serial.print("T: ");
        Serial.println(temperature);
    #endif
      } else {
        // Increase no update counter if the temperature stayed the same
        nNoUpdatesTemp++;
      }
    
      // Get humidity from DHT library
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
        Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
        // Only send humidity if it changed since the last measurement or if we didn't send an update for n times
        lastHum = humidity;
        // Reset no updates counter
        nNoUpdatesHum = 0;
        send(msgHum.set(humidity, 1));
    
    #ifdef MY_DEBUG
        Serial.print("H: ");
        Serial.println(humidity);
    #endif
      } else {
        // Increase no update counter if the humidity stayed the same
        nNoUpdatesHum++;
      }
    
      // Sleep for a while to save energy
      sleep(UPDATE_INTERVAL);
    }
    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(message.sensor - 1 + RELAY_PIN, 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());
      }
    }
    
    Development

  • RGB LED strip
    X xypzo

    what DID happen the day before, was that when i added more WHITE, at around 60% white the whole unit stopped responding to any inputs, it would just freeze in that color, until i removed the 12v power supply. Also strange! :)

    My Project

  • RGB LED strip
    X xypzo

    @maghac The stupid thing, is that the day before, same setup, no red lights stayed on. It happened overnight!!! Maybe the mice did it! :')

    My Project

  • RGB LED strip
    X xypzo

    @maghac said in RGB LED strip:

    your connections, perhaps you're connecting to the wrong pin on the arduino

    Then green keeps on, so it should be a pin 6 problem, but i can't find it. Maybe I try a 10kohm resistor between gate and ground... Or IRFZ instead of IRLZ transistors.

    BTW, bought a LD362A ufo which works great with my controller, but i still want to win this battle!

    My Project

  • RGB LED strip
    X xypzo

    I dont know what went wrong, but RED is just always on. Yesterday in the breadboard it was ok. Today in the breadboard red was on. So i thought lets just solder it... Now I soldered it to a pcb, RED on all the time. This must be a ground issue, but where do i look?

    It is even red when just all the connections are off, 12v to raw and strip, then connect ground to arduino, BOOM red comes on...

    My Project

  • 💬 Parking Sensor
    X xypzo

    Hey David,
    Could you share the working code (with the SHARP sensor integrated) with us?

    Announcements

  • 💬 Power Meter Pulse Sensor
    X xypzo

    Fhem tells me this all the time:
    MYSENSORS: ignoring presentation-msg from unknown radioId 0, childId 255, sensorType 18

    Announcements

  • 💬 Power Meter Pulse Sensor
    X xypzo

    Hey guys, I have a strange problem using excact this scetch and the new 2.0 serial gateway scetch using FHEM.
    I do get KWH values, but no Power values, and sometimes all of a sudden it gives me a power value, like twice a day.
    It didn't do that before and I am a complete copy-pase N00B, so maybe somebody already sovled this issue? HELP

    Announcements

  • Help with scetch relaywithbutton
    X xypzo

    Wow, thank you so much, it works like a charm!

    Troubleshooting

  • Help with scetch relaywithbutton
    X xypzo

    Hi, I am trying to have a double relay switching using FHEM controller.

    I took the code of scetch RelayWithButton and modified it for 2 relays.
    When I switch in FHEM, it will always switch both relays at the same time.

    I am a copy-pasting extreme code NOOB, so please be gentle!

    Thanks in advance
    xypzo

    #include <MySensor.h>
    #include <SPI.h>
    #include <Bounce2.h>
    
    #define RELAY_ON 1
    #define RELAY_OFF 0
    #define RELAY1_PIN  3  // Arduino Digital I/O pin number for relay 1
    #define RELAY2_PIN  4  // Arduino Digital I/O pin number for relay 2 
    #define BUTTON_PIN  7  // Arduino Digital I/O pin number for button 
    #define CHILD_ID_R 1   // Id of the sensor child R1
    #define CHILD_ID_R2 2   // Id of the sensor child R2
    
    
    Bounce debouncer = Bounce(); 
    int oldValue=0;
    bool state;
    MySensor gw;
    MyMessage msg1(CHILD_ID_R, V_LIGHT);
    MyMessage msg2(CHILD_ID_R2, V_LIGHT);
    
    
    void setup()  
    {  
      gw.begin(incomingMessage, AUTO, true);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Relays & Button", "0.1");
    
     // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      
      // After setting up the button, setup debouncer
      debouncer.attach(BUTTON_PIN);
      debouncer.interval(5);
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_R, S_LIGHT);
      gw.present(CHILD_ID_R2, S_LIGHT);
      
      // Make sure relays are off when starting up
      digitalWrite(RELAY1_PIN, RELAY_OFF);
      digitalWrite(RELAY2_PIN, RELAY_OFF);
      
      // Then set relay pins in output mode
      pinMode(RELAY1_PIN, OUTPUT);
      pinMode(RELAY2_PIN, OUTPUT);   
          
      // Set relay to last known state (using eeprom storage) 
      state = gw.loadState(CHILD_ID_R);
      digitalWrite(RELAY1_PIN, state?RELAY_ON:RELAY_OFF);
      state = gw.loadState(CHILD_ID_R2);
      digitalWrite(RELAY2_PIN, state?RELAY_ON:RELAY_OFF);
    }
    
    
    /*
    *  Example on how to asynchronously check for new messages from gw
    */
    void loop() 
    {
      gw.process();
      debouncer.update();
      // Get the update value
      int value = debouncer.read();
      if (value != oldValue && value==0) {
          gw.send(msg1.set(state?false:true), true); // Send new state and request ack back
          gw.send(msg2.set(state?false:true), true);
      }
      oldValue = value;
    } 
     
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.isAck()) {
         Serial.println("This is an ack from gateway");
      }
    
      if (message.type == V_LIGHT) {
         // Change relay state
         state = message.getBool();
         digitalWrite(RELAY1_PIN, state?RELAY_ON:RELAY_OFF);
         digitalWrite(RELAY2_PIN, state?RELAY_ON:RELAY_OFF);
         
         // Store state in eeprom
         gw.saveState(CHILD_ID_R, state);
         gw.saveState(CHILD_ID_R2, state);
        
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getBool());
       } 
    }```
    Troubleshooting
  • Login

  • Don't have an account? Register

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