I am currently trying to connect a laser to my 3D printer and give a TTL signal manipulated by an M106 command.
The "official" way didn't work out for me so right now I am trying to control it by my Raspberry Pi 3B+ with Octoprint on it. I am using a plugin called Fan Speed Mirror to transform the Fan Speed (M106) to a PWM signal on a GPIO pin.
Therefore I have copied this bash script, which is calling the python script and giving it the M106 number (at least I think that's what it does, please note that I know only basic programming stuff and near to nothing about python or bash).
#!/bin/bash killall fan.py echo $1 $2 $3 >>/home/pi/fan.txt python /home/pi/fan.py $1 exit $?
#!/usr/bin/python3 import sys import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.OUT) s = int(sys.argv) dc = s*100/255 p = GPIO.PWM(11,1000) # channel=11 frequency=1kHz p.start(dc) time.sleep(100000000000000000000)
As you can see I am trying to run the PWM signal as long as no new M106 command is entered.
But that's not really working out.
Instead it runs the first M106 command and then stops the gcode.
I already asked the developer of the plugin here: https://github.com/b-morgan/OctoPrint-FanSpeedMirror/issues/3
But I was hoping to get some input here as well. I hope that what I am trying to achieve is even possible.