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
P

Panos Toumpaniaris

@Panos Toumpaniaris
About
Posts
5
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • LED Dimming library
    P Panos Toumpaniaris

    Ok, before reading further, take note that this is my very first attempt at anything c++ like, with virtually no programming background.
    I cannot be held responsible for anything or everything going wrong, although it's probably relatevily safe..
    However if you led strips come to life and start chasing your cat, please do post a video!

    Having said that, here's the problem: Having two or more led lights/strips to be dimmed on the same node. You can have up to 6 on Nano, 14 on Mega and 11 on Due, so there are a lot of options.

    The example sketch in the Build section uses the dreaded delay(), so nothing can be done while the light dims.
    Replacing it with gw.wait() makes the entire dimming process rather unpredictable if a message is received while dimming. Noone knows where it's going to stop.

    My (crude and amateurish) solution : https://github.com/ptoump/LedDimmer

    It's a library which provides you with a LedDimming class keeping the state machine philosophy of arduino multi-task programming.

    Each LedDimmer object comes with a constructor LedDimmer(int led_pin), a state changing routine dim(int time_step, int target_level) and an updater, update().

    Here's some example code :

    #define SN "DimLED_x2_bsm"
    #define SV "1.4"
    
    #include <MySensor.h> 
    #include <SPI.h>
    #include <MyTransportNRF24.h>
    #include <MyHwATMega328.h>
    #include <LedDimmer.h>
    
    // Uncomment the following line to enable debug
    // #define DEBUG_Local 
    
    #ifdef DEBUG_Local
    #define DEBUG_Local_SERIAL(x) Serial.begin(x)
    #define DEBUG_Local_PRINT(x) Serial.print(x)
    #define DEBUG_Local_PRINTLN(x) Serial.println(x)
    #else
    #define DEBUG_Local_SERIAL(x)
    #define DEBUG_Local_PRINT(x) 
    #define DEBUG_Local_PRINTLN(x) 
    #endif
    
    #define LED1_PIN 9      // Arduino pin attached to MOSFET Gate pin
    #define LED2_PIN 10      // Arduino pin attached to MOSFET Gate pin
    
    #define LED1_CHILD 0           // Id of 1st LED strip child
    #define LED2_CHILD 1           // Id of 2nd LED strip child
    
    // Please note the CE,CS PINS !!!!
    MyTransportNRF24 transport(7, 8, RF24_PA_MAX);
    MyHwATMega328 hw;
    MySensor gw(transport, hw);
    
    const int ledpins[] = {LED1_PIN,LED2_PIN};
    const int fade_period = 3 * 1000;     // fade time in ms
    
    LedDimmer dim1(ledpins[0]);
    LedDimmer dim2(ledpins[1]);
    
    MyMessage dim1Msg(LED1_CHILD, V_DIMMER);
    MyMessage dim2Msg(LED2_CHILD, V_DIMMER);
    
    
    /***
     * Dimmable LED initialization method
     */
     
    void setup()  
    { 
      DEBUG_Local_SERIAL(115200);    
      DEBUG_Local_PRINTLN("Serial started");
       
      gw.begin( incomingMessage );
      gw.sendSketchInfo(SN, SV);
        
      // Register the LED Dimmable Light with the gateway
      gw.present( LED1_CHILD, S_DIMMER );
      gw.present( LED2_CHILD, S_DIMMER );
        
      // Pull the gateway's current dim level - restore light level upon sendor node power-up
      gw.request( LED1_CHILD, V_DIMMER );
      gw.request( LED2_CHILD, V_DIMMER );
    }
    
    /***
     *  Dimmable LED main processing loop 
     */
    void loop() 
    {
      gw.process();
      dim1.update();
      dim2.update();
    }
    
    
    
    void incomingMessage(const MyMessage &message) {
      if (message.type == V_LIGHT || message.type == V_DIMMER) {
    
        int led2dim = message.sensor ;
        
        //  Retrieve the power or dim level from the incoming request message
        int requestedLevel = atoi( message.data );
        
        // Adjust incoming level if this is a V_LIGHT variable update [0 == off, 1 == on]
        requestedLevel *= ( message.type == V_LIGHT ? 100 : 1 );
        
        // Clip incoming level to valid range of 0 to 100
        requestedLevel = requestedLevel > 100 ? 100 : requestedLevel;
        requestedLevel = requestedLevel < 0   ? 0   : requestedLevel;
        
        DEBUG_Local_PRINT( "Changing led no [ ");
        DEBUG_Local_PRINT( led2dim );
        DEBUG_Local_PRINT( " ] level to " );
        DEBUG_Local_PRINTLN( requestedLevel );
        
         
        switch (led2dim) {
          case 0:
              dim1.dim(dim1.calcStep(fade_period, requestedLevel), requestedLevel); 
          break;
    
          case 1:
             dim2.dim(dim2.calcStep(fade_period, requestedLevel), requestedLevel);
          break;
        } //*/
      }  // ENDIF messagetype
    
    
        
    }
    

    Now group your dimmers together and have them change state at the same time..... Magic!!

    I hope you find it usefull!

    panos

    Development

  • Heatpump controller
    P Panos Toumpaniaris

    @ToniA said:

    @Panos-Toumpaniaris said:

    Am I missing something?

    Yes you are :smiley:

    You just have an uninitialized pointer to PanasonicNKEHeatpumpIR, while you should have this instead:

    PanasonicNKEHeatpumpIR *ACIR = new PanasonicNKEHeatpumpIR();
    

    Sorry I didn't answer sooner.. I was having too much fun with my working node!
    I just forgot a constructor and no matter how many times I went through my code I couldn't see it!
    Thanks so much Toni!

    One down 30 more nodes to go!

    Development

  • Compilation error in IDE as well as Codebender
    P Panos Toumpaniaris

    Have you followed the instructions in the download page?

    http://www.mysensors.org/download/

    Development code bender err

  • Compilation error in IDE as well as Codebender
    P Panos Toumpaniaris

    You should make sure you're using the appropriate API version. Codebender is on 1.4 AFAIK .

    For the ide have you perhaps update some of the libraries with ide updater?

    Development code bender err

  • Heatpump controller
    P Panos Toumpaniaris

    Hello,

    I'm trying to build a sensor node to control a Panasonic AirCon and I'm having trouble (using the latest MySensors and Heatpump-IR libs).
    Whenever the node tries to send IR it restarts. I tried switching RF24's CE and CS pins in case the timers conflict and tried to reduce sram usage as much as I could to no avail.

    I'm using a nano and RF24 wireless modules. The hardware works ok with other sketches (for example a simple relay ON/OFF).

    Here's the sketch:

    #include <Arduino.h>
    #include <MySensor.h>  
    #include <MyTransportNRF24.h>
    #include <SPI.h>
    #include <Timer.h>
    #include <avr/pgmspace.h>
    #include <PanasonicHeatpumpIR.h>
    
    
    #define ACW2_CHILD 2           // Id of the AC Warm 2 hours child
    #define ACW6_CHILD 3           // Id of the AC Warm 6 hours child
    
    
    
    MyTransportNRF24 radio(7, 8, RF24_PA_MAX);
    
    MySensor gw(radio);
    
    MyMessage acw2Msg(ACW2_CHILD, V_LIGHT);
    MyMessage acw6Msg(ACW6_CHILD, V_LIGHT);
    
    IRSender irsender(9);
    PanasonicNKEHeatpumpIR *ACIR;
    
    Timer t;
    
    boolean ac_state = false;
    
    
    void setup() {
    
    
      // Initialize library and add callback for incoming messages
      gw.begin(incomingMessage, AUTO, true);
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present( ACW2_CHILD, S_LIGHT );
      gw.present( ACW6_CHILD, S_LIGHT );
      gw.sendSketchInfo("AC", "1");
    
      
    }
    
    void loop() {
      // MySensors Process
      gw.process();
    
      
    
      // Timer Process
      t.update();
    
    }
    
    void incomingMessage(const MyMessage &message) {
    
      if (message.isAck()) {
             Serial.println(F("This is an ack from gateway"));
          }
          
      if (message.type == V_LIGHT) {
        boolean state = message.getBool();
        
        if (message.sensor == ACW2_CHILD) {
          
          if(state){
            Serial.println(F("--- received ACW2 - ON"));
         schedule_auto(6600000);
         //schedule_auto(6000);      
          }
          else
          {
            Serial.println(F("--- received ACW2 - OFF"));
            ac_off();
          }
          
        }
        
        if (message.sensor == ACW6_CHILD) {
          Serial.println(F("--- received ACW6"));
           if(state){
         schedule_quiet(21000000);      
             }
          else
          {
            ac_off();
          }
         }
        }
    }
    
    
    void schedule_auto(int dur) {
    
       Serial.println(F("--- sending auto"));
       ACIR->send(irsender, POWER_ON, MODE_HEAT, FAN_AUTO, 26, VDIR_MIDDLE, HDIR_AUTO);
       t.after(dur,ac_off);
       ac_state = true;
      
    }
    
    void schedule_quiet(int dur) {
    
       
       Serial.println(F("--- sending quiet"));
       ACIR->send(irsender, POWER_ON, MODE_HEAT, FAN_1, 25, VDIR_MIDDLE, HDIR_AUTO);
       t.after(dur,ac_off);
       ac_state = true;
      
    }
    
    void ac_off() {
      Serial.println(F("--- trying off"));
      if (ac_state) 
      {
        Serial.println(F("--- sending off"));
      ACIR->send(irsender, POWER_OFF, MODE_HEAT, FAN_1, 25, VDIR_MIDDLE, HDIR_AUTO);
    
      ac_state = false;
      gw.send(acw2Msg.set(false), true);
      gw.send(acw6Msg.set(false), true);
      }
     
    }
    
    

    Here's the Serial output:

    send: 2-2-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=ok:1.5.1
    send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-2 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    repeater started, id=2, parent=0, distance=1
    send: 2-2-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 2-2-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=2,sg=0,st=ok:AC
    send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=1,sg=0,st=ok:1
    read: 0-0-2 s=2,c=1,t=2,pt=0,l=1,sg=0:0
    send: 2-2-0-0 s=2,c=1,t=2,pt=0,l=1,sg=0,st=ok:0
    --- received ACW2 - OFF
    --- trying off
    read: 0-0-2 s=2,c=1,t=2,pt=0,l=1,sg=0:1
    send: 2-2-0-0 s=2,c=1,t=2,pt=0,l=1,sg=0,st=ok:1
    --- resend: 2-2-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=ok:1.5.1
    send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-2 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    repeater started, id=2, parent=0, distance=1
    send: 2-2-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 2-2-0-0 s=3,c=0,t=3,pt=0,l=0,sg=0,st=ok:
    send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=2,sg=0,st=ok:AC
    send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=1,sg=0,st=ok:1
    

    the node restarted at " --- resend" ... it should be "---received"...

    Am I missing something?

    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