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
  1. Home
  2. Controllers
  3. Domoticz
  4. RGB LED strip amplifier gives inverted RGB value

RGB LED strip amplifier gives inverted RGB value

Scheduled Pinned Locked Moved Domoticz
6 Posts 2 Posters 3.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ChakkieC Offline
    ChakkieC Offline
    Chakkie
    wrote on last edited by
    #1

    Hi all

    Insteads of using three Mosfet, I have connected my RGB led strip with my arduino using a RGB mini amplifier (see below). Since it is smaller and you don't have to solder any wires. I am able to control the led strip in Domoticz but the only problem is the RGB value is inverted. So when you choose blue in the colorpicker the led turns yellow. When you dim the light to 10% it is at its full brightness and when you set the level to 100% it turns off. (So the values are inverts). I have tested with a single dimmable led strip and it gave me the same result. It looks like that this module works as an inverted Mosfet.

    alt text

    Anyway I was wondering if you can solve this problem by modifying the script I am using. Like may be inverting the value.

    This is the script I am using

    #include <MySensor.h>
    #include <SPI.h>
    
    #define RED_PIN 3
    #define GREEN_PIN 5
    #define BLUE_PIN 6
    
    #define NODE_ID 70
    #define CHILD_ID 0
    #define SKETCH_NAME "RGB_STRIP "
    #define SKETCH_VERSION "1.0.0"
    #define NODE_REPEAT false
    
    MySensor gw;
    
    long RGB_values[3] = {0, 0, 0};
    float dimmer;
    
    void setup() {
    
    
      pinMode(RED_PIN, OUTPUT);
      pinMode(GREEN_PIN, OUTPUT);
      pinMode(BLUE_PIN, OUTPUT);
    
      gw.begin(incomingMessage, NODE_ID, NODE_REPEAT, 0);
      gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
      gw.present(CHILD_ID, S_RGB_LIGHT, "RGB Strip", false);
      gw.request(CHILD_ID, V_RGB);
    }
    
    void loop() {
      gw.process();
    }
    
    void incomingMessage(const MyMessage &message) {
    
      if (message.type == V_RGB) {
    
        String hexstring = message.getString();
        long number = (long) strtol( &hexstring[0], NULL, 16);
        RGB_values[0] = number >> 16;
        RGB_values[1] = number >> 8 & 0xFF;
        RGB_values[2] = number & 0xFF;
      }
      if (message.type == V_DIMMER) {
        dimmer = message.getInt();
        analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
        analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
        analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
      }
    
      if (message.type == V_LIGHT) {
        if (message.getInt() == 0) {
          digitalWrite(RED_PIN, 0);
          digitalWrite(GREEN_PIN, 0);
          digitalWrite(BLUE_PIN, 0);
    
        }
        if (message.getInt() == 1) {
          analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
          analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
          analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
        }
      }
    }
    

    Thanks

    Raspberry Pi 2
    Domoticz
    RFXCOM
    ZWAVE Aeon stick
    Coming soon Arduino mysensors GW

    TheoLT 1 Reply Last reply
    0
    • ChakkieC Chakkie

      Hi all

      Insteads of using three Mosfet, I have connected my RGB led strip with my arduino using a RGB mini amplifier (see below). Since it is smaller and you don't have to solder any wires. I am able to control the led strip in Domoticz but the only problem is the RGB value is inverted. So when you choose blue in the colorpicker the led turns yellow. When you dim the light to 10% it is at its full brightness and when you set the level to 100% it turns off. (So the values are inverts). I have tested with a single dimmable led strip and it gave me the same result. It looks like that this module works as an inverted Mosfet.

      alt text

      Anyway I was wondering if you can solve this problem by modifying the script I am using. Like may be inverting the value.

      This is the script I am using

      #include <MySensor.h>
      #include <SPI.h>
      
      #define RED_PIN 3
      #define GREEN_PIN 5
      #define BLUE_PIN 6
      
      #define NODE_ID 70
      #define CHILD_ID 0
      #define SKETCH_NAME "RGB_STRIP "
      #define SKETCH_VERSION "1.0.0"
      #define NODE_REPEAT false
      
      MySensor gw;
      
      long RGB_values[3] = {0, 0, 0};
      float dimmer;
      
      void setup() {
      
      
        pinMode(RED_PIN, OUTPUT);
        pinMode(GREEN_PIN, OUTPUT);
        pinMode(BLUE_PIN, OUTPUT);
      
        gw.begin(incomingMessage, NODE_ID, NODE_REPEAT, 0);
        gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
        gw.present(CHILD_ID, S_RGB_LIGHT, "RGB Strip", false);
        gw.request(CHILD_ID, V_RGB);
      }
      
      void loop() {
        gw.process();
      }
      
      void incomingMessage(const MyMessage &message) {
      
        if (message.type == V_RGB) {
      
          String hexstring = message.getString();
          long number = (long) strtol( &hexstring[0], NULL, 16);
          RGB_values[0] = number >> 16;
          RGB_values[1] = number >> 8 & 0xFF;
          RGB_values[2] = number & 0xFF;
        }
        if (message.type == V_DIMMER) {
          dimmer = message.getInt();
          analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
          analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
          analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
        }
      
        if (message.type == V_LIGHT) {
          if (message.getInt() == 0) {
            digitalWrite(RED_PIN, 0);
            digitalWrite(GREEN_PIN, 0);
            digitalWrite(BLUE_PIN, 0);
      
          }
          if (message.getInt() == 1) {
            analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
            analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
            analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
          }
        }
      }
      

      Thanks

      TheoLT Online
      TheoLT Online
      TheoL
      Contest Winner
      wrote on last edited by
      #2

      @Chakkie Hmmm it sounds odd. But if the software part can easily be changed. I'm not able to test it but this is what I would do. I'm not gonna modify the complete sketch. But I'd use an unsigned byte as the storage type for the RGB values. It uses less memory, but that's the only reason.

      void incomingMessage(const MyMessage &message) {
      
        if (message.type == V_RGB) {
      
          String hexstring = message.getString();
          long number = (long) strtol( &hexstring[0], NULL, 16);
          RGB_values[0] = 254 - ( number >> 16 );
          RGB_values[1] = 254 - ( number >> 8 & 0xFF );
          RGB_values[2] = 254 - ( number & 0xFF );
        }
        else if (message.type == V_DIMMER) {
          dimmer = message.getInt();
          analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
          analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
          analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
        }
        else if (message.type == V_LIGHT) {
          analogWrite( RED_PIN, message.getBool() == true ? 0 : int(RGB_values[0] * (dimmer / 100)) );
          analogWrite( GREEN_PIN, message.getBool() == true ? 0 : int(RGB_values[1] * (dimmer / 100)) );
          analogWrite( BLUE_PIN, message.getBool() == true ? 0 : int(RGB_values[2] * (dimmer / 100)) );
       }
        }
      }
      

      I've refactored the code a bit. As said I can't test it and haven't compiled it. But I hope it works and that it'll help you a bit in the good direction.

      ps. I didn't like soldering in the beginning but once you've mastered it is - to me at least - more satisfying to solder my own projects.

      Anyway good luck with it

      ChakkieC 1 Reply Last reply
      0
      • TheoLT TheoL

        @Chakkie Hmmm it sounds odd. But if the software part can easily be changed. I'm not able to test it but this is what I would do. I'm not gonna modify the complete sketch. But I'd use an unsigned byte as the storage type for the RGB values. It uses less memory, but that's the only reason.

        void incomingMessage(const MyMessage &message) {
        
          if (message.type == V_RGB) {
        
            String hexstring = message.getString();
            long number = (long) strtol( &hexstring[0], NULL, 16);
            RGB_values[0] = 254 - ( number >> 16 );
            RGB_values[1] = 254 - ( number >> 8 & 0xFF );
            RGB_values[2] = 254 - ( number & 0xFF );
          }
          else if (message.type == V_DIMMER) {
            dimmer = message.getInt();
            analogWrite(RED_PIN, int(RGB_values[0] * (dimmer / 100)));
            analogWrite(GREEN_PIN, int(RGB_values[1] * (dimmer / 100)));
            analogWrite(BLUE_PIN, int(RGB_values[2] * (dimmer / 100)));
          }
          else if (message.type == V_LIGHT) {
            analogWrite( RED_PIN, message.getBool() == true ? 0 : int(RGB_values[0] * (dimmer / 100)) );
            analogWrite( GREEN_PIN, message.getBool() == true ? 0 : int(RGB_values[1] * (dimmer / 100)) );
            analogWrite( BLUE_PIN, message.getBool() == true ? 0 : int(RGB_values[2] * (dimmer / 100)) );
         }
          }
        }
        

        I've refactored the code a bit. As said I can't test it and haven't compiled it. But I hope it works and that it'll help you a bit in the good direction.

        ps. I didn't like soldering in the beginning but once you've mastered it is - to me at least - more satisfying to solder my own projects.

        Anyway good luck with it

        ChakkieC Offline
        ChakkieC Offline
        Chakkie
        wrote on last edited by
        #3

        @TheoL

        Thank you so much TheoL. With your help I have added the 254 value as you told me. Once uploaded I can see that the color is closer to color I picked. So I have changed 254 to 255 and yes I 've got the right color. Now comes the next problem. I can no longer dim or turn off the led strip. When ever I choose the white ffffff or black 000000. The led stays at it full brightness. I guess we are close but only a little more tweak.

        Thanks you so much

        Raspberry Pi 2
        Domoticz
        RFXCOM
        ZWAVE Aeon stick
        Coming soon Arduino mysensors GW

        TheoLT 1 Reply Last reply
        0
        • ChakkieC Chakkie

          @TheoL

          Thank you so much TheoL. With your help I have added the 254 value as you told me. Once uploaded I can see that the color is closer to color I picked. So I have changed 254 to 255 and yes I 've got the right color. Now comes the next problem. I can no longer dim or turn off the led strip. When ever I choose the white ffffff or black 000000. The led stays at it full brightness. I guess we are close but only a little more tweak.

          Thanks you so much

          TheoLT Online
          TheoLT Online
          TheoL
          Contest Winner
          wrote on last edited by
          #4

          @Chakkie What happens if you turn the light off? I'd be expecting a V_LIGHT....

          ChakkieC 1 Reply Last reply
          0
          • TheoLT TheoL

            @Chakkie What happens if you turn the light off? I'd be expecting a V_LIGHT....

            ChakkieC Offline
            ChakkieC Offline
            Chakkie
            wrote on last edited by
            #5

            @TheoL

            Hi TheoL, When I turn off the RGB, the ArduinoIDE serial Monitor gives a sg=0:0. See image below. And as you mentioned. I don't see the V_Light respond. See image.

            ![alt text](0_1459696736731_upload-84afe10a-7f2a-475e-bafb-fe84a4dc7049 0_1459696705265_upload-4c5475c9-23db-4517-8c2c-aae77d081a57 image url)

            ![alt text](0_1459696766153_upload-743804b2-8e2f-4d66-992d-12f433216cfa image url)

            ![alt text](0_1459696825659_upload-3ed10e3f-4f2e-4b21-84ee-c4d3cb6cdd21 image url)

            Raspberry Pi 2
            Domoticz
            RFXCOM
            ZWAVE Aeon stick
            Coming soon Arduino mysensors GW

            1 Reply Last reply
            0
            • ChakkieC Offline
              ChakkieC Offline
              Chakkie
              wrote on last edited by Chakkie
              #6

              Hi TheoL,

              I have changed the value from 0 to 255 as shown below and now the LED strip turn off when I click the off button in domoticz.

              Now the dimming part has yet to be solved :)

              ![alt text](0_1459697790250_upload-deea4aa9-4d91-4afa-af88-b87a342aed1e image url)

              Was

               if (message.type == V_LIGHT) {
                  if (message.getInt() == 0) {
                    digitalWrite(RED_PIN, 255);
                    digitalWrite(GREEN_PIN, 255);
                    digitalWrite(BLUE_PIN, 255);```

              Raspberry Pi 2
              Domoticz
              RFXCOM
              ZWAVE Aeon stick
              Coming soon Arduino mysensors GW

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              22

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

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