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 program with AccelStepper library

    / 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 <AccelStepper.h>      //import biblioteki AccelStepper 
    
    #define HALFSTEP 8
    #define CURTAIN_CLOSED 2000  // wartosc gdy kurtyna zamknieta
    #define CURTAIN_OPEN 0       // wartosc gdy kurtyna otwarta
    #define CHILD_ID 1
    
    // definicje MySensors
    
    MyMessage message(CHILD_ID, S_COVER);
    
    // Definicja pinow silnika
    #define IN1  3     // IN1 - zielony
    #define IN2  4     // IN2 - czarny
    #define IN3  5     // IN3 - niebieski
    #define IN4  6     // IN4 - czerwony
     
    AccelStepper stepper1(HALFSTEP, IN1, IN2, IN3, IN4);
    
    void setup()
    {
      stepper1.setMaxSpeed(200.0);
      stepper1.setAcceleration(1000.0);
      stepper1.setSpeed(200);
      stepper1.moveTo(CURTAIN_OPEN);
    }
    
    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 loop()
    {
      stepper1.run();  //Start
    }
    
    void receive(const MyMessage &message)
    {
      // if message = V_UP start moving until closed
      if (message.type==V_UP) {
         if (stepper1.distanceToGo() == 0){
             if (stepper1.currentPosition() == CURTAIN_OPEN){
                 stepper1.moveTo(CURTAIN_CLOSED);
         // 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) {
           stepper1.moveTo(CURTAIN_OPEN);
           // Store state in eeprom
           saveState(message.sensor, message.getBool());
           request(CHILD_ID, V_DOWN, 0); // request new values from controller   
        }
        if (message.type==V_STOP) {
            stepper1.setCurrentPosition(0);
            // Store state in eeprom
            saveState(message.sensor, message.getBool());
            request(CHILD_ID, V_STOP, 0); // request new values from controller
        }
    }
    
    

    I use MySensors library 2.0

    Now i working.

    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

  • 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

  • Coal or water level sensor
    R romeok01

    Coal or water level sensor
    http://projektpimalina.blogspot.com/2016/05/czujnik-poziomu-wegla-na-nadajniku.html

    https://www.youtube.com/embed/3ShomcZfV-w

    #include <MySensor.h>
    #include <SPI.h>          //import biblioteki MySenors
    
    #define trigPin 3
    #define echoPin 4
    int max = 60; //maksymalna odleglosc w cm gdy zbiornik bedzie pusty
    int procent; //odleglosc w procentach
    int ilosc; //ilosc w procentach napelnienia zbiornika
    
    #define child_id_ilosc 1   //definicja identyfikacji ilosci wegla w kontenerze
    
    MySensor gw;
    MyMessage msgilosc(child_id_ilosc, V_IMPEDANCE); //utworzenie konteneru do przechowywania danych
     
    void setup() {
      
      pinMode(trigPin, OUTPUT); //Pin, do którego podłączymy trig jako wyjście
      pinMode(echoPin, INPUT); //a echo, jako wejście
     
      gw.begin();   //uruchomienie biblioteki MySensors
      gw.sendSketchInfo("Czujunik ilosci wegla", "1.0");
      
      gw.present(child_id_ilosc, S_WEIGHT); //prezentacja danych do kontrolera
    }
     
    void loop() {
      
      long czas, dystans;
     
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
     
      czas = pulseIn(echoPin, HIGH);
      dystans = czas / 58;
      
      procent = ((dystans * 100) / max);
      ilosc = 100 - procent;
      
      gw.send(msgilosc.set(ilosc)); //przeslanie ilosci wegla do domoticz
      
      delay(1000);    // opóźnienie
    }
    My Project

  • Office plant monitoring
    R romeok01

    Thank you very much works very well for Domoticz :+1:
    Schowek-3.jpg Schowek-2.jpg 2015-10-10 18.27.06.jpg

    My Project

  • Domoticz 4 x relay
    R romeok01

    @TheoL Thank you very much, really helped me, now the program code work :smile:

    Development

  • Domoticz 4 x relay
    R romeok01

    I used leds to perform a functional test code.

    I connected LEDs to pins 3, 4, 5, 6 and GND.

    Development

  • Domoticz 4 x relay
    R romeok01

    I wrote code to 4 relays:

    #include <MySigningNone.h>
    #include <MyTransportNRF24.h>
    #include <MyTransportRFM69.h>
    #include <MyHwATMega328.h>
    #include <MySensor.h>
    #include <SPI.h>
    
    #define RELAY_1  3  // Pin D3
    #define RELAY_2  4  // Pin D4
    #define RELAY_3  5  // Pin D5
    #define RELAY_4  6  // Pin D6
    #define NUMBER_OF_RELAYS 4 // Liczba przekaznikow
    #define RELAY_ON 1  // Stan wysoki przekaznik wlaczony
    #define RELAY_OFF 0 // Stan niski przekaznik wylaczony
    
    // NRFRF24L01 radio driver (set low transmit power by default) 
    MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);  
    //MyTransportRFM69 radio;
    // Message signing driver (none default)
    //MySigningNone signer;
    // Select AtMega328 hardware profile
    MyHwATMega328 hw;
    // Construct MySensors library
    MySensor gw(radio, hw);
    
    void setup() {   
      // Initialize library and add callback for incoming messages
      gw.begin(incomingMessage, AUTO, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Relay", "1.0");
    
      // Fetch relay status
      for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++)
      for (int sensor=1, pin=RELAY_2; sensor<=NUMBER_OF_RELAYS;sensor++, pin++)
      for (int sensor=1, pin=RELAY_3; sensor<=NUMBER_OF_RELAYS;sensor++, pin++)
      for (int sensor=1, pin=RELAY_4; sensor<=NUMBER_OF_RELAYS;sensor++, pin++){
        // Register all sensors to gw (they will be created as child devices)
        gw.present(sensor, S_LIGHT);
        // Then set relay pins in output mode
        pinMode(pin, OUTPUT);   
        // Set relay to last known state (using eeprom storage) 
        digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
      }
    }
    
    
    void loop() 
    {
      // Alway process incoming messages whenever possible
      gw.process();
    }
    
    void incomingMessage(const MyMessage &message) {
      // We only expect one type of message from controller. But we better check anyway.
      if (message.type==V_LIGHT) {
         // Change relay state
         digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
         // Store state in eeprom
         gw.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());
       } 
    }
    

    Domoticz detected 4 switches

    Schowek-1.jpg

    I added 4 switches in Domoticz
    Schowek-2.jpg

    I connected the LED to pins 3,4,5,6 and when I turn on switch in Domoticz the LEDs do not want to turn on.

    What is poorly written code?

    Development
  • Login

  • Don't have an account? Register

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