Deep dive ATXPiHat LED and Switch support

During the design phase, we felt that two features, 12v RGB LEDs and a controllable switch for external devices were critical. These features are isolated away from the GPIO pins of the Pi to save the hardware from accidental overload. To protect the Pi at all costs, all output features of the ATXPiHat, except for the fan connector, are isolated away from the Pi.

The LED Strip Support

The hardware can drive any standard 12v RGB LEDs. Here are the default pin outs;


Outside of the 12 volt + pin, these are configurable via the plug in settings. With the 1.0 version of the ATXPiHat we ship a female JST cable that can be used for this connector. There are all sorts of applications for this, include cabinet lighting, notification of completed prints, etc.LED Plugin config

Amazon has several LEDs strips that should work well with this feature. The strips can be controlled either by the plugin user interface or via G-Code. On the ATXPiHat tab, you can statically control the color and brightness of the strip. LED strips are only driven when the ATX power supply is on an powering the printer.


When using these controls, Octoprint will save and apply these settings without having to go to the settings menu and saving the configuration. Each time that the power is turned on, the LED strip will set the LEDs these settings. Pressing “Reset” will shut the LED strip off and set the brightness to the highest setting. These can be changed at anytime regardless if the ATX PSU is running or not. When running a 10 foot length of LED strip it will use about 1 amp at 12v. In combination with a standard hot bed and  hot end, you are still under the 19 amp limit.

The Switch Support

The switch can be either 12 or 5 volts, depends on how it is wired. The ATXPiHat controls the switch by handling the ground side of the circuit. That is why it can be either 5 or 12 volts. The switch can be identified on the screw terminal by the SW terminal.


Use the SW terminal as the GND side of whatever you are providing voltage to (the black wire). There are few examples of applications for this feature;

Additionally, it can be configured to be either a on/off or PWM. Pulse Wave Modulation (PWM), is a modulation technique used to encode a message into a pulsing signal. It can also be used to encode a digital signal to an analog output. This allows for dimming of lights, varying motor speeds, etc.

One of the more important features, is what state the switch is in when power is applied to the printer. This allows for automatically switching on a device at startup, or leaving it off until either a G-Code or UI command turns it on.

SW Config.png

The switch can be controlled either by the plugin user interface or via G-Code. On the ATXPiHat tab, you can statically control if the switch is either on or off as well as if the output is “dimmed” or variable. In “variable” mode, “Reset” will set the PWM to maximum (255). The switch is only driven when the ATX power supply is on an powering the printer.  If you wish to use another G-Code command to turn the switch on and off, you can modify the command from the settings panel. Please note, the command must start in the left most position of the line. I will be ignored if it is not.


SW Variable.PNG

Like the LED controls, Octoprint will save and apply these settings without having to go to the settings menu and saving the configuration implicitly. These can be changed at anytime regardless if the ATX PSU is running or not.

Amperage pull is dictated by what you are using. I would advise connecting what you want to run, with the printer and other electronics disconnected, turn on the supply and the device, and monitor the amperage draw on the Octoprint state dialog, or ATXPiHat tab. This is what the amperage draw of a 10 ft strip of LEDs and a 12v 4 watt bulb with a PWM of 145.


In the case of my Anet-A8, 10 amps for the bed, 3-4 amps for the hot end, 2 amps for lighting, and 1 amp for the electronics, I am under the 19 amp maximum. While running the plugin, the ATXPiHat will force a shutdown if the amperage exceeds 19 amps for more than 5-6 seconds.

Controlling via G-Code

Either the LED strip and/or the switch can be controlled by inserting special G-Code commands in to your sliced models. There are essentially two commands to consider;

  • M150: Set display color 
  • M355: Turn case lights on/off

M150 is used to control the RGB values that the ATXPiHat uses to set the colors for the LED strips. Here is an example;

M150 R255 U128 B192

Now you will ask yourself, where is the “Green”, well for whatever reason this command uses a “U” to denote green. Our implementation can use either “U” or “G”. The ATXPiHat will apply these values and ignore the current settings in the UI. In an effort to preserve the current settings, the G-Code values do not overwrite the current UI set values for the LEDs.

M355 is used to turn the switch on and off. At the time of this post, the G-Code only supports one function, On or Off. It will however, use the current PWM settings is the switch is set variable.

M355 S1 ; Enable lights
M355 S0 ; Disable lights

Calling M355 does not report the current status of the switch. We will incorporate this into future releases.

In the case of both these commands, the ATXPiHat will not interfere with these G-Code commands. It will process the request and pass it on to the printer. This is to allow for these commands to be acted upon by the printer if need be.

How to G-Code it!

I use Simplify3D for all of my slicing and to be honest, inserting these commands during the slicing operation is not a great experience. Cura has several plugins that work very well for this. S3D use a REPLACE command in the “Post Processing” section of the scripts tab to make changes to the G-Code. There is an extensive article regarding all of the capabilities of the script panels.


S3D commands include;

{REPLACE "E" "A"} 
{PREPEND "G92 E0\n"}
{APPEND "G28 X0 Y0\n"}
{DELETE "M82\n"}
{STRIP ";"} 

The article goes into detail regarding how these work and there usage.

So to turn a the LEDs to RED at line 2;

{REPLACE "; layer 2," "M150 R255 G0 B0\n; layer 2,"}

You will notice that I used the “G” for green instead of “U”. Either will work.

To turn on the switch at line 10;

{REPLACE "; layer 10," "M355 S1\n; layer 10,"}

So go ahead and try these out and see what you can come up with. I am using the switch from a 12v 4 watt bulb to light the area. I got it from an old exterior landscaping light and fixture that I had. Works great.

Look for future articles on the usage of the ATXPiHat, including the fan RPM monitor, over amperage protection, and EPO installation.

Warm regards,



Reference Material

Leave a Reply