Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

StoKatze/Automatic-Floodlights-For-3D-Printer-Octoprint-server-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PLEASE NOTE - If you are using Octoprint, you can use its event manager. No need to do all of this. Check my new repository for more info: https://github.com/StoKatze/Automatic-Floodlights-for-3D-Printer-Octoprint-server-event-

This repository will be archived.

Automatic Floodlights for 3D Printer (Octoprint server)

A Python script sends an HTTP GET request to the octoprint server. If it responds that it is printing, a signal is sent to a relay that turns on a parallel led lamp that I use as a flood light for the timelapse camera.

Requirements

Software

  • Python 3 (Should be installed by default on Raspbian - How to install)
  • Python 3 RPi.GPIO package sudo pip install RPi.GPIO
  • (Obviously) an Octoprint server
  • Works fine on Raspberry Pi OS Bullseye (Debian 11)

Hardware

  • Raspberry Pi
  • 1 Channel 5V Relay (Something like this)
  • A breadboard
  • Some components (wires, LEDs and a resistor) to make the lamp

Wiring scheme

There are two ways to wire this thing. The first one is the recommended way. The second one is an alternate way if, for example, you are using a fan on your Pi alongside these LEDs and don't have any spare 5V pins. In any case, wiring is fairly straight-forward.

Common parts

LEDs

  1. Put 5 LEDs on the breadboard
  2. Connect them in parallel (something like in the pictures below)
  3. Add a 10Ω resistor on one side (in this case I put it on the positive side - red wires on the breadboard in the images below)
  4. Connect a wire from the resistor to a 5V pin on your Raspberry Pi (red wire going from the breadbord to the Raspberry Pi in the images below)

Relay

  1. Connect the NO to the negative side of the lamp (check the pictures below, it's the cyan wire going from the relay to the breadbord)
  2. Connect the signal pin on the relay to pin 7 on the Raspberry Pi (check the pictures below, it's the cyan wire going from the Raspberry Pi to the relay)
  3. Connect the - pin on the relay to a ground header on your Raspberry Pi
  4. Connect the COM to another ground header on your raspberry Pi

1 - Default

Wiring scheme

  • Connect the + pin on the relay to the other unused 5V pin on your Raspberry Pi (red wire going from the Raspberry Pi to the relay in the picture above)

If you don't have a second 5V pin available, please follow the alternate wiring instructions.

2 - Alternate

Wiring scheme Alternate

  • Connect the + pin on the relay to a 3.3V pin on your Raspberry Pi (white cable in the picture above)

Please note that if you have a fan, the ground pin next to the 5V one might be already occupied. This is not an issue since you can use any other ground pin.

Usage

Download the python script inside a directory, edit some parameters and execute it. If your Octoprint server automatically starts at boot time, you can use a crontab to start this other script too. If you want to use cron, I suggest setting it to run the autostart scripts. It's also possible to just run the python code directly if you don't want useless files in your system.

Detailed instructions

Configuring the python script

  1. Create a new directory and CD into it
  2. Download AutomaticOctoprintLED.py in this directory
  3. Edit it using nano or any other text editor nano AutomaticOctoprintLED.py
  4. Check and, if needed, edit your settings from line 13 to line 16 (an in-depth explanation of these options is available in the script, comments from line 6 to line 12)
  5. Set your API Key on line 18 (Octoprint Server Web UI -> Settings -> API -> Enable CORS, then copy the Global API Key string) - DO NOT SHARE THIS KEY! WHOEVER HAS IT CAN CONTROL YOUR WHOLE OCTOPRINT SERVER!
  6. If you are using another pin for the relay signal, edit line 23 too
  7. Save and exit

Running the script manually

  1. Execute the script python3 AutomaticOctoprintLED.py
  2. The script should print some text
  3. Use CTRL+C to terminate it
  4. OPTIONAL: you can run it to save a log file (don't forget the -u option - also note that the log is erased every time you start the python script) python3 -u AutomaticOctoprintLED.py > ./log.txt 2>&1 or ignore all output python3 AutomaticOctoprintLED.py &> /dev/null - You can also use screen to hide the output (sudo apt update && sudo apt install screen && screen, press enter and write your command. You can use CTRL+A+D to detach from your screen session and screen -r to resume it)

Using the autostart with logging

  1. Download the octoprintLedLog.sh script in the same directory of the python file
  2. Make it executable chmod +x octoprintLedLog.sh
  3. Execute it

Please note that the log file is erased every time you start this script.

Using the silent autostart

  1. Download the octoprintLed.sh file
  2. Make it executable
  3. Execute it

Using crontab to automatically start this script at boot time

  1. Edit your user's crontab (don't forget to edit the path to match your system settings - also if you want to save a log file make sure that the user you're editing the crontab is allowed to write to the script folder): crontab -e
  2. Add one of the following, depending on your setup:
  • If using the logging start script octoprintLedLog.sh:
    @reboot /path/to/your/octoprintLedLog.sh
  • If using the silent start script octoprintLed.sh:
    @reboot /path/to/your/octoprintLed.sh
  • Or you can execute the python script directly (not tested but should work fine - not logging version):
    @reboot python3 path/to/your/AutomaticOctoprintLED.py >& /dev/null
  • Or you can execute the python script directly (not tested but should work fine - logging version):
    @reboot python3 path/to/your/AutomaticOctoprintLED.py > /path/to/log.txt 2>&1

If the script terminates earlier than expected (due to some connection errors) you may need to add some timeout to allow octoprint to start. Just add sleep [NUMBER_IN_SECONDS] && after @reboot but before anything else (please note there must be a space after @reboot and after &&). E.g.: @reboot sleep 60 && /path/to/your/octoprintLed.sh [OR] @reboot sleep 120 && python3 path/to/your/AutomaticOctoprintLED.py > ./log.txt 2>&1

Thank you

I don't know much about electronics so I tried making this circuit as easy as possible. Suggestions are welcome.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published