Trying to figure out how to have an IO pin supply power to a light on startup

First off, huge apologies if this isn't the right area or if I'm not posting my question correctly. I read the stickies, and tried to research my question before asking, but I have to admit I'm stuck because I don't want to kill my motherboard by accident.

Short story is I have a 3d printer that a friend of mine built. Its motherboard is a SAV-MKI, and I would like a light strip to light up when I plug in the printer. Currently I'm controlling the lights through gcode commands sent through OctoPrint, so when I start a print I can get the lights on, but I'd like them to automatically power on from the get-go.

The 5v LED light strip is plugged into pin A4 (and the ground next to it) on the expansion interface of the board, in an IO pin marked as A4 (analog) or A42/44 (digital, depending on if it's teensy or marlin, respectively). I'm using Marlin, so I believe the pin is labeled as 44, based on this code I found in the pins_SAV_MKI.h file:

#define EXT_AUX_A4_IO 44

From what I've read, I can use

digitalWrite(44, HIGH);

to make that pin generate power for my LED lights. Here's my questions:

  1. Is that the right code
  2. Where do I put it so that it will run on startup but won't affect anything else

This printer uses a very old version of Marlin, I see that the newest version has an excellent "GCode on startup" function I could use, but there are all sorts of dependencies present in this old version that disable functionality of certain things on the printer when I tried to flash a new Marlin version (namely, the heated bed plate didn't heat anymore).

Okay, sorry again if I did anything wrong, please point me in the right direction if I'm way off base. I sincerely appreciate any advice you can all give me, I'm incredibly excited about learning all of this!

  • Dave

The above code looks good and could go as the first 2 lines in setup().

But when the controller is running setup() 'startup' is well past.

Any reason for not using a digital pin?

On some Uno thingies A4/A5 are the I2C pins. Using another pin might make more sense if you plan on adding a display or some other I2C device.

what's the current limit on a Marlin pin?

Thanks for responding!

The lights were already attached to that pin, so I wasn’t sure how to move them since the OctoPrint commands control them during the print. It’s probably easy, but this is all new to me.

I don’t know if it’ll be helpful or not, but I’m attaching a schematic of my board with the only open pins circled in red, with the pins that my light is on in yellow - let me know if there’s any additional info I can add to make it clearer.

If I put my code in the setup() function, would that run relatively quickly after the printer is plugged in, or would it still wait until I started sending gcode from OctoPrint? It doesn’t have to happen “immediately”, but in the first 10 seconds or so would be great

SAV_MKI schematic

1st 10 sec or so, then setup() would be fine.

Just got home, thanks for responding, I'll try that tomorrow!!

Just wanted to let you know that worked perfectly, I have lights that come on the moment I plug in my printer! Thank you SO much for your advice!!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.