Hi,
I would like to use the beeper that is part of the SBC (I am talking about the physical beeper that is on the MKS board behind the LCD).
Does anybody know, which pin of the rpi I have to address or how I can find it out by myself?
I tried:
ar37: not a valid pin
gpio17: a valid pin, but I can get no sound, neither with, nor without PWM
In printer.cfg I have
[output_pin beeper_pin]
pin: rpi:gpio17
# Beeper pin. This parameter must be provided.
# ar37 is the default RAMPS/MKS pin.
pwm: True
# A piezo beeper needs a PWM signal, a DC buzzer doesn't.
value: 0
# Silent at power on, set to 1 if active low.
shutdown_value: 0
# Disable at emergency shutdown (no PWM would be available anyway).
cycle_time: 0.001
# Default PWM frequency : 0.001 = 1ms will give a tone of 1kHz
# Although not pitch perfect.
[gcode_macro BEEP]
gcode:
# Parameters
{% set i = params.I|default(1)|int %} ; Iterations (number of times to beep).
{% set dur = params.DUR|default(100)|int %} ; Duration/wait of each beep in ms. Default 100ms.
{% set freq = params.FREQ|default(2000)|int %} ; Frequency in Hz. Default 2kHz.
{% for iteration in range(i|int) %}
SET_PIN PIN=beeper_pin VALUE=0.8 CYCLE_TIME={ 1.0/freq if freq > 0 else 1 }
G4 P{dur}
SET_PIN PIN=beeper_pin VALUE=0
G4 P{dur}
{% endfor %}
Any help would be greatly appreciated - cheers
Bastian
ok, i have worked out some stuff with this. from reading stuff about the chip itself i found commands to turn pins on and off from the command line and found that this command echo 1 > /sys/class/gpio/gpio82/value turns the buzzer on and this echo 0 > /sys/class/gpio/gpio82/value turns it off. however these only work as root (sudo su)
i beleive the gpio82 maps to the name GPIO2_C2 that should be used in the config but i have a print going right now so i cant check
also, this did not need pwm so it is a DC buzzer (unfortunatly i think that means we have no controller over pitch)
Hey @TomW1605 - thank you very much for this information!
I feel really stupid, that I did not pick up on your answer earlier
I can confirm, I can get the beep through the command line as you describe.
In the config though, I found no way to use that pin:
pin: rpi:GPIO2_C2 in printer.cfg gives me:
âPin âGPIO2_C2â is not a valid pin name on mcu ârpiââ
Same kind of error with pin: rpi:GPIO82
I can use a shell script and trigger that from a macro - I would like it more (as it is more direct and elegant) if I was able to address the pin via the correct name.
If you have any more information - it would be greatly appreciated.
Cheers
ive done all this and i keep getting a response in the website gui that you need root privilages. when i tell the shell script macro to run the script with sudo -s bash i get no password was provided. the script works, as i can trigger it from putty manually. any insight? @Bastian
@pgain88 : hm, letâs see if wee can figure it out.
With which user are you accessing the terminal (if you run $ whoami youâll know).
And what are the owner and permissions on the script file ($ ls -la macro_beep-beep.sh)?
In my setup, the file belongs to user mks and permissions are set as -rwxr-xr-x: -rwxr-xr-x 1 mks netdev 610 Jan 11 22:26 macro_beep-beep.sh
To change permission: $ sudo chmod 755 macro_beep-beep.sh
To change ownership: $ sudo chown mks:netdev macro_beep-beep.sh
unfortunately it does not help. my original file permissions were not the same as yours, but even after fixing them with chmod, it does not work.
my file properties pull up as -rwxr-xr-x 1 mks netdev 489 Jan 16 21:37 beeper.sh whoami pulls as mks.
After turning on logging and trying to trigger the command from mainsail i get this.
â/home/mks/printer_data/config/beeper.sh: line 20: /sys/class/gpio/gpio82/value: Permission deniedâ
âRaw parameters:â
âBeep count: 3, beep duration: 0.1, pause duration: 0.5â
if i try to sudo bash the command i get this error â[sudo] password for mks:
sudo: no password was providedâ
however if from a real command line i sudo bash the script, input the password then it will work as expected.
ive used visudo to modify to sudoers.tmp and made sure mks password required was set to no.
I believe I can see the difference in behaviour clearer now:
With my setup running $ echo 1 > /sys/class/gpio/gpio82/value from the terminal as mks works (you have to echo 0 ... to stop the beepâŚ) - without su or sudo.
Is this the same for you? I believe not.
Also TomW1605 wrote you had to use sudo, but I donât think that was ever necessary for me.
$ groups mks gives me: mks : netdev root tty disk dialout sudo audio video plugdev games users systemd-journal input ssh
Is there any group, that my mks has, which yourâs doesnât?
$ ls -la /sys/class/gpio/gpio82/value gives me: -rw-rw---- 1 root dialout 4096 Jan 23 17:15 /sys/class/gpio/gpio82/value
It looks like itâs the dialout group, which allows mks to access that value.
Who are ownership and permissions for that file on your side?
I donâd understand why it is working with the user mks, but not from the macro. I thought, that scripts, which are called from macros would be using exactly that userâŚ
You could try to align the file-ownership and -permissions, so that they are the same as on my setup:
$ sudo chown root:dialout /sys/class/gpio/gpio82/value to set dialout as the group, which owns that value.
$ sudo chmod g+w /sys/class/gpio/gpio82/value to add âwriteâ-permissions for the owning group (echoing into that file is like writing).
If it works after that - hurray (but I donât understand why this is the solutionâŚ).
i did find that my method of " sudo chmod 777 /sys/class/gpio/gpio82/value" does not work after restart.
must login as root to make these changes stick.
I got it to work from within klipper, without using gcode_shell_command. /sys/class/gpio/gpio82 inside klipper is rpi:gpiochip2/gpio18. But to make the pin available in klipper, we have to take it away from sysfs
These are the steps to get there:
1. take the pin away from sysfs, so it is available in klipper
To free the pin each time before klipper starts, add a service override file: $ sudo systemctl edit klipper.service
There are just two lines of content, which go into the file that opens after running the command above:
If you want to reverse the canges to the service, you have to remove the override file - you can remove the whole directory, that contains the file: $ sudo rm -r /etc/systemd/system/klipper.service.d/
and donât forget to reboot.
Every time i try this new method i get this error and the system will not start.
Moonraker canât connect to Klipper!
Please check if the Klipper service is running and klippy_uds_address is correctly configured in the moonraker.conf.
Thanks @Bastian for having investigated this. My two cents:
Directly accessing the gpio from Klipper gets rid of the gcode-shell-command dependency (what is nice), but it does not play together with the makerbase-beep-service, which makes the screen beep when it is touched.
The reason is, that the makerbase service works by writing to gpio82 via sysfs, but it canât, if the gpio gets unexported.
To get both kinds of beeps working, the gcode-shell-command approach is the better choice (both gcode-shell-command and makerbase-beep-service are installed in the original Sovol image).
But if one does not want the screen beeps, then the direct gpio access from Klipper is a nice approach.