#Phyton Script with klipper macros
117 messages · Page 1 of 1 (latest)
So i basically have this script (example not final one)
import time
servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)
p = GPIO.PWM(servoPIN, 50) # GPIO 17 als PWM mit 50Hz
p.start(2.5) # Initialisierung
try:
while True:
p.ChangeDutyCycle(5)
time.sleep(0.5)
p.ChangeDutyCycle(7.5)
time.sleep(0.5)
p.ChangeDutyCycle(10)
time.sleep(0.5)
p.ChangeDutyCycle(12.5)
time.sleep(0.5)
p.ChangeDutyCycle(10)
time.sleep(0.5)
p.ChangeDutyCycle(7.5)
time.sleep(0.5)
p.ChangeDutyCycle(5)
time.sleep(0.5)
p.ChangeDutyCycle(2.5)
time.sleep(0.5)
except KeyboardInterrupt:
p.stop()
GPIO.cleanup()```
and my question is where to save it and how to execute it (and what to adjust cause this is not written for klipper)
this thread has some information on controling GPIO pins with Klipper. https://www.reddit.com/r/klippers/comments/n1028z/executing_shell_or_python_scripts_by_klipper/
would that also work for servos? Cause they only have one data pin
and that data pin needs to send a pulse with a specific lenght
You should really start to read the Klipper documentation https://www.klipper3d.org/Config_Reference.html#servo
Never tried it on a Linux mcu but should be easy to try out for you
I configured the servo in the printer config but i get this error
pin: gpiochip0/gpio26
minimum_pulse_width: 0.0005
maximum_pulse_width: 0.0024```
camera is just the name
and then pulse width is from the datasheet
And did you add it also in the printer.cfg
i dont think so let me look into that
serial: /dev/serial/by-path/platform-3f980000.usb-usb-0:1.3:1.0-port0
baud: 115200
restart_method: command
[mcu host]
serial: /tmp/klipper_host_mcu```
like this?
Yes
Okay starts with no errors
ill go try if the servo works
ignore this SET_SERVO SERVO=my_servo ANGLE=180
nothing happens no idea why
pin: host:gpiochip0/gpio26
minimum_pulse_width: 0.0005
maximum_pulse_width: 0.0024```
command i sent SET_SERVO SERVO=camera ANGLE=100
no errors
thats probably it
Or you simple used the wrong io
a good psu is already ordered because i get the undervolted warning a lot
I would use a scope to measure it but you might not have one
i dont
i guess thats the reason
Datasheet says this Operating voltage: 4.8 V (~5V)
ill wait for the power supply and then test
I tried to use my arduino for power and it still didnt work and no errors
The data pin is a pwm0 but my rpi 3b doesnt have a normal pwm pin
Maybe thats the issue idk?
Ill try to debug tomorrow maybe i made a mistake when setting up the mcu or smth
just a basic led also doesnt work
Than you most likly use the wrong IO
Ill just try with a different pin later
I only have pwm0 is that fine or do i have to do smth different
Or pwm1
not even an led works
white_pin: host:gpiochip0/gpio25```
line 25: "GPIO25" unused input active-high (gpioinfo)
and the cpu usage on the mcu and host is the same so its set up correctly (i guess)
Pins used by Klipper are seen
in printer.cfg?
You will not get an output as long gpioinfo does not show it
Use my example, change the pin to host: gpio16
Restart Klipper and verify gpioinfo
Guy I provide you with an example that I know it is working
should i put it in printer.cfg or somewhere else
If that not working you might have missed the step with the group permission
Sorry but what is so hard to understand?
Put
[output_pin lock_M106]
pin: host: gpio16
value:0```
In your printer.cfg. Do a firmware restart. SSH in your pi and run gpioinfo to check if that IO is now marked as Klipper
set to klipper and output
and a switch shows up on the dashboard
and if i plug in a led its lights up
but not very bright (probably because of the psu)
What did gpioinfo tells you
line 16: "GPIO16" "klipper" output active-high [used]
You can use each pin only once
We know it is working in general so remove my example completely
Is the pin shown in gpioinfo
Good the rest is than your external hw
Ill just wait for the power supply maybe thats causing it
Alright the new power supply arrived and its still the same
No matter what i change the led is on but not very bright
And i cant turn it off
What kind of led do you use
lol how should that help me. I need a part number
Bump
Have you placed a serial resistor as a current limit?
What value?
No wonder why it is only glimmimg 3.3V/10k = 0.3mA
The data sheet expects a forward current of 20mA
But be aware you should not draw more that 16mA from a PI IO
So 3.3V/16mA=> ~205 Ohm so something around 220 would be ok. A 0.25W type is ok as it will draw ~0.05W (U*U/R)
And that is basic electrical knowledge and has nothing to do with 3d printing
But its on even when i turn the pin off
And its still not very bright with a 200 ohm resistor
I only have 200 and 330 ohm resistors and bigger/smaller ones but 200 is the closest i have
Honestly I have no idea what you did setup, you talk about a wrong PS and so one, I proof to you that the functionality of a klipper mcu controlling an GPIO is working.
The easist way to proof that is a multimeter that should show ~0V if the GPIO is off and around 3.3V if the IO is on. Also important that you did not enable the weak pullup of the IO