Announcement

Collapse
No announcement yet.

Smart Blind Control

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Forrest,

    I have added code to store the position in the eeprom so that it is not reset on connection and added debug logging so I could test what was happening. If you connect to the device with the serial monitor in the Arduino IDE at Baud rate of 115200 then you will see what is going on in the board and this will tell you if the driver is doing thing sit should not.

    Looking at the device setup you should have:
    0 = Down
    23 = UP
    12 = Open
    1 - 22 = %

    then you will need to manually close the blind and make sure the device is set to 0/Down when the device is first powered up and it should track its position.


    I think I have marked all code changes with // Change in V1.1 to help you see what has changed.


    Code:
    //**************Declare your variables here*******************
    
    #define DebugFlag true// Change in V1.1
    #define MaxValue 150
    
    #include <AH_EasyDriver.h> //http://www.alhin.de/arduino/downloads/AH_EasyDriver_20120512.zip
    #include <SimpleTimer.h> //https://github.com/thehookup/Simple-Timer-Library
    #include <EEPROM.h>// Change in V1.1
    
    #define STEPPER_SPEED 35 //Defines the speed in RPM for your stepper motor
    #define STEPPER_STEPS_PER_REV 1028 //Defines the number of pulses that is required for the stepper to rotate 360 degrees
    #define STEPPER_MICROSTEPPING 0 //Defines microstepping 0 = no microstepping, 1 = 1/2 stepping, 2 = 1/4 stepping
    #define DRIVER_INVERTED_SLEEP 1 //Defines sleep while pin high. If your motor will not rotate freely when on boot, comment this line out.
    
    
    #define STEPPER_DIR_PIN D6
    #define STEPPER_STEP_PIN D7
    #define STEPPER_SLEEP_PIN D5
    #define STEPPER_MICROSTEP_1_PIN 14
    #define STEPPER_MICROSTEP_2_PIN 12
    
    
    
    // Change in V1.1 remove unsigned long send_rotations;
    int currentPosition = 0;
    int newPosition = 0;
    bool moving = false;
    // Change in V1.1
    
    SimpleTimer timer;
    AH_EasyDriver shadeStepper(STEPPER_STEPS_PER_REV, STEPPER_DIR_PIN ,STEPPER_STEP_PIN,STEPPER_MICROSTEP_1_PIN,STEPPER_MICROSTEP_ 2_PIN,STEPPER_SLEEP_PIN);
    //************************************************************ ****
    
    
    void HSSetup() {
    
    
    EEPROM.begin(512);// Change in V1.1
    #if DebugFlag // Change in V1.1
    Serial.begin(115200);// Change in V1.1
    Serial.println("Startup..."); // Change in V1.1
    #endif// Change in V1.1
    //************************
    //Add YOUR SETUP HERE;
    //************************
    // Change in V1.1 remove pinMode(D1, INPUT_PULLUP);
    shadeStepper.setMicrostepping(STEPPER_MICROSTEPPING); // 0 -> Full Step
    shadeStepper.setSpeedRPM(STEPPER_SPEED); // set speed in RPM, rotations per minute
    #if DRIVER_INVERTED_SLEEP == 1
    shadeStepper.sleepOFF();
    #endif
    #if DRIVER_INVERTED_SLEEP == 0
    shadeStepper.sleepON();
    #endif
    
    timer.setInterval(((1 << STEPPER_MICROSTEPPING)*5800)/STEPPER_SPEED, processStepper);
    
    currentPosition = EEPROM.read(1);// Change in V1.1
    if (currentPosition > MaxValue){// Change in V1.1
    currentPosition = FromHS[0];// Change in V1.1
    }// Change in V1.1
    
    FromHS[0] = currentPosition;// Change in V1.1
    newPosition = currentPosition;// Change in V1.1
    #if DebugFlag // Change in V1.1
    Serial.print("Position Loaded from eeprom = "); // Change in V1.1
    Serial.println(currentPosition); // Change in V1.1
    #endif // Change in V1.1
    }
    
    
    
    
    
    
    void HSloop() {
    //************************
    //Add YOUR CODE HERE;
    //************************
    /* To Send Data to Homeseer use SendToHS(Device,Value)
    Eg.. SendToHS(1,200); where 1 is the API device in homeseer and 200 is the value to send
    To Recieve data from Homeseer look up the FromHS array that is updated when the device value changes.
    Eg.. FromHS[5] would be the data from API Output device 5
    All code that is located just below this block will execute regardless of connection status!
    You can include SendToHS() calls, however when there isn't an active connection, it will just return and continue.
    If you only want code to execute when HomeSeer is connected, put it inside the if statement below.
    */
    
    /*Execute regardless of connection status*/
    
    
    if (IsConnected == true) {
    /*Execute ONLY when HomeSeer is connected*/
    
    timer.run();
    
    if(FromHS[0]!=newPosition){
    newPosition=FromHS[0];
    #if DebugFlag // Change in V1.1
    Serial.print("Position from HS Changed to = "); // Change in V1.1
    Serial.println(newPosition); // Change in V1.1
    #endif // Change in V1.1
    }
    
    }
    }
    
    
    //Voids After here.
    
    void processStepper()
    {
    if (newPosition > currentPosition)
    {
    #if DRIVER_INVERTED_SLEEP == 1
    shadeStepper.sleepON();
    #endif
    #if DRIVER_INVERTED_SLEEP == 0
    shadeStepper.sleepOFF();
    #endif
    shadeStepper.move(80, FORWARD);
    currentPosition++;
    moving = true;
    EEPROM.write(1, currentPosition);// Change in V1.1
    EEPROM.commit(); // Change in V1.1
    #if DebugFlag // Change in V1.1
    Serial.print("currentPosition Changed to = "); // Change in V1.1
    Serial.println(currentPosition); // Change in V1.1
    #endif // Change in V1.1
    }
    if (newPosition < currentPosition)
    {
    #if DRIVER_INVERTED_SLEEP == 1
    shadeStepper.sleepON();
    #endif
    #if DRIVER_INVERTED_SLEEP == 0
    shadeStepper.sleepOFF();
    #endif
    shadeStepper.move(80, BACKWARD);
    currentPosition--;
    moving = true;
    EEPROM.write(1, currentPosition);// Change in V1.1
    EEPROM.commit(); // Change in V1.1
    #if DebugFlag // Change in V1.1
    Serial.print("currentPosition Changed to = "); // Change in V1.1
    Serial.println(currentPosition); // Change in V1.1
    #endif // Change in V1.1
    }
    if (newPosition == currentPosition && moving == true)
    {
    #if DRIVER_INVERTED_SLEEP == 1
    shadeStepper.sleepOFF();
    #endif
    #if DRIVER_INVERTED_SLEEP == 0
    shadeStepper.sleepON();
    #endif
    // Change in V1.1 Remove String temp_str = String(currentPosition);
    moving = false;
    #if DebugFlag// Change in V1.1
    Serial.print("Stopped at = ");// Change in V1.1
    Serial.println(currentPosition);// Change in V1.1
    #endif// Change in V1.1
    }
    }
    Zwave = Z-Stick, 3xHSM100� 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment

    Working...
    X