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
R

romeok01

@romeok01
About
Posts
9
Topics
2
Shares
0
Groups
0
Followers
1
Following
0

Posts

Recent Best Controversial

  • Curtain Control Node.
    R romeok01

    I write a program on library Stepper not AccelStepper.
    Now is working.

    Program code:

    // 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 <Stepper.h>
    
    #define CURTAIN_CLOSED 1000  // wartosc gdy kurtyna zamknieta
    #define CURTAIN_OPEN -1000         // wartosc gdy kurtyna otwarta 
    #define CHILD_ID 1
    
    // definicje MySensors 
    
    MyMessage message(CHILD_ID, S_COVER);
    
    int in1Pin = 3;
    int in2Pin = 4;
    int in3Pin = 5;
    int in4Pin = 6;
    int lastState;
     
    // liczba kroków na jeden obrót
    #define stepsPerRevolution 200
    
    //ustawienie szybkości silnika 
    int motorSpeed = 40;
    
    Stepper myStepper(stepsPerRevolution, in1Pin, in2Pin, in3Pin, in4Pin);
    
    void setup() {
      
    // ustawienie pinów jako wyjście
      pinMode(in1Pin, OUTPUT);
      pinMode(in2Pin, OUTPUT);
      pinMode(in3Pin, OUTPUT);
      pinMode(in4Pin, OUTPUT);
    // ustawienie szybkosci silnika
      myStepper.setSpeed(motorSpeed);
    }
    
    void presentation()  
    { 
      // Wyslanie informacji o wersji programu
      sendSketchInfo("Program kurtyna", "1.0");
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID, S_COVER); // Window Cover sub-type, commands: V_UP, V_DOWN, V_STOP
    }
    
    void receive(const MyMessage &message) {
      // if message = V_UP start moving until closed
      if (message.type==V_UP) {
         myStepper.step(CURTAIN_OPEN);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         request(CHILD_ID, V_UP, 0); // request new values from controller
            }
         
     if (message.type==V_DOWN) {
         myStepper.step(CURTAIN_CLOSED);
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
         request(CHILD_ID, V_DOWN, 0); // request new values from controller
            } 
    }
    
    

    I use MySensors Library 2.0

    Youtube film

    https://www.youtube.com/embed/gm0r2kDXrt4

    My Project domoticz curtain control mysensors node

  • Curtain Control Node.
    R romeok01

    Hello.

    To my project i use stepper motor JK42HS34-0404 and driver L298N.

    This is a wiring diagram.
    alt text

    This is a program code that I use

    #include <MySensor.h>  
    #include <SPI.h>
    #include <AccelStepper.h>
    #define HALFSTEP 4  // Stepper uses "Halfstep" mode
    #define CURTAIN_CLOSED 1000 // value when closed
    #define CURTAIN_OPEN 0 // value when open
    #define CHILD_ID 1   // Id of the sensor child
    // MySensors definitions
    MySensor gw;
    // Initialize message
    MyMessage msg(CHILD_ID, V_TRIPPED);
    
    
    // Motor pin definitions
    #define motorPin1  3     // IN1 on the ULN2003 driver 1
    #define motorPin2  4     // IN2 on the ULN2003 driver 1
    #define motorPin3  5     // IN3 on the ULN2003 driver 1
    #define motorPin4  6     // IN4 on the ULN2003 driver 1
    
    // Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
    AccelStepper stepper1(HALFSTEP, motorPin1, motorPin2, motorPin3, motorPin4);
    
    unsigned long current_position ; // remembers current position, need to be saved in EEPROM?
    
    void setup() {
      // MySensors
      gw.begin(); // fixed node 13
      gw.sendSketchInfo("Curtain control 13", "1.0"); // Send the sketch version information to the gateway and Controller
    
      //pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID, S_COVER); // Window Cover sub-type, commands: V_UP, V_DOWN, V_STOP
      
      stepper1.setMaxSpeed(500.0);
      stepper1.setAcceleration(700.0);
      stepper1.moveTo(CURTAIN_OPEN);
      
      current_position = CURTAIN_OPEN ;
      stepper1.moveTo(CURTAIN_OPEN);
    }//--(end setup )---
    
    void loop() {
      // if message = V_UP start moving until closed
      // if message = V_DOWN start moving back until open
      // if message = V_STOP stop moving
      // Test: Change direction when the stepper reaches the target position
      gw.process(); // check if message from controller
      if (stepper1.distanceToGo() == 0){
        if (stepper1.currentPosition() == CURTAIN_OPEN){
          stepper1.moveTo(CURTAIN_CLOSED);
          Serial.println("Curtain Open, now closing");
          gw.request(CHILD_ID, V_UP, 0); // request new values from controller  
        }
        else{
          stepper1.moveTo(CURTAIN_OPEN);
          Serial.println("Curtain Closed, now opening");
          gw.request(CHILD_ID, V_DOWN, 0); // request new values from controller   
        }
      }
      
      stepper1.run();
    }
    
    // This is called when a message is received 
    void incomingMessage(const MyMessage &message) {
      // We only expect few types of messages from controller, check which
      stepper1.moveTo(message.getInt() * CURTAIN_CLOSED/100);
      Serial.print("Message - valid: ");
      Serial.print(message.sensor);
      Serial.print(" , value: % ");
      Serial.println(message.getInt());
      switch (message.getInt()) {
      case 100:
        // Curtain should be opened
         Serial.print("Message - valid: ");
         Serial.print(message.sensor);
         Serial.print(", Message UP ");
         stepper1.moveTo(CURTAIN_OPEN);
         break;
      case 0:
        // Curtain should be closed
         Serial.print("Message - valid: ");
         Serial.print(message.sensor);
         Serial.print(", Message DOWN ");
         stepper1.moveTo(CURTAIN_CLOSED);
        break;
      case 50:
        // Curtain action should be stopped
         Serial.print("Message - valid: ");
         Serial.print(message.sensor);
         Serial.print(", Message STOP ");
        break;
      default: 
        // not recognizable message
         Serial.print("Message - valid: ");
         Serial.print(message.sensor);
         Serial.print(", Unrecognized ");
    
      }
     
    }
    

    When the program I have uploaded to my mysensors, the engine still turns, one left and one to the right and did not work the button blinds in Domoticz.

    I cant turn off my stepper motor in Domoticz.

    https://www.youtube.com/embed/1Wc1p_9YDQQ

    Please help me.

    My Project domoticz curtain control mysensors node

  • Curtain Control Node.
    R romeok01

    Now the wiring diagram should be visible.

    My Project domoticz curtain control mysensors node
  • Login

  • Don't have an account? Register

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