This plugin allows the user to easilly configure and control a PWM light for Raspberry PI GPIOs. The Light controls will show up on the controls tab as shown in the screenshots below. Additionally, the user can configure light values per light control entity for various Octoprint events such as printer connect / disconnect, print start / end, ...
Install via the bundled Plugin Manager or manually using this URL:
https://github.com/RoboMagus/OctoPrint-LightControls/archive/main.zip
The end user is responsible for setting up the gpio configuration used in this plugin and the corresponding wiring correctly. Failure to do so could damage your Raspberry Pi! I cannot be held accountable for any damages.
Many PWM controlled Lights can be added through the plugins settings menu. In the top section you can add the light and give it a name, select the pin to use, etc. Enabling and Disabling the lights automatically on e.g. print start / stop can be configured in the section below. Here you can enter the light value as a percentage of full brightness. Empty fields imply the light will remain untouched when the event occurs.
In versions >= 0.4.3
support for Hardware PWM is added to mittigate the flickering effects that users may experience caused by the software PWM used by default (See issue #6).
The use of Hardware PWM needs additional configuration to the Raspberry pi config. The applicable PWM overlays need to be added to the /boot/config.txt
file. Details and options are best described here.
Note that Hardware PWM on the Pi is limited to pins 12, 13, 18 and 19! For each of these pins, the following overlays should be added to /boot/config.txt
:
GPIO | dtoverlay |
---|---|
GPIO 12 | dtoverlay=pwm,pin=12,func=4 |
GPIO 18 | dtoverlay=pwm,pin=18,func=2 |
GPIO 13 | dtoverlay=pwm,pin=13,func=4 |
GPIO 19 | dtoverlay=pwm,pin=19,func=2 |
Once these changes are applied and the Pi is rebooted(!), this plugin will automatically attempt to use Hardware PWM on any of these pins when they are configured to act as PWM lights.
As per version 0.3.0
this plugin supports a few helper functions that can be used by other plugin developers to interact with LightControls.
These helper functions are:
get_light_names()
: returns an array of strings containing all configured light names.get_light_value(light_name)
: returns an integer light value as a percentage of brightness (0 to 100) for the providedlight_name
if the entity exists. ReturnsNone
otherwise.set_light_value(light_name, light_value)
: sets thelight_value
(from 0 to 100) for providedlight_name
and returns the set value if succesfull. ReturnsNone
otherwise.
An example of how to use these helpers:
helpers = self._plugin_manager.get_helpers("LightControls")
if helpers:
if "get_light_names" in helpers:
light_names = helpers["get_light_names"]()
self._logger.info(f"Light names: {light_names}")
if "get_light_value" in helpers:
self._logger.info("Light values before reset:")
for name in light_names:
self._logger.info("Light '{}' value: {}".format(name, helpers["get_light_value"](name)))
if "set_light_value" in helpers:
set_light_value = helpers["set_light_value"]
self._logger.info("Light values after reset:")
for name in light_names:
value = set_light_value(name, 0)
self._logger.info(f"Light '{name}' value: {value}")
Since version 0.5.0
this plugin supports changing light values using @-commands
. This enables control of the lights through GCode and may be useful in combination with Octolapse to change the light brightness using the before / after snapshot gcode.
The format for these commands is @LIGHTCONTROL [name] [value]
, where [name]
is the name assigned to the light you wish to change, and [value]
is the brightness percentage to set (range 0 to 100).
For example to take Octolapse snapshots in a well lit chamber, without the glare of lights near the nozzle, one could use the following GCode snippets:
Before Snapshot GCode
@LIGHTCONTROL Chamber 100
@LIGHTCONTROL NozzleCam 0
G4 S2
After Snapshot GCode
@LIGHTCONTROL Chamber 20
@LIGHTCONTROL NozzleCam 100
Note the G4
Dwell command after changing the light values to allow the light values to settle and the camera to adjust its settings.
- Add support for hardware PWM (Should improve #2)
- Implement
@-commands
(Issue #9) - ...