Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. roffy
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    roffy

    @roffy

    0
    Reputation
    3
    Posts
    387
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    roffy Follow

    Best posts made by roffy

    This user hasn't posted anything yet.

    Latest posts made by roffy

    • RE: Relay with button example sketch, works...but not as expected

      wow thanks for all the suggestions guys! sorry for the slow reply, this is the first time iv actually been able to sit at my computer since i posted, if only we didnt have to work to pay bills id be here all day...ahhh if only..... anyway!

      Yes i am using a pushbutton not a rocker switch so i would need it to only do something on the down press and ignore the upward contact on the release of the button.

      Ill try changing the script as explained above and see what that does, (as you have probably guessed by now my arduino tinkering only covered the first 10 or so lessons in the basic tutorial, then i went off and only looked up specific coding for the small projects i was working on....and most of which i have forgotten as i haven't used them for a long time 😞 need to brush up on what i should already know i guess)

      anyway i shall post results as soon as i try out the suggestions. i think you all get what im trying to achieve here! thanks again,

      posted in Troubleshooting
      roffy
      roffy
    • RE: Relay with button example sketch, works...but not as expected

      powered from the usb of my PC as i have only uploaded the sketch then went to try it out.
      i was thinking it wasent a power supply problem as the sensor seems to be working ok. no errors or fails in the serial monitor.

      sketch is a direct coppy and past from the example of relay with button. here it is.

      // Example sketch för a "light switch" where you can control light or something 
      // else from both vera and a local physical button (connected between digital
      // pin 3 and GND).
      // This node also works as a repeader for other nodes
      
      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define RELAY_PIN  4  // Arduino Digital I/O pin number for relay 
      #define BUTTON_PIN  3  // Arduino Digital I/O pin number for button 
      #define CHILD_ID 1   // Id of the sensor child
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      Bounce debouncer = Bounce(); 
      int oldValue=0;
      bool state;
      MySensor gw;
      MyMessage msg(CHILD_ID,V_LIGHT);
      
      void setup()  
      {  
        gw.begin(incomingMessage, AUTO, true);
      
        // Send the sketch version information to the gateway and Controller
        gw.sendSketchInfo("Relay & Button", "1.0");
      
       // 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, S_LIGHT);
      
        // Make sure relays are off when starting up
        digitalWrite(RELAY_PIN, RELAY_OFF);
        // Then set relay pins in output mode
        pinMode(RELAY_PIN, OUTPUT);   
            
        // Set relay to last known state (using eeprom storage) 
        state = gw.loadState(CHILD_ID);
        digitalWrite(RELAY_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(msg.set(state?false:true), true); // Send new state and request ack back
        }
        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 && strlen(msg.getString()) != 0) {
           // Change relay state
           state = message.getBool();
           digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
           // Store state in eeprom
           gw.saveState(CHILD_ID, state);
          
           // Write some debug info
           Serial.print("Incoming change for sensor:");
           Serial.print(message.sensor);
           Serial.print(", New status: ");
           Serial.println(message.getBool());
         } 
      }
      
      

      does this help at all?

      posted in Troubleshooting
      roffy
      roffy
    • Relay with button example sketch, works...but not as expected

      Hi all, am fairly new to automation but have tinkered with arduino in the past.
      my setup is currently
      VeraLite UI7
      arduino seral gateway (working with no obvious errors)
      1 arduino nanno running door/window/button sketch
      (this is working as expected)

      and the one i have just setup running relayWithButton.

      so, i have no relay to controll i just want my button to be able to activate some scenes in vera.
      the sketch and button are attached and running, added to the vera seemingly ok.
      i can turn on/off the device in the vera UI and can see commands being recieved in serial monitor on the relay node arduino.

      one thing i am stuck on, it seems that my button only changes the device state after the gw has altered it first.
      i.e. if i turn it on in vera, the button when pressed will then turn it off again.
      after that the button becomes useless and i have to turn it back on through the vera UI.

      What am i missing here? is the button behaving as it should or should the button be active (change the device state) every press?

      here is my serial monitor readout of the button press After turning the device on in the vera UI

      Incoming change for sensor:1, New status: 1  //i just turned it on in vera
      send: 2-2-0-0 s=1,c=1,t=2,pt=2,l=2,st=ok:0        // just pressed the button
      read: 0-0-2 s=1,c=1,t=2,pt=2,l=2:0
      This is an ack from gateway
      

      and here is the serial monitor readout when pressing the button again without touching the vera UI

      send: 2-2-0-0 s=1,c=1,t=2,pt=2,l=2,st=ok:0
      read: 0-0-2 s=1,c=1,t=2,pt=2,l=2:0
      This is an ack from gateway
      

      the divice does not change state after the second press.

      Thanks for any help, sorry if im missing something bleeding obvious!

      posted in Troubleshooting
      roffy
      roffy