google / OctoPrint-LEDStripControl

OctoPrint plugin that intercepts M150 GCode commands and controls local GPIOs connected to LEDs.
Apache License 2.0
64 stars 50 forks source link

Will this work on common anode RGB LEDs? If not, what modifacations would need to be made to make it work? #9

Closed MrBreadWater closed 7 years ago

MrBreadWater commented 7 years ago

Title says it all. Thanks for your help!

precision commented 7 years ago

Yes, that is what I use.

MrBreadWater commented 7 years ago

Thanks!

On Mon, Jul 17, 2017 at 3:55 PM, Uriah Welcome notifications@github.com wrote:

Yes, that is what I use.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/OctoPrint-LEDStripControl/issues/9#issuecomment-315908541, or mute the thread https://github.com/notifications/unsubscribe-auth/AWeVKoyNKTC0Xlopmz139oUodXa0mYnCks5sO-ZcgaJpZM4OanG_ .

MrBreadWater commented 7 years ago

How do I close this issue...?

MrBreadWater commented 7 years ago

@precision Hey, sorry to bring this up again, but I'm having a bit of trouble making colors. Since it's common anode, everything is reversed. So 255 is actually 0, and vice versa. Is there a way to change this to be the opposite?

MrBreadWater commented 7 years ago

@precision actually, scratch that, something else is going on. Setting Blue to 255 will make blue, setting red to 255 makes red, etc, but I can't mix colors unless they are perfectly equal. If they aren't it will just be whichever color has a higher value, but the led will just be dimmer than normal.

precision commented 7 years ago

That is odd. Few questions..

  1. How are your LEDs/mosfets wired up to the Pi?
  2. Are you using pigpiod?
  3. What Pi are you using?
  4. What do you see if you send 'M150 R200 G0 B200'?
MrBreadWater commented 7 years ago
  1. I have 2 wired up.
  2. No.
  3. Pi Zero W.
  4. I see a light green. R255 U0 B255 gives just green.

For some unknown reason, color mixing started working. But I still have the original problem of 255 being off and 0 being on.

MrBreadWater commented 7 years ago

@precision Ok, earlier I had read and blue swapped, and I had green set to the wrong pin altogether. That was why R255 would make red and b255 would make blue. Now R255 makes turquoise, and B255 makes yellow, and U255 makes pink/purple.

It seems like the problem is now the inversion. Simple to fix, however, I don't understand your code (I'm a python amateur) otherwise I would fix it myself. All you need to do is take whatever value it should be, and subtract it from 255. Would you be so kind as to send me a copy of the python with that change?

precision commented 7 years ago

I think all you should have to do to invert the values is to change line 136 of init.py

                try:
                    v = float(match.group(2))
                except ValueError:
                    # more than likely match.group(2) was unspecified
                    v = 255.0

And just change it to

                try:
                    v = 255.0 - float(match.group(2))
                except ValueError:
                    # more than likely match.group(2) was unspecified
                    v = 0.0
MrBreadWater commented 7 years ago

Oh is that all? Well, in that case, that makes things much easier. Do you know where the file is stored? I can't find it.

On Thu, Oct 12, 2017 at 8:35 AM, Uriah Welcome notifications@github.com wrote:

I think all you should have to do to invert the values is to change line 136 of init.py

          try:
              v = float(match.group(2))
          except ValueError:
              # more than likely match.group(2) was unspecified
              v = 255.0

And just change it to

          try:
              v = 255.0 - float(match.group(2))
          except ValueError:
              # more than likely match.group(2) was unspecified
              v = 0.0

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/OctoPrint-LEDStripControl/issues/9#issuecomment-336175774, or mute the thread https://github.com/notifications/unsubscribe-auth/AWeVKjYTIOeS9mSqJvwSW5ThMpp8lwk2ks5srjHGgaJpZM4OanG_ .

precision commented 7 years ago

Well assuming you're using Octopi it should be in

/home/pi/oprint/lib/python2.7/site-packages/octoprint_LEDStripControl/

Of not, basically the same path but where ever you put your virtualenv base.

MrBreadWater commented 7 years ago

Alright, I've changed it and it pretty much works. I just have to specify all the values, otherwise the led defaults to white. But other than that it works flawlessly.

On Thu, Oct 12, 2017 at 9:59 AM, Uriah Welcome notifications@github.com wrote:

Well assuming you're using Octopi it should be in

/home/pi/oprint/lib/python2.7/site-packages/octoprint_LEDStripControl/

Of not, basically the same path but where ever you put your virtualenv base.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/OctoPrint-LEDStripControl/issues/9#issuecomment-336199894, or mute the thread https://github.com/notifications/unsubscribe-auth/AWeVKuiGT-NsNYd4tCei0x1tzLtFv4Rnks5srkVpgaJpZM4OanG_ .

MrBreadWater commented 7 years ago

Thanks for all your help!

On Thu, Oct 12, 2017 at 9:59 AM, Uriah Welcome notifications@github.com wrote:

Well assuming you're using Octopi it should be in

/home/pi/oprint/lib/python2.7/site-packages/octoprint_LEDStripControl/

Of not, basically the same path but where ever you put your virtualenv base.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google/OctoPrint-LEDStripControl/issues/9#issuecomment-336199894, or mute the thread https://github.com/notifications/unsubscribe-auth/AWeVKuiGT-NsNYd4tCei0x1tzLtFv4Rnks5srkVpgaJpZM4OanG_ .

precision commented 7 years ago

Glad to hear!