Navigation

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

    ihtgtwtd

    @ihtgtwtd

    4
    Reputation
    14
    Posts
    498
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    ihtgtwtd Follow

    Best posts made by ihtgtwtd

    • RE: Binary switch code written for 1.5.4

      No, of course not. Here you go, have fun everyone 🙂

      #define MY_DEBUG
      #define MY_RADIO_NRF24
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define SKETCH_NAME "Binary Sensor"
      #define SKETCH_MAJOR_VER "1"
      #define SKETCH_MINOR_VER "0"
      
      #define first_CHILD_ID 0
      #define second_CHILD_ID 1
      #define third_CHILD_ID 2
      #define fourth_CHILD_ID 3
      #define fifth_CHILD_ID 4
      #define sixth_CHILD_ID 5
      
      #define NUMBER_OF_SWITCHES 6
      
      Bounce debouncer[NUMBER_OF_SWITCHES];
      
      int oldValue[NUMBER_OF_SWITCHES];
      byte switchPin[NUMBER_OF_SWITCHES] = {3,4,5,6,7,8}; //<<<<<<<<<<< set your switch pins here
      
      MyMessage msg(0,V_STATUS);
      
      
      void setup()  
      {  
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          pinMode(switchPin[i],INPUT_PULLUP);
          debouncer[i] = Bounce();
          debouncer[i].attach(switchPin[i]);
          debouncer[i].interval(5);
        }
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          present(i, S_BINARY);
          delay(250);
        }
      }
      //
      void loop() 
      {
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          debouncer[i].update();
          int value = debouncer[i].read();
          if (value != oldValue[i]) 
          {
            send(msg.setSensor(i).set(value == HIGH? true : false), false); 
          }
          oldValue[i] = value;
        }
      } 
      
      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: Problem with multiple relays and delays

      @parachutesj
      thank you very much. looks good now.

      posted in Development
      ihtgtwtd
      ihtgtwtd
    • RE: Binary switch code written for 1.5.4

      thanks @mfalkvidd
      I already read that post. I tried again and now it worked.

      Thanks again

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd

    Latest posts made by ihtgtwtd

    • RE: [contest] 3D printed battery powered Wall Remote Control

      hi @Dirk_H
      Great project. I'm looking for a battery powered switch sketch like yours.
      Do you have it updated to MySensors v2.x? I tried to convert it but did not manage to get it working.

      /*
       * Copyright (C) 2015 Dirk H. R.
       * 
       * This program is free software; you can redistribute it and/or
       * modify it under the terms of the GNU General Public License
       * version 2 as published by the Free Software Foundation.
       * 
       * DESCRIPTION
       * This Program will implement six child sensors, which present one Push Button each.
       * The Program is meant to be used in conjunction with the Wall Remote Hardware
       * See MySensors for more information
       *
       * Frequency is 3.6864 MHz to ensure operation at low Voltages
       *
       */
      
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <PinChangeInt.h> //???
      
      #define MY_DEBUG
      #define MY_RADIO_NRF24
      #define SKETCH_NAME "Wall Remote"
      
      #define NodeID 2
      
      #define BotLeft_CHILD_ID 0			//Child ID for Bottom Left 
      #define MidLeft_CHILD_ID 1			//Child ID forMiddle Left 
      #define TopCornerLeft_CHILD_ID 2	//Child ID for Top Left (Corner Switch)
      
      #define BotRight_CHILD_ID 3			//Child ID for Bottom Left
      #define MidRight_CHILD_ID 4			//Child ID forMiddle Left
      #define TopCornerRight_CHILD_ID 5	//Child ID for Top Left (Corner Switch)
      
      #define BotLeft_PIN A1//21			//Digital Input for Bottom Left Pin			PCInt 11
      #define MidLeft_PIN A0//20			//Digital Input for Middle Left Pin			PCInt 10
      #define TopLeft_PIN A2//19			//Digital Input for Top Left (Corner Switch) Pin	PCInt 9
      
      #define BotRight_PIN 8			//Digital Input for Bottom Right Pin			
      #define MidRight_PIN 5			//Digital Input for Middle Right Pin			
      #define TopRight_PIN 4			//Digital Input for Top Right (Corner Switch) Pin	
      
      int BATTERY_SENSE_PIN = A6;  // select the input pin for the battery sense point
      int oldBatteryPcnt = 0;
      
      
      // Change V_LIGHT if you don't use S_LIGHT in presentation below
      MyMessage msg_BotLeft(BotLeft_CHILD_ID, V_LIGHT);
      MyMessage msg_MidLeft(MidLeft_CHILD_ID, V_LIGHT);
      MyMessage msg_TopLeft(TopCornerLeft_CHILD_ID, V_LIGHT);
      
      MyMessage msg_BotRight(BotRight_CHILD_ID, V_LIGHT);
      MyMessage msg_MidRight(MidRight_CHILD_ID, V_LIGHT);
      MyMessage msg_TopRight(TopCornerRight_CHILD_ID, V_LIGHT);
      
      //The BtnVal and the Btn_xx_ID are used to store the current state of the six buttons into a single uint8
      uint8_t BtnVal=0;	//idle/start value is 255 because Buttons get pulled up in idle state
      uint8_t BtnVal_last=0;
      #define Btn_BotLeft_ID 0
      #define Btn_MidLeft_ID 1
      #define Btn_TopLeft_ID 2
      
      #define Btn_BotRight_ID 3
      #define Btn_MidRight_ID 4
      #define Btn_TopRight_ID 5
      
      void setup()  
      {  
        //begin(NULL,NodeID);
      
        // Setup the buttons
        pinMode(BotLeft_PIN, INPUT);
        pinMode(MidLeft_PIN, INPUT);
        pinMode(TopLeft_PIN, INPUT);
        
        pinMode(BotRight_PIN, INPUT);
        pinMode(MidRight_PIN, INPUT);
        pinMode(TopRight_PIN, INPUT);
      
        // Activate internal pull-ups
        digitalWrite(BotLeft_PIN, HIGH);
        digitalWrite(MidLeft_PIN, HIGH);
        digitalWrite(TopLeft_PIN, HIGH);
        
        digitalWrite(BotRight_PIN, HIGH);
        digitalWrite(MidRight_PIN, HIGH);
        digitalWrite(TopRight_PIN, HIGH);
        
        //Use internal 1.1V Reference (for Battery Measurement)
        analogReference(INTERNAL);
      
        /*Setup PinChange Interrupt. Unfortunately you must ensure that the "MyGateway.cpp" will not be compiled for this,
        i.e. look into your Arduino libraries\MySensors folder and 
        ---> RENAME THE "MyGateway.cpp" to e.g. "MyGateway.cpp.nolib" <---.
        Of cause you must undo the renameing when you want to compile a MySensors Gateway!
        The reason for this renaming is that the compilter of Arduino compiles also the MyGateway where the PinChange interrupt 
        Vector is also defined, which will lead to an error because it is only allowed to have it one time in the program.
        */
        PCattachInterrupt(BotLeft_PIN,BotLeft_ISR,CHANGE);  
        PCattachInterrupt(MidLeft_PIN,MidLeft_ISR,CHANGE); 
        PCattachInterrupt(TopLeft_PIN,TopLeft_ISR,CHANGE); 
        
        PCattachInterrupt(BotRight_PIN,BotRight_ISR,CHANGE);
        PCattachInterrupt(MidRight_PIN,MidRight_ISR,CHANGE);
        PCattachInterrupt(TopRight_PIN,TopRight_ISR,CHANGE);
        interrupts();
      
        Serial.begin (115200);
      } 
      
      void presentation()
      {
          // Register Wall Remote buttons (they will be created as child devices)
        // I decided to take the S_Light parameter as i inteded the WallRemote to switch lights,
        // however you can change if you think this is more apropriate, hovwever
        // If S_LIGHT is not used, remember to update variable type you send in. See "msg" above.
        present(BotLeft_CHILD_ID, S_LIGHT);  
        present(MidLeft_CHILD_ID, S_LIGHT);  
        present(TopCornerLeft_CHILD_ID, S_LIGHT); 
        
        present(BotRight_CHILD_ID, S_LIGHT);
        present(MidRight_CHILD_ID, S_LIGHT);
        present(TopCornerRight_CHILD_ID, S_LIGHT); 
      }
      }
      
      void WallRemote_Sleep(){
      	//Custom Function that puts ATMega and NRF24L01 into sleep mode.
      	//This was necessary because PinChange Interrupts have been used.
      	sleep(0xff, 0x00, 0xff, 0x00, 0);
      	}
      
      void inline BtnPressHandler(uint8_t Button, uint8_t ValPos){
      	//Handler that just saves state of pressed button into BtnVal variable
      	//assuming that no debouncing is necessary because of wakeup time (16kCykles @ 4MHz = 4ms)
      	if (digitalRead(Button)==LOW) BtnVal |= (1<<ValPos);
      	else BtnVal &= ~(1<<ValPos);
      }
      
      //The six following ISRs are used to Wakeup the device and to call the Button Handler routine
      void BotLeft_ISR(){
      	BtnPressHandler(BotLeft_PIN, Btn_BotLeft_ID);
      }
      
      void MidLeft_ISR(){
      	BtnPressHandler(MidLeft_PIN, Btn_MidLeft_ID);
      }
      
      void TopLeft_ISR(){
      	BtnPressHandler(TopLeft_PIN, Btn_TopLeft_ID);
      }
      
      void BotRight_ISR(){
      	BtnPressHandler(BotRight_PIN, Btn_BotRight_ID);
      }
      
      void MidRight_ISR(){
      	BtnPressHandler(MidRight_PIN, Btn_MidRight_ID);
      }
      
      void TopRight_ISR(){
      	BtnPressHandler(TopRight_PIN, Btn_TopRight_ID);
      }
      
      void BtnSender(MyMessage Btn_Msg, uint8_t Btn_ID){
      	uint8_t temp=0;
      	temp = (BtnVal & (1<<Btn_ID));
      	if ( (BtnVal_last & (1<<Btn_ID)) != temp){
      		if (temp) send(Btn_Msg.set(HIGH)); 
      		else send(Btn_Msg.set(LOW));
      	}
      }
      
      //loop only checks the ButtonState Variable and transmits changes if necessary
      void loop() 
      {
      	
      	// get the battery Voltage (note: we only get here at restart of the node or after Interrupt from the Buttons)
      	int BatVal = analogRead(BATTERY_SENSE_PIN);
      	
      	// 1M, 470K divider across battery and using internal ADC ref of 1.1V
      	// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
      	// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
      	// 3.44/1023 = Volts per bit = 0.003363075
      	float batteryV  = BatVal * 0.003363075;
      	int batteryPcnt = BatVal / 10;
      	
      	if (oldBatteryPcnt != batteryPcnt) {
      		// Power up radio after sleep
      		sendBatteryLevel(batteryPcnt);
      		oldBatteryPcnt = batteryPcnt;
      	}
      
        //check if something has changed
        if (BtnVal != BtnVal_last){
      	  BtnSender(msg_BotLeft, Btn_BotLeft_ID);
      	  BtnSender(msg_MidLeft, Btn_MidLeft_ID);
      	  BtnSender(msg_TopLeft, Btn_TopLeft_ID);
      	  
      	  BtnSender(msg_BotRight, Btn_BotRight_ID);
      	  BtnSender(msg_MidRight, Btn_MidRight_ID);
      	  BtnSender(msg_TopRight, Btn_TopRight_ID);
        }
        BtnVal_last = BtnVal;
        
        //Go back to sleep (custom function, see above)
        WallRemote_Sleep();
      } 
      
      

      thx

      posted in Enclosures / 3D Printing
      ihtgtwtd
      ihtgtwtd
    • RE: Binary switch code written for 1.5.4

      No, of course not. Here you go, have fun everyone 🙂

      #define MY_DEBUG
      #define MY_RADIO_NRF24
      
      #include <MySensors.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define SKETCH_NAME "Binary Sensor"
      #define SKETCH_MAJOR_VER "1"
      #define SKETCH_MINOR_VER "0"
      
      #define first_CHILD_ID 0
      #define second_CHILD_ID 1
      #define third_CHILD_ID 2
      #define fourth_CHILD_ID 3
      #define fifth_CHILD_ID 4
      #define sixth_CHILD_ID 5
      
      #define NUMBER_OF_SWITCHES 6
      
      Bounce debouncer[NUMBER_OF_SWITCHES];
      
      int oldValue[NUMBER_OF_SWITCHES];
      byte switchPin[NUMBER_OF_SWITCHES] = {3,4,5,6,7,8}; //<<<<<<<<<<< set your switch pins here
      
      MyMessage msg(0,V_STATUS);
      
      
      void setup()  
      {  
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          pinMode(switchPin[i],INPUT_PULLUP);
          debouncer[i] = Bounce();
          debouncer[i].attach(switchPin[i]);
          debouncer[i].interval(5);
        }
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          present(i, S_BINARY);
          delay(250);
        }
      }
      //
      void loop() 
      {
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          debouncer[i].update();
          int value = debouncer[i].read();
          if (value != oldValue[i]) 
          {
            send(msg.setSensor(i).set(value == HIGH? true : false), false); 
          }
          oldValue[i] = value;
        }
      } 
      
      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: Binary switch code written for 1.5.4

      thanks @mfalkvidd
      I already read that post. I tried again and now it worked.

      Thanks again

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • Binary switch code written for 1.5.4

      Hi,
      I found the following sketch somewhere in the forum. It is written for MySensors 1.5.4, I tried to convert it for 2.1 but ended up with code that wont compile.

      What needs to be changed to make it compile?

      #include <MySensor.h>
      #include <SPI.h>
      #include <Bounce2.h>
      
      #define NUMBER_OF_SWITCHES 6
      
      MySensor gw;
      Bounce debouncer[NUMBER_OF_SWITCHES];
      
      int oldValue[NUMBER_OF_SWITCHES];
      byte switchPin[NUMBER_OF_SWITCHES] = {3,4,5,6,7,8}; //<<<<<<<<<<< set your switch pins here
      
      MyMessage msg(0,V_STATUS);
      
      void setup()  
      {  
        gw.begin();
      
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          pinMode(switchPin[i],INPUT_PULLUP);
          debouncer[i] = Bounce();
          debouncer[i].attach(switchPin[i]);
          debouncer[i].interval(5);
        }
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          gw.present(i, S_BINARY);
          delay(250);
        }
      }
      //
      void loop() 
      {
        for (int i = 0; i < NUMBER_OF_SWITCHES; i++)
        {
          debouncer[i].update();
          int value = debouncer[i].read();
          if (value != oldValue[i]) 
          {
            gw.send(msg.setSensor(i).set(value == HIGH? true : false), false); 
          }
          oldValue[i] = value;
        }
      } 
      

      this is the original sketch without changes.

      greetings

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: problem with implementation of my sensors in rollershutter sketch

      well thanks, I already tried that because it looked suspicious 😉
      but i was sending on switch 1 in domoticz and did not create a switch for 0.

      So it seems this thing works, thanks again for your help and the patience to deal with my noob questions 🙂

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: problem with implementation of my sensors in rollershutter sketch

      @AWI
      thanks, still small problems to figure out though.
      when I send a command to rollershutter 1 then rollershutter 2 receives the command. I can not control shutter 1, only 2 and 3 (with the buttons of 1 and 2)

      output in serial monitor is right and physical buttons work the right way too

      is there a problem in the registration or am I missing something (again)?
      the physical buttons work the right way.

      // Enable debug prints to serial monitor
      #define MY_DEBUG
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      #include <MySensors.h>
      #include <SPI.h>
      
      // Rollladensteuerung by jurs for German Arduino-Forum
      #define BUTTONPRESSED LOW
      #define RELAYACTIVE LOW
      
      MyMessage sensorMsg0(0, V_DIMMER);
      MyMessage sensorMsg1(1, V_DIMMER);
      MyMessage sensorMsg2(2, V_DIMMER);
      
      enum {NOACTION, UPACTION, DOWNACTION};
      
      struct roll_t {
        byte downPin;
        byte upPin;
        boolean downPressed;
        boolean upPressed;
        byte action;
        unsigned long actionStarttime;
        unsigned long actionTimeout;
        byte relayOnePin;
        byte relayTwoPin;
      };
      
      roll_t rollladen[] = {
        {2, 3, false, false, NOACTION, 0, 60000L, A0, A1}, // Button-Pins 2, 3, Relay-Pins A0, A1, Timeout 60 secons
        {4, 5, false, false, NOACTION, 0, 45000L, A2, A3}, // Button-Pins 4, 5, Relay-Pins A2, A3, Timeout 45 secons
        {6, 7, false, false, NOACTION, 0, 45000L, A4, A5}, // Button-Pins 6, 7, Relay-Pins A4, A5, Timeout 45 secons
      };
      
      #define ANZAHLROLLLADEN sizeof(rollladen)/sizeof(rollladen[0])
      
      
      void setup()
      {
        Serial.begin(115200);
        for (int i = 0; i < ANZAHLROLLLADEN; i++)
        {
          if (BUTTONPRESSED == HIGH)
          {
            pinMode(rollladen[i].downPin, INPUT);
            pinMode(rollladen[i].upPin, INPUT);
          }
          else
          {
            pinMode(rollladen[i].downPin, INPUT_PULLUP);
            pinMode(rollladen[i].upPin, INPUT_PULLUP);
          }
          if (RELAYACTIVE == LOW)
          {
            digitalWrite(rollladen[i].relayOnePin, HIGH);
            digitalWrite(rollladen[i].relayTwoPin, HIGH);
          }
          pinMode(rollladen[i].relayOnePin, OUTPUT);
          pinMode(rollladen[i].relayTwoPin, OUTPUT);
        }
      }
      
      
      void switchRelay(byte i)
      {
        Serial.print("Schalte Rolladen-");
        Serial.print(i);
        switch (rollladen[i].action)
        {
          case NOACTION: // STOP
            digitalWrite(rollladen[i].relayOnePin, !RELAYACTIVE);
            digitalWrite(rollladen[i].relayTwoPin, !RELAYACTIVE);
            Serial.println(" STOP");
            break;
          case UPACTION: // UP
            digitalWrite(rollladen[i].relayOnePin, RELAYACTIVE);
            digitalWrite(rollladen[i].relayTwoPin, !RELAYACTIVE);
            Serial.println(" UP");
            break;
          case DOWNACTION: // DOWN
            digitalWrite(rollladen[i].relayOnePin, !RELAYACTIVE);
            digitalWrite(rollladen[i].relayTwoPin, RELAYACTIVE);
            Serial.println(" DOWN");
            break;
        }
      }
      
      
      
      void loop(void)
      {
        byte state;
        for (int i = 0; i < ANZAHLROLLLADEN; i++)
        {
          // Prüfen, ob Down gedrückt wurde
          state = digitalRead(rollladen[i].downPin);
          if (BUTTONPRESSED == LOW) state = !state;
          if (state && !rollladen[i].downPressed)
          {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action = DOWNACTION;
                rollladen[i].actionStarttime = millis();
                switchRelay(i);
                break;
              default: if (rollladen[i].action != NOACTION)
                {
                  rollladen[i].action = NOACTION;
                  switchRelay(i);
                }
            }
          }
          rollladen[i].downPressed = state;
      
          // Prüfen, ob Up gedrückt wurde
          state = digitalRead(rollladen[i].upPin);
          if (BUTTONPRESSED == LOW) state = !state;
          if (state && !rollladen[i].upPressed)
          {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action = UPACTION;
                rollladen[i].actionStarttime = millis();
                switchRelay(i);
                break;
              default: if (rollladen[i].action != NOACTION)
                {
                  rollladen[i].action = NOACTION;
                  switchRelay(i);
                }
            }
          }
          rollladen[i].upPressed = state;
      
          // Prüfen auf Timeout
          if (rollladen[i].action != NOACTION && millis() - rollladen[i].actionStarttime >= rollladen[i].actionTimeout)
          {
            rollladen[i].action = NOACTION;
            switchRelay(i);
          }
        }
        delay(5); // kleines Delay zum Entprellen der Buttons
      }
      
      void presentation()
      {
      
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Test", "1.0");
      
        // Fetch relay status
        for (int sensor = 1, pin = A0; sensor <= ANZAHLROLLLADEN; sensor++, pin++) {
      
          // Register all sensors to gw (they will be created as child devices)
          present(sensor, S_COVER);
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);
        }
      }
      
      
      void receive(const MyMessage &message) {
        byte state;
        int i = message.sensor ;
      
        if (message.type == V_UP) {
          {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action = UPACTION;
                rollladen[i].actionStarttime = millis();
                switchRelay(i);
                break;
              default: if (rollladen[i].action != NOACTION)
                {
                  rollladen[i].action = NOACTION;
                  switchRelay(i);
                }
      
            }
          }
          rollladen[i].upPressed = state;
      
          Serial.println("going up:" + String(message.type));
        }
        else if (message.type == V_DOWN) {
          {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action = DOWNACTION;
                rollladen[i].actionStarttime = millis();
                switchRelay(i);
                break;
              default: if (rollladen[i].action != NOACTION)
                {
                  rollladen[i].action = NOACTION;
                  switchRelay(i);
                }
            }
          }
          rollladen[i].downPressed = state;
      
          Serial.println("going down:" + String(message.type));
        }
        else if (message.type == V_STOP) {
          {
            switch (rollladen[i].action)
            {
              case DOWNACTION: rollladen[i].action = NOACTION;
                rollladen[i].actionStarttime = millis();
                switchRelay(i);
                break;
      
              case UPACTION: rollladen[i].action = NOACTION;
                rollladen[i].actionStarttime = millis();
                switchRelay(i);
                break;
            }
          }
          Serial.println("stopping:" + String(message.type));
        }
      }
      

      hope it's clear what I mean. It is a bit weird...

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: problem with implementation of my sensors in rollershutter sketch

      @AWI
      thx, I tried that. it exits with 'const class MyMessage' has no member named 'sensors'.

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: problem with implementation of my sensors in rollershutter sketch

      @AWI
      😄 the result was indeed interesting and fun to watch.

      void receive(const MyMessage &message) {
        byte state;
        i = message.sensors
        
        if (message.type == V_UP) {
        {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action=UPACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
              default: if (rollladen[i].action!=NOACTION)
                       {
                         rollladen[i].action=NOACTION;
                         switchRelay(i);
                       }
          
           }
          }
          rollladen[i].upPressed=state;
          
          Serial.println("going up:" + String(message.type));
        }
        else if (message.type == V_DOWN) {
      {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action=DOWNACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
              default: if (rollladen[i].action!=NOACTION)
                       {
                         rollladen[i].action=NOACTION;
                         switchRelay(i);
                       }
            }
          }
          rollladen[i].downPressed=state;
          
          Serial.println("going down:" + String(message.type));
        }
        else if (message.type == V_STOP) {
          {
            switch (rollladen[i].action)
            {
              case DOWNACTION: rollladen[i].action=NOACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
      
              case UPACTION: rollladen[i].action=NOACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
            }
          }
          Serial.println("stopping:" + String(message.type));
          } 
        }
      

      I replaced the for loop with i = sensor.message , now i get "exit status 1
      'i' was not declared in this scope". Do I have to declare the variable?

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: problem with implementation of my sensors in rollershutter sketch

      @AWI
      I don't get it. I inserted for (int i=0;i<message.sensor;i++) and the result is
      switch 1 up= relay 1; switch 1 down= relay 2
      switch 2 up= relay 1+3 ; switch 2 down=relay 2+4
      switch 3 up= relay 1+3+5; switch 3 down=relay 2+4+6

      shouldn't i++ give each following message.sensor it's own number?

      maybe I am just too tired to get it.

      thanks for your help, I'm going to sleep now

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd
    • RE: problem with implementation of my sensors in rollershutter sketch

      @AWI
      thank you, that helped a lot.
      I received my first arduino 3 weeks ago and since then I'm constantly learning. Getting things explained helps a lot.

      the code receives my commands now but when I press down, all the down relays switch on/off and the other way around. I thought the line for (int i=0;i<ANZAHLROLLLADEN;i++) declares the number of the rollershutter.

      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      #include <MySensors.h>
      #include <SPI.h>
      
      // Rollladensteuerung by jurs for German Arduino-Forum
      #define BUTTONPRESSED LOW
      #define RELAYACTIVE LOW
      
      MyMessage sensorMsg0(0,V_DIMMER);
      MyMessage sensorMsg1(1,V_DIMMER);
      MyMessage sensorMsg2(2,V_DIMMER);
      
      enum {NOACTION, UPACTION, DOWNACTION};
      
      struct roll_t{byte downPin; byte upPin; boolean downPressed; boolean upPressed; byte action; unsigned long actionStarttime; unsigned long actionTimeout; byte relayOnePin; byte relayTwoPin;};
      
      roll_t rollladen[]={
        {2,3,false, false, NOACTION,0,60000L, A0, A1}, // Button-Pins 2, 3, Relay-Pins A0, A1, Timeout 60 secons
        {4,5,false, false, NOACTION,0,45000L, A2, A3}, // Button-Pins 4, 5, Relay-Pins A2, A3, Timeout 45 secons
        {6,7,false, false, NOACTION,0,45000L, A4, A5}, // Button-Pins 6, 7, Relay-Pins A4, A5, Timeout 45 secons
      };
      
      #define ANZAHLROLLLADEN sizeof(rollladen)/sizeof(rollladen[0])
      
      
      void setup()
      {
        Serial.begin(115200);
        for (int i=0;i<ANZAHLROLLLADEN;i++)
        {
          if (BUTTONPRESSED==HIGH)
          {
            pinMode(rollladen[i].downPin,INPUT);
            pinMode(rollladen[i].upPin,INPUT);
          }
          else
          {
            pinMode(rollladen[i].downPin,INPUT_PULLUP);
            pinMode(rollladen[i].upPin,INPUT_PULLUP);
          }
          if (RELAYACTIVE==LOW)
          {
             digitalWrite(rollladen[i].relayOnePin,HIGH);
             digitalWrite(rollladen[i].relayTwoPin,HIGH);
          }
          pinMode(rollladen[i].relayOnePin,OUTPUT);
          pinMode(rollladen[i].relayTwoPin,OUTPUT);
        }
      }
      
      
      void switchRelay(byte i)
      {
        Serial.print("Schalte Rolladen-");
        Serial.print(i);
        switch (rollladen[i].action)
        {
          case NOACTION: // STOP
            digitalWrite(rollladen[i].relayOnePin,!RELAYACTIVE);
            digitalWrite(rollladen[i].relayTwoPin,!RELAYACTIVE);
            Serial.println(" STOP");
            break;
          case UPACTION: // UP
            digitalWrite(rollladen[i].relayOnePin,RELAYACTIVE);
            digitalWrite(rollladen[i].relayTwoPin,!RELAYACTIVE);
            Serial.println(" UP");
            break;
          case DOWNACTION: // DOWN
            digitalWrite(rollladen[i].relayOnePin,!RELAYACTIVE);
            digitalWrite(rollladen[i].relayTwoPin,RELAYACTIVE);
            Serial.println(" DOWN");
            break;
        }
      }
      
      
      
      void loop(void) 
      {
        byte state;
        for (int i=0;i<ANZAHLROLLLADEN;i++)
        {
          // Prüfen, ob Down gedrückt wurde
          state=digitalRead(rollladen[i].downPin);
          if (BUTTONPRESSED==LOW) state=!state;
          if (state && !rollladen[i].downPressed)
          {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action=DOWNACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
              default: if (rollladen[i].action!=NOACTION)
                       {
                         rollladen[i].action=NOACTION;
                         switchRelay(i);
                       }
            }
          }
          rollladen[i].downPressed=state;
          
          // Prüfen, ob Up gedrückt wurde
          state=digitalRead(rollladen[i].upPin);
          if (BUTTONPRESSED==LOW) state=!state;
          if (state && !rollladen[i].upPressed)
          {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action=UPACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
              default: if (rollladen[i].action!=NOACTION)
                       {
                         rollladen[i].action=NOACTION;
                         switchRelay(i);
                       }
            }
          }
          rollladen[i].upPressed=state;
          
          // Prüfen auf Timeout
          if (rollladen[i].action!=NOACTION && millis()-rollladen[i].actionStarttime>=rollladen[i].actionTimeout)
          {
            rollladen[i].action=NOACTION;
            switchRelay(i);
          }
        }
        delay(5); // kleines Delay zum Entprellen der Buttons
      }
      
      void presentation()
      {
      
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Test", "1.0");
      
        // Fetch relay status
         for (int sensor = 1, pin = A0; sensor <= ANZAHLROLLLADEN; sensor++, pin++) {
        
          // Register all sensors to gw (they will be created as child devices)
            present(sensor, S_COVER);
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);
        } 
      }
      
      
      void receive(const MyMessage &message) {
        byte state;
        for (int i=0;i<ANZAHLROLLLADEN;i++)
       
        if (message.type == V_UP) {
        {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action=UPACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
              default: if (rollladen[i].action!=NOACTION)
                       {
                         rollladen[i].action=NOACTION;
                         switchRelay(i);
                       }
            }
          }
          rollladen[i].upPressed=state;
          
          Serial.println("going up:" + String(message.type));
        }
        else if (message.type == V_DOWN) {
      {
            switch (rollladen[i].action)
            {
              case NOACTION: rollladen[i].action=DOWNACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
              default: if (rollladen[i].action!=NOACTION)
                       {
                         rollladen[i].action=NOACTION;
                         switchRelay(i);
                       }
            }
          }
          rollladen[i].downPressed=state;
          
          Serial.println("going down:" + String(message.type));
        }
        else if (message.type == V_STOP) {
          {
            switch (rollladen[i].action)
            {
              case DOWNACTION: rollladen[i].action=NOACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
      
              case UPACTION: rollladen[i].action=NOACTION;
                             rollladen[i].actionStarttime=millis();
                             switchRelay(i);
                             break;
            }
          }
          Serial.println("stopping:" + String(message.type));
        }
      }
      
      

      Do you have any idea whats wrong?
      thx

      posted in Troubleshooting
      ihtgtwtd
      ihtgtwtd