PDA

View Full Version : [ANNOUNCE] SqueezeButtonPi - Tool to use buttons and rotary encoders on a RPi



Pages : 1 [2]

paul-
2019-09-25, 15:59
4.x is not compatible, need to at least be running 5.0. But the 6.0 beta is pretty stable now for most things. Really only playing with the rpi4 support.

I'll update the extension so you can just install via the extension page. The extension name is pcp-sbpd.tcz

chill
2019-09-26, 01:30
Just wondering if it's possible to redirect the sbpd commands to a Jivelite installation on a difference device. I know the MAC address option can be used to send commands to a specific player, but if, say, I have Jivelite running on a Jogger, can I send keystrokes to that Jivelite somehow? I'm guessing not, given the uinput involvement, but I thought I'd ask.

Jursi
2019-09-26, 06:10
Install pigpio.tcz from the piCorePlayer repository, then make sure the daemon is running: just type pigpiod from the command line of an SSH terminal.

Then issue the two commands that Paul specified:

sudo modprobe uinput
sudo chmod g+w /dev/uinput

Then download the sbpd binary from Paul's dropbox link, and put it in the home directory of user tc: /home/tc
Make sure it's executable: I changed the permissions to 755 from within Filezilla

Finally, issue the ./sbpd command, with gpio pin assignments to match your encoder's connections to the RPi pins.

For testing purposes I did all this from an SSH command line, but for normal use I would put it in a script file which I'd call at startup using pCP's 'User commands' tweak. If you go that route, note that pigpiod seems to need a moment to start up before you can issue the sbpd command - I inserted a 'sleep 1' into my script immediately after the pigpiod command.


I installed pcp5 and everything is working perfectly, thank you Paul!

Chill, could you provide me the script to call sbpd and pigpiod etc. at the startup. That would be awesome!
And how to call it from the tweaks page.

Thank you!

paul-
2019-09-26, 07:04
Just wondering if it's possible to redirect the sbpd commands to a Jivelite installation on a difference device. I know the MAC address option can be used to send commands to a specific player, but if, say, I have Jivelite running on a Jogger, can I send keystrokes to that Jivelite somehow? I'm guessing not, given the uinput involvement, but I thought I'd ask.

I'm sure anythings possible, but not sure how to go about that.

chill
2019-09-26, 08:02
Chill, could you provide me the script to call sbpd and pigpiod etc. at the startup. That would be awesome!
And how to call it from the tweaks page.


Sure - when I get home I'll update to Paul's latest pcp-sbpd.tcz from the repository, adjust my script to suit, and post it here.

chill
2019-09-26, 12:02
Here's my script for launching sbpd at start-up. I originally put the sbpd command into a script file because I had so may buttons configured that the command was too long to be launched as a User Command. But having it as a script now allows for the necessary extra steps, such as launching the pigpio daemon and loading the uinput module.

Save this text in a file called sbpd-script.sh in the home folder of the default 'tc' user.


#!/bin/sh

# start pigpiod daemon
pigpiod

# give the daemon a moment to start up before issuing the sbpd command
sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd e,20,21,KEY:KEY_UP-KEY_DOWN,2 b,26,KEY:KEY_RIGHT,2,0,KEY:KEY_LEFT,500

To get this script to run when pCP boots, add this line as a user command at the end of the 'Tweaks' section.

http://www.cjh.me.uk/MyPhotobucket/cache/DIYHifi/Tweaks_1024.jpg

Jursi
2019-09-27, 04:16
Here's my script for launching sbpd at start-up. I originally put the sbpd command into a script file because I had so may buttons configured that the command was too long to be launched as a User Command. But having it as a script now allows for the necessary extra steps, such as launching the pigpio daemon and loading the uinput module.

Save this text in a file called sbpd-script.sh in the home folder of the default 'tc' user.


#!/bin/sh

# start pigpiod daemon
pigpiod

# give the daemon a moment to start up before issuing the sbpd command
sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd e,20,21,KEY:KEY_UP-KEY_DOWN,2 b,26,KEY:KEY_RIGHT,2,0,KEY:KEY_LEFT,500

To get this script to run when pCP boots, add this line as a user command at the end of the 'Tweaks' section.

http://www.cjh.me.uk/MyPhotobucket/cache/DIYHifi/Tweaks_1024.jpg


Thank you very much, everything is working now.

Finally I have a player in my bathroom/sauna with physical control. Physical controls are important because it is hard to use touch screen with wet hands when I am in sauna/shower or in a hot tube. And the cheap touch screen is almost unusable anyways.

Here is a picture of my "prototype" player. It is not the prettiest but it sure gets the job done! https://imgur.com/a/bG1HApc
Sad that there is no 3.5 inch display with bezel/frame like there is in the official 7inch display. It hard to cut a proper hole with a dremel:D

chill
2019-09-27, 04:37
That's neat. Two rotary encoders? One for Jivelite navigation, and one for volume?

Jursi
2019-09-27, 05:33
That's neat. Two rotary encoders? One for Jivelite navigation, and one for volume?

Yes that's correct! I changed the volume commands to: KEY:KEY_VOLUMEUP-KEY_VOLUMEDOWN

Now the player also shows the volume bar when changing the volume.

chill
2019-09-28, 01:17
Yes that's correct! I changed the volume commands to: KEY:KEY_VOLUMEUP-KEY_VOLUMEDOWN

Now the player also shows the volume bar when changing the volume.

That's a another benefit of the new keypress emulation. Previously the volume control applied to a specific player, either defaulted by sbpd or specified via the MAC address - that's useful in some cases, such as my integrated amplifier where I always want the volume control to apply to the player where the buttons/encoder are mounted. But with the KEY_VOLUMEUP and KEY_VOLUMEDOWN keypresses presumably the command goes to whichever player is currently under the control of Jivelite.

Aki7
2019-10-04, 04:11
Hi,

after two trials with fresh PiCorePlayer 5.0 setup and sbpd (from piCorePlayer repository) - cannot get it working:

sudo /usr/local/sbin/sbpd -d -s b,24,POWR,2,0,NEXT,300

Command returns without error, but button is not working. Same command line with PiCorePlayer 4.1 is working fine.

Next try: Upgrade Install from 4.1 ... Tried: No good way (squeezlite not starting).

Any help?

thanks and regards
Aki

Jursi
2019-10-09, 12:18
Hi,

after two trials with fresh PiCorePlayer 5.0 setup and sbpd (from piCorePlayer repository) - cannot get it working:

sudo /usr/local/sbin/sbpd -d -s b,24,POWR,2,0,NEXT,300

Command returns without error, but button is not working. Same command line with PiCorePlayer 4.1 is working fine.

Next try: Upgrade Install from 4.1 ... Tried: No good way (squeezlite not starting).

Any help?

thanks and regards
Aki

Maybe you could try to run the command with verbose (-v) to see if the button presses are actually registered.

sudo /usr/local/sbin/sbpd -d -v -s b,24,POWR,2,0,NEXT,300

Br Jursi

Aki7
2019-10-10, 13:20
Hi Jursi,

thanks.

tc@pcTest5:~$ sudo /usr/local/sbin/sbpd -v b,24,POWR,2,0,NEXT,300
...
1570738211.9278 6 GPIO.c,312: Initializing GPIO
1570738211.9287 3 sbpd.c,202: Could not connect to pigpiod. Is it running?

Seems pigpiod is missing. Tried installing pigpio-dev.tcz from the pcp-repository without success (after reboot):

..
1570738751.0564 6 GPIO.c,312: Initializing GPIO
1570738751.0578 3 sbpd.c,202: Could not connect to pigpiod. Is it running?

Ok, just found your script in this threat, tested, but seems to accept the POWR button only once - switches off.
Long keypress is working (NEXT) and short keypress (POWR) is working after it. But after this no more acceptance of any key press.
Can switch back to "On" via browser interface, but audio is at very slow speed after it (low pitch).
So something special happens after POWR-button (off) with pcp 5.0

Regards Aki

chill
2019-10-10, 13:36
1570738211.9287 3 sbpd.c,202: Could not connect to pigpiod. Is it running?

Seems pigpiod is missing. Tried installing pigpio-dev.tcz from the pcp-repository without success (after reboot):


It's not missing, but you have to load it before you call sbpd. See this post (https://forums.slimdevices.com/showthread.php?107001-ANNOUNCE-SqueezeButtonPi-Tool-to-use-buttons-and-rotary-encoders-on-a-RPi&p=951523&viewfull=1#post951523) above.

chill
2019-10-10, 13:50
Ok, just found your script in this threat, tested, but seems to accept the POWR button only once - switches off.
Long keypress is working (NEXT) and short keypress (POWR) is working after it. But after this no more acceptance of any key press.
Can switch back to "On" via browser interface, but audio is at very slow speed after it (low pitch).
So something special happens after POWR-button (off) with pcp 5.0


That doesn't seem right. The default sbpd_commands.cfg has an entry for the POWR command that simply toggles the player's 'soft' power. Is it possible that you are instead calling a shutdown script? What does your sbpd_commands.cfg look like?

Aki7
2019-10-10, 14:39
chill,

thanks.

justed started again with fresh pcp 5.0
installed pcp-sbpd.tcz from pcp-repo, reboot.
sudo pigpiod - this time player stops playing
soft power on via browser - playing again, but with low pitch (slow) sound

sudo vi sbpd_commands.cfg - seems to be empty
Do i have to copy it from .. ?

give up for tonight.

regards Aki

paul-
2019-10-10, 14:43
soft power on via browser - playing again, but with low pitch (slow) sound


This sounds like you have interfaced a button with a GPIO that is being used by your DAC. What DAC are you running ?

Aki7
2019-10-10, 22:32
Paul,

Thanks, same HW-setup is running fine with pcp 4.1

Pi 3b+
Allo boss

Regards Aki

DOliana
2019-10-19, 12:41
Thanks, same HW-setup is running fine with pcp 4.1


I am having a similar issue with a RPi zero and HiFiBerry MiniAMP. It works fine with pcp 4.1, but not with 5.0.

If I start the script mentioned above I get a strange pitch in the output and the buttons / rotary controls do not work.

Update:
It seems, that seems to be causing the error: If I start it, the sound gets distorted - as soon as I stop it everything goes back to normal. The sound is slowed down as if the CPU weren't fast enough.

Krazystar
2019-11-04, 20:06
I having similar issues to Aki7 and DOliana, though also some successes:

1. As soon as I run pigpiod on the test player (which requires sudo? Otherwise I get "Sorry, you don't have permission to run this program. Try running as root, e.g. precede the command with sudo") the music cuts out on that player.

2. In addition to above, as soon as its enabled on the test player the music stream to other players skips rather frequently (like every second). The sound doesn't actually cut out, but it just skips ahead a few milliseconds constantly. As soon as I kill the test player, the music returns to normal. Turning off the other players and using just the test player (and the server pi) doesn't change the behavior.

3. The buttons and encoder worked right away manually using the commands that Chill suggested :D (though running it as a script didn't work due to the need of sudo for pigpiod?). Play/pause and next/prev work audibly across the server as desired and even though there is no sound coming out of the unit, I can see the volume setting go up and down by watching the test player's status on the browser.

I have the server running on a Pi 3B+, the test player is a pi zeroW, and other players are pi zeroWs too (running the older wiringpi version, which works flawlessly). The pi zeroWs (both the test and regular) are connected to i2s style DACs/Amps (Pimoroni pHAT DAC, Adafruit AMP bonnet). I have confirmed via pinout.xyz that there are no shared pins between my button/encoder setup and these HATs.

FYI in case others want to try I'm using:

sbpd b,25,PLAY,2 b,4,NEXT,2 b,26,PREV,2 e,6,5,VOLU,4

Any help would be appreciated (or just a way to fall back to the old version, which is no longer available?). I'm happy to run some tests on this hardware if needed. I don't have a pi 4.


----- UPDATE: ----
I found this https://forums.pimoroni.com/t/issue-phatdac-on-pi-zero-with-pigpio-and-moode-6-3/11875

I did what they sort of recommended, issuing the pigpiod command with -t 0, which turns the clock from PCM to PWM. This solved all of my previous issues and sound now plays normally across all devices, buttons & encoders work, etc. YAY! :D

Note that unlike the user in that post, i don't utilize an IR remote, so that issue is of no impact to me.

However, i'm not sure if this has other repercussions or was the intended behavior? Someone with more knowledge than me may be able to answer. I just got a little worried when i read the final comment: "I’m thinking the use of any DAC for sound is going to have the same problem, they all use i2s, as far as I know anyway." (and i'm pretty sure the vast majority of the DAC options use i2s). :confused:

FYI this is the script i use now (works on boot, based on Chill's script):

#!/bin/sh

# start pigpoid daemon
pigpiod -t 0

# give the daemon a moment to start up before issuing the sbpd command
sleep 1

# load uinput module, then set the permission to group writable, so you
# don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd b,25,PLAY,2 b,4,NEXT,2 b,26,PREV,2 e,6,5,VOLU,4


I did chmod +x it, not sure if that is necessary or not.

Note that there is no conflict between this unit and older units that are running the wiring pi version. Both work simultaneously.

-- one last edit: --
i tested the script without sudo on the pigpiod command and it still works fine. I'm not sure why this doesn't work when just manually launching things (rather than script), but my lack of linux knowledge is showing... i've updated my script above accordingly.

paul-
2019-11-04, 20:25
Start pigpiod with the -t 0 option.

http://abyz.me.uk/rpi/pigpio/pigpiod.html

Krazystar
2019-11-04, 20:41
Self-update:

I found this https://forums.pimoroni.com/t/issue-phatdac-on-pi-zero-with-pigpio-and-moode-6-3/11875

I did what they sort of recommended, issuing the pigpiod command with -t 0, which turns the clock from PCM to PWM. This solved all of my previous issues and sound now plays normally across all devices, buttons & encoders work, etc. YAY! :D

Note that unlike the user in that post, i don't utilize an IR remote, so that issue is of no impact to me.

However, i'm not sure if this has other repercussions or was the intended behavior? Someone with more knowledge than me may be able to answer. I just got a little worried when i read the final comment: "Iím thinking the use of any DAC for sound is going to have the same problem, they all use i2s, as far as I know anyway." (and i'm pretty sure the vast majority of the DAC options use i2s). :confused:

paul-
2019-11-05, 20:15
All i2s dacs are going to use PCM. Those using the internal RPI audio are using PWM. Not sure if USB is affected by either clock.

DOliana
2019-11-11, 06:37
I did what they sort of recommended, issuing the pigpiod command with -t 0, which turns the clock from PCM to PWM. This solved all of my previous issues and sound now plays normally across all devices, buttons & encoders work, etc. YAY! :D


Thanks Krazystar & paul - that did the trick. Now everything works again. (I also had to change the command from VOLM to VOLU - when did that change?)

paul-
2019-11-11, 08:58
(I also had to change the command from VOLM to VOLU - when did that change?)

I think I changed it as I needed to keep some code separated, then when I merged it, I changed everything to the new value......as that was the easier change at that time.

jofland
2020-01-28, 10:27
Is it possible to run more than one rotary encoder with spbd? I need to control volume and want to step through a menue.

paul-
2020-01-28, 11:06
It should work fine. I think Chill did some tests with 2.

chill
2020-01-28, 11:46
It should work fine. I think Chill did some tests with 2.

Not me - Jursi (https://forums.slimdevices.com/showthread.php?107001-ANNOUNCE-SqueezeButtonPi-Tool-to-use-buttons-and-rotary-encoders-on-a-RPi&p=951571&viewfull=1#post951571).

Jursi
2020-01-28, 13:42
Is it possible to run more than one rotary encoder with spbd? I need to control volume and want to step through a menue.

Yes, it is possible!

ChrisList
2020-02-10, 09:10
Hi there,
I am trying to get this working on a Pi zero. I used chills script and when looking on verbose output, I can see the button is registered and a command seems to be send to the server.


1581350083.4460 6 sbpd.c,307: Options parsing: Set verbose mode
1581350083.4475 6 sbpd.c,342: Options parsing: Manually set http address 192.168.2.9
1581350083.4482 6 sbpd.c,496: Using builtin button configuration
1581350083.4490 6 control.c,108: Adding Command PLAY: Fragment ["pause"]
1581350083.4511 6 control.c,108: Adding Command VOL+: Fragment ["button","volup"]
1581350083.4526 6 control.c,108: Adding Command VOL-: Fragment ["button","voldown"]
1581350083.4560 6 control.c,108: Adding Command PREV: Fragment ["button","rew"]
1581350083.4573 6 control.c,108: Adding Command NEXT: Fragment ["button","fwd"]
1581350083.4574 6 control.c,108: Adding Command POWR: Fragment ["button","power"]
1581350083.4575 6 GPIO.c,312: Initializing GPIO
1581350083.4768 6 control.c,262: Button defined: Pin 11, BCM Resistor: up, Short Type: LMS, Short Fragment: ["pause"] , Long Type: unused, Long Fragment: (null), Long Press Time: 3000
1581350083.4904 6 discovery.c,385: MAC address found: b8:22:eb:45:bc:3e
1581350083.4919 6 servercomm.c,176: Initializing CURL
1581350083.5676 6 sbpd.c,255: Starting main loop polling
1581350091.4959 6 GPIO.c,107: Short PRESS: 316
1581350091.4960 6 control.c,134: Button CB set for button #:0, gpio pin 11
1581350091.5851 6 control.c,276: Button pressed: Pin: 11, Press Type:Short
1581350091.5852 6 servercomm.c,74: Send Command:0, Fragment:["pause"]

However nothing happens. Sometimes I got a timeout error message:

1581347930.8281 6 servercomm.c,134: Curl Error: (28)
1581347930.8282 6 servercomm.c,136: Connection timed out after 5001 milliseconds

The command I use to start sbpd is

sbpd -v -A 192.168.2.9 b,11,PLAY,2,0

Is there a way to see the curl command being generated? Or has anyone another idea why this is not working?
Chris

paul-
2020-02-10, 10:47
Change the -v to -z, and you'll get more messages.

ChrisList
2020-02-10, 11:05
Using -z, I get a more infos. Apparently, this is the command being send to the server:


1581357277.5801 6 control.c,276: Button pressed: Pin: 11, Press Type:Short
1581357277.5802 6 servercomm.c,74: Send Command:0, Fragment:["pause"]
1581357277.5802 7 servercomm.c,122: Server ::192.168.2.9:0 command: {"id":1,"method":"slim.request","params":["b8:22:eb:45:bc:3e",["pause"]]}

The Server and port seem to be wrong, it should be port 9000?!

I added -P 9000 to the launch command, however now I get a segmentation fault:

1581357680.1965 6 sbpd.c,312: Options parsing: Set debug mode
1581357680.1983 6 sbpd.c,342: Options parsing: Manually set http address 192.168.2.9
Segmentation fault

Additionally I found the API documentation and created the curl by hand. That works without issues, hence something is broken in the plugin or my configuration of it?

curl -X POST -d '{"id":0,"params":["b8:22:eb:45:bc:3e",["button","pause.single"]],"method":"slim.request"}' http://192.168.2.9:9000/jsonrpc.js

paul-
2020-02-10, 12:11
If I had time, I would trap that, but yes you need to set both server and port. If you aren't using discovery.

What is your full command line. All options need to be before button or encoder configuration.

ChrisList
2020-02-10, 12:59
The string I use is:
sbpd -z -A 192.168.2.9 -P 9000 b,11,PLAY,2,0

Then I get the segmentation fault

Discovery is not working for unknown reasons, he does not find my server.

Paul Webster
2020-02-10, 13:08
As an experiment ... try
--port=9000
instead of
-P 9000

paul-
2020-02-10, 13:27
Are you using this on pCP? If not where did you get the binaries?

ChrisList
2020-02-10, 14:50
yes, on piCore player 5.0.0. I installed it via the extensions menu.

ChrisList
2020-02-10, 15:16
As an experiment ... try
--port=9000
instead of
-P 9000

Gives the same segmentation fault

paul-
2020-02-10, 17:04
Well there is something that never worked....lol. The print statement showing that you set the -P option is what is seg faulting. If you had the verbose output turned off it would have worked.

Anyway, its fixed update your extension (run "pcp-update pcp-sbpd.tcz") I also defaulted to port 9000 if you use the -A option, so you can leave off -P too.

Thanks for posting details, as I knew others have used the -P option, and wondered how it worked in the past.

ChrisList
2020-02-10, 17:45
:-D nice one...

It works now! Thanks a lot!

M-H
2020-02-16, 11:12
I do have some trouble to debug the setup of my rotary controller through the expansion.header of my sound card.
Documentation of the manufacturer is quite bad, So I am not sure what rpi gpio pins are what pins on the header.
So searching for a debug option.. And I am afraid that a multimeter beep ( active resistance measurement ) could damage the 3.3 volt soundcard.

Can we use sbpd to output on pins in human visible frequencies ? and then use a led or multimeter to see where that pin is blinking on the soundcard header?

regards M-H

paul-
2020-02-16, 13:48
why not just work your way though the gpio, setting them to output one by one and measuring the voltage on the pin?

within the spbd software, you can only see information coming off the pins you have programmed. But in debug mode(-z) you should see encoder counts.

M-H
2020-02-16, 15:55
within the spbd software, you can only see information coming off the pins you have programmed. But in debug mode(-z) you should see encoder counts.
Thanks Paul- That gave me enough info to find the pins were right, but sending programmed keys does seem to fit installations with jivelite only. And as this one is truly headless that did not work out. And I adjusted.

Next issue, The encoder seems to send +1 and -1 on about each step in either direction.

1581892998.8865 6 control.c,466: Encoder on GPIO 12, 3 - value: -1, detents: -1, change: -1
1581892998.8868 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1581892999.0046 6 control.c,466: Encoder on GPIO 12, 3 - value: -2, detents: -2, change: -1
1581892999.0048 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1581892999.1187 6 control.c,466: Encoder on GPIO 12, 3 - value: -1, detents: -1, change: 1
1581892999.1189 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1581892999.3336 6 control.c,466: Encoder on GPIO 12, 3 - value: -2, detents: -2, change: -1
1581892999.3338 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1581892999.7485 6 control.c,466: Encoder on GPIO 12, 3 - value: -1, detents: -1, change: 1
1581892999.7487 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1581893000.3643 6 control.c,466: Encoder on GPIO 12, 3 - value: -2, detents: -2, change: -1
1581893000.3647 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1581893000.4794 6 control.c,466: Encoder on GPIO 12, 3 - value: -1, detents: -1, change: 1
1581893000.4796 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]

So the volume does not really change.
Is this a HW controller issue? or do I have more options than the 0-3 for the detecting edge ?
Tested with both a controller that has its own pullup and pulldown resistors with +vcc and gnd connection
And tested with a bare controller that has only the switches so I used a ground connection and software pullups.
All tests same result, except for detect edge value 0 and 3 where there is no detection at all.

The used SBPD initialisation:

sbpd -v e,12,3,VOLU,1 b,26,VOL+,2,0,VOL-,250

And currently testing on a pi B+ with PCP 6b9, BMC signals 3,12,26 work OKE if used with the button.
VOLU versus VOLM seems to be needed, perhaps a differently compiled version from the PCP repository.

Hints and solutions are welcome M-H

paul-
2020-02-16, 16:27
Are you compiling your own version? Source code is currently in my github, I've never merged back to pippen's git.

VOLU is the correct command. When I set all that up, we tested with 3 wire encoders, using ground as the center tap. The gpio pins are set with pullup resistors, and we need to used both rising and falling edges to properly detect changes. The volume appears to be changing from your log.....perhaps not as fast as you want.

foxsam
2020-02-16, 22:24
1581916860.8494 3 sbpd.c,202: Could not connect to pigpiod. Is it running?

I am running
piCorePlayer v6.0.0-b9 | www v0001 | linux 4.19.102-pcpCore | piCore v10.3pCP | Squeezelite v1.9.6-1206-pCP

I do have pigpio installed (not running).
If I run
sudo pigpiod I get terrible squealing from my speaker and if I try to play music it comes out as static.

Is there something I need to do to fix this?

paul-
2020-02-17, 07:29
I am running
piCorePlayer v6.0.0-b9 | www v0001 | linux 4.19.102-pcpCore | piCore v10.3pCP | Squeezelite v1.9.6-1206-pCP

I do have pigpio installed (not running).
If I run
sudo pigpiod I get terrible squealing from my speaker and if I try to play music it comes out as static.

Is there something I need to do to fix this?

pigipiod is using the system clock that you sound card is using.

If you are using the rpi onboard audio, then use pigpiod -t 1

If you are using an i2s dac Hat, then use pigpiod -t 0

Reference: http://abyz.me.uk/rpi/pigpio/pigpiod.html

M-H
2020-02-17, 10:40
Are you compiling your own version? Source code is currently in my github, I've never merged back to pippen's git.
No I am happy with the version you compiled for me / us.
But if your additions can be incorporated in Pipins version, there are fewer things to go wrong for people who do not read source files for breakfast. :-)




VOLU is the correct command. When I set all that up, we tested with 3 wire encoders, using ground as the center tap. The gpio pins are set with pullup resistors, and we need to used both rising and falling edges to properly detect changes. The volume appears to be changing from your log.....perhaps not as fast as you want.

Haha -1 -1 +1 -1 +1 -1 +1 = -1 that is indeed not fast enough for me, As all rotary clicks were in the same direction.
But as I tested with the same wire setup you used, I will triple check the encoders datasheets and verify with a faster pi.
This was all done on a B+, and fast turns seemed to have undetected clicks. So a detection performance issue might be at hand.
And I should also eliminate the sound card, just to be on the safe side.


M-H

paul-
2020-02-17, 12:41
Its possible that things I had to do to tone down a pi4 hurt the slower pis. Test on a pi4 if you can.

M-H
2020-02-18, 14:56
Its possible that things I had to do to tone down a pi4 hurt the slower pis. Test on a pi4 if you can.

Paul, I did, same results on a Pi zero-w , 3B+ and 4B,
All tested with pcp 6b9 and a basic encoder, only software pullups, connections to gnd, sw1 sw2
Switched to use BMC 16, 26 for encoder same result.

Tried to build the same sbpd setup on a pcp 4.1.0, but could not quickly locate the extension in the gui, that list is quite long !

Who can share a working config for a sbpd and an encoder in pcp 6 ?

Regards M-H

paul-
2020-02-18, 19:35
There are several users doing this. https://forums.slimdevices.com/showthread.php?107001-ANNOUNCE-SqueezeButtonPi-Tool-to-use-buttons-and-rotary-encoders-on-a-RPi&p=951523&viewfull=1#post951523.

All of our encoders seem to have more velocity than yours.

guiv
2020-02-19, 16:33
I am currently discovering all this pCP and sbpd stuff, and first of all thanks a lot for that, it really works great !

As a newbee I have a few questions... First : I am currently launching a script via "Tweaks/User commands" page, which calls sbpd at init. I am just a little puzzled by one comment found in the script mentionned in this thread and apparently reused by many users:

# load uinput module, then set the permission to group writable, so you
# don't need to run sbpd with root permissions
I don't use jivelite neither uinput, however I get the idea to run sbpd without root permissions. But... what's the use of that, if the script directly calls sbpd ? Commands added in "Tweaks/User commands" are run as root, aren't they?
I modified the script to run sbpd like this, does it make sense?

sudo -u tc sbpd ...
Well, at least sbpd does not run as root any more, and still works like a charm :)

Second point: I would like to play a little bit with multi-players sync with my buttons
The idea when I press a button is to play a favorite, but only on local player: first un-synchronize other players if necessary (the idea is to avoid waking up the kids when starting the kitchen radio)
I know in this case I have to issue several commands to LMS, and that might be a little tricky. What do you think would be the most straightforward?
I am currently thinking of launching a script from sbpd. This script would launch a binary in charge of handling the feature. I could probably reuse sbpd source code to implement that part (at least servercomm).
Would there be an easier path?

Paul Webster
2020-02-19, 22:48
Would there be an easier path?

Perhaps easier would be to not use the regular groups in LMS but instead switch to Philippe's dynamic group plugin.
Then you would play to the dynamic group when you want to drive multiple players at the same time and it would disassemble when the music stops.

M-H
2020-02-23, 16:27
There are several users doing this. .. <cut> ..
All of our encoders seem to have more velocity than yours.

Paul, Chill, and others here,
I finally debugged my encoder issues, so let me share to pass knowledge and experiences:

As with a lot of difficult problems it had multiple issues.
First the audio card that exposes Raspi pins , has bad documentation, so pushing me to use the wrong BCM numbers in the sbpd init.
Second , The rotary controllers I have , are not all the same; especially the hardware resistors on the module board do interfere with the default used here ( pull-up software resistors and ti to ground switches.) Using the 3V3 on the appropriate pin helps to get reliable levels on the output pins. This is why Chill might not have experienced it. I recognise his module in the photo.
Third, it seems the borrowed script should not be started over and over again with new sbpd lines. I have not looked into the issue, but if just started once from boot it does produce the expected results, if ran for the 10th or so time, the correct settings give different results.

But Hey! I got trough , and have 3 working sets now. Thank you for providing the info in this thread.

Last ; On the sensitivity of the controllers, I believe there is a difference in the amount of physical clicks and contact logical cycles.
So 1 perceived click might very well be 2 or more steps measured by sbpd. I read that before , but can't find that source right now.

Regards, M-H

luigi2000
2020-03-20, 17:05
Hi Paul,

I updated my piCorePlayer to version 6.0. Unfortunately none of my Buttons and encoders are working anymore. Did something change?
I also tried a clean Install of pCP 6.0 on an emtpy SD Card but it is also not working. So there was nothing wrong with the Update itself.

The sbpd was installed via the piCorePlayer repsitory at the extension menu.
Then I added the following line as user command in the tweaks menu: /usr/local/sbin/sbpd -d e,23,24,VOLU e,12,6,TRAC b,7,POWR,2,0 b,5,PLAY,2,0.

Anything I did wrong? I did the same thing with piCore Player 4 and 5 and it worked.

Is there any documentation or a short How-To that is up to date? When I look at Github (https://github.com/coolio107/SqueezeButtonPi-Daemon) there is still the VOLM command instead of VOLU and no TRAC command that you implemented for encoders 1 or 2 years ago.

Thanks again for the great work!!

paul-
2020-03-20, 17:43
Yes, everything is changed, you will need to update the extension, and then follow the new instructions.....a lot of info in this thread.

The main reason for the change is wiring pi is depreciated.

luigi2000
2020-03-21, 09:24
OK. I tried to start sbpc and pigipio via a sbpc-script.sh in the tweaks user command line.

I created the file and inserted the text that what posted here.
But how can I make the file NOT disapear after a reboot?

paul-
2020-03-21, 09:46
Backup after you make changes.

luigi2000
2020-03-22, 10:24
Installed pigpio and added the script to start pigpio and sbpd.

Volume control and track skipping works now with this command:
sbpd e,23,24,VOLU,1 e,12,6,TRAC,1 b,7,POWR,2,0 b,5,PLAY,2,0

The power toggle and the play toggle function is still not working.

The POWR command is not listed anymore in sbpd Infortmation (-->sbpd -?)
Is there another way to toggle the power state now?

The PLAY command is still listed but doesn't work for me. Where could be the problem?

Another question concerning the new KEY command. Do I need jivelite when I want to use a command like this:
sbpd e,23,24,KEY:KEY_VOLUMEUP-KEY_VOLUMEDOWN

Thanks for your help!

Jursi
2020-04-03, 07:05
That's a another benefit of the new keypress emulation. Previously the volume control applied to a specific player, either defaulted by sbpd or specified via the MAC address - that's useful in some cases, such as my integrated amplifier where I always want the volume control to apply to the player where the buttons/encoder are mounted. But with the KEY_VOLUMEUP and KEY_VOLUMEDOWN keypresses presumably the command goes to whichever player is currently under the control of Jivelite.

Hello,

Do you know if it is possible to use one rotary encoder to control jivelite running on other raspberry pi and another encoder to control the volume on a player where the both encoders are mounted.

Thanks!

paul-
2020-04-09, 12:37
No guide, but why don't you post

1) Exactly how you have your encoder wired
2) Model # and Brand of encoder
3) Startup Scripts/sbpd configuration files.

luigi2000
2020-04-10, 11:24
Ok I try to explain it more detailed.
My Setup is a Raspberry Pi 3 with JustBoom Amp HAT.
The rotary encoder was this one I think https://shop.justboom.co/products/rotary-encoder-push-switch
I wired the encoder so that they worked with this command before I updated to piCorePlayer 6 and the newest SBPD extension

sbpd e,23,24,VOLU,1 e,12,6,TRAC,1 b,7,POWR,2,0 b,5,PLAY,2,0

I learned that with the updated sbpd extension there must be pigpio installed too.
So I installed pigpio and now I use the following script that is started via user command line in the tweaks menu:

#!/bin/sh

# start pigpiod daemon
pigpiod -t 0

# give the daemon a moment to start up before issuing the sbpd command
sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd e,23,24,VOLU,1 e,12,6,TRAC,1 b,7,POWR,2,0 b,5,PLAY,2,0

The VOLU and TRAC commands are working fine but the POWR and the PLAY command is not working.

This was working with the older version of SBPD and I did not change anything physically at the encoders.
I hope this is enough information to identify the problem.

paul-
2020-04-10, 14:15
Start sbpd from command line and add the -v option. you should see verbose output showing commands getting added to gpio and then you should see button pushes when they come in.

luigi2000
2020-04-11, 03:10
That was strange. I started sbpd manually with -v option to look at the verbose output and the POWR and PLAY command worked fine.
Then I switched back to the script that starts sbpd and also everything is working now. I did not change anything at the script.
Same behaviour for two different PiCoreplayers. Nevertheless everything is working now and thanks for your support.

jemhayward
2020-04-12, 11:21
Noob alert!

I have my encoder on 16 and 18

Yesterday /usr/local/sbin/sbpd -v suggested that pigpoid was not running, so I did:

sudo pigpoid

and then ran /usr/local/sbin/sbpd -v again, and it was happy about pigpoid - but that was all I got done.

Today I ran /usr/local/sbin/sbpd -v and it didn't complain about pigpoid, so I'm assuming I've 'installed' pigpoid and it now runs automatically?

So, I then ran /usr/local/sbin/sbpd -d e,16,18,VOLU, 1

Encoder not changing volume - so I'm assuming I've not got my parameters correct?

Is VOLU right or should I now be using VOL+ and declaring each pin separately? It's a long thread and I've read it all but really need some working examples and a command ref for someone as inexperienced as me!

jemhayward
2020-04-12, 11:44
Just randomly tried:

/usr/local/sbin/sbpd -z -d e,16,VOL+,e,18,VOL-

and that doesn't work either...:mad:

paul-
2020-04-12, 11:52
Try randomly running "sbpd --help" and looking at the help

You are not using correct command line parameters. Also, do not use the -d option when using verbose -v or -z.



For rotary encoders):
e,pin1,pin2,CMD[,mode]
"e" for "Encoder"
p1, p2: GPIO PIN numbers in BCM-notation
CMD: Command. one of.
VOLU for Volume
TRAC for Prev/Next track
KEY:<linux key_name>-<linux key_name>.
mode: Optional. one of
1 - Step mode (default)
2-9 - Detent mode - Assumes 1 dial click is x steps.

jemhayward
2020-04-12, 12:00
As I said noob!!!

Help file is very helpful and I am now doing:

/usr/local/sbin/sbpd e,16,18,VOLU

but it's now saying pigpiod isn't running so I need to run that first...

jemhayward
2020-04-12, 12:11
Installed User Commands as:

sudo pigpiod
and
/usr/local/sbin/sbpd e,16,18,VOLU

But it's not working... maybe need to check the GIPO pins really are 16 and 18 tomorrow.

Thanks for guidance!

paul-
2020-04-12, 12:11
If you look at the post on this page or last page, you will see a startup script

or this post......

https://forums.slimdevices.com/showthread.php?107001-ANNOUNCE-SqueezeButtonPi-Tool-to-use-buttons-and-rotary-encoders-on-a-RPi&p=951523&viewfull=1#post951523

jemhayward
2020-04-13, 05:02
I've coped that script, and changed the last line so it now reads:

#!/bin/sh

# start pigpiod daemon
pigpiod

# give the daemon a moment to start up before issuing the sbpd command
sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd e,16,18,VOLU

I've double checked my wiring and my encoder is definitely on 16 & 18
It's not working :(

Are there any diagnostics I can do to make sure the script has successfully run, and anything I can use to 'detect' my encoder on those pins in case the encoder is broken?

Paul Webster
2020-04-13, 05:06
Could it be pin numbering ... BCM v Physical ?
https://pinout.xyz/

jemhayward
2020-04-13, 05:25
Ah, yes, possibly - that was a complication I hadn't been aware of (noob!!!)

Updating script and rebooting now...

So, physical pins are 16 & 18, but I've now put them in the script as 23 & 24, rebooted, and it still doesn't work :(

I'm sure I'm doing something fundamentally stupid, but not spotted it yet...

Paul Webster
2020-04-13, 05:41
Make sure that your changes survived the reboot

chill
2020-04-13, 05:52
Are there any diagnostics I can do to make sure the script has successfully run, and anything I can use to 'detect' my encoder on those pins in case the encoder is broken?

Yes - don't run your script from the User commands section of pCP, but start it manually, and include the -v option in the sbpd command line. This will allow you to see whenever sbpd reacts to a button press or an encoder event.

EDIT: run your script from the command line with 'sudo', to make sure that pigpiod has permission to run.

While working on the Pirate Audio setup, there were some useful suggestions for improving this button script, in particular to make sure that the pigpio daemon really has had time to initialise before sbpd is run (the original 'sleep 1' may not have been enough in some cases). The result of those suggestions is this code, which waits up to 10 seconds for the daemon to start:



#!/bin/sh

# start pigpiod daemon
pigpiod -t 0 -f -l -s 10

# wait for pigpiod to initialize - indicated by 'pigs t' exit code of zero
count=10 # approx time limit in seconds
while ! pigs t >/dev/null 2>&1 ; do
if [ $((count--)) -le 0 ]; then
printf "\npigpiod failed to initialize within time limit\n"
exit 1 # or however you want to deal with failure
fi
# printf "\nWaiting for pigpiod to initialize\n"
sleep 1
done
printf "\npigpiod is running\n"

# load uinput module - required to be able to send keystrokes
# then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd ....... <= your command string here

jemhayward
2020-04-13, 05:56
Make sure that your changes survived the reboot

Interesting - I definitely uploaded the updated file by sftp, but I've now downloaded it to check and it's the OLD file - how does that work?

I'm also working on the WiFi setup, so I'm going to write the file to the card from my windows machine and I'll then be sure it's 'stuck'

Paul Webster
2020-04-13, 06:04
pCP runs in memory and does not write to disk unless you tell it to make a backup.

You will not be able to write to that part of the SD card from regular Windows.

jemhayward
2020-04-13, 06:20
pCP runs in memory and does not write to disk unless you tell it to make a backup.

You will not be able to write to that part of the SD card from regular Windows.

Ah, that probably explains a lot! The original file I uploaded seemed to survive a reboot, but subsequent edits didn't - weird, but now I know.

jemhayward
2020-04-13, 07:53
Correct file in place, but no joy.

Open shell:

I've run sudo pigpiod and pgs t gives me a number - so that is running

I then did my sbpd -v e,23,24,VOLU and there is a response like this:

1586789274.1176 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1586789274.4334 6 control.c,466: Encoder on GPIO 23, 24 - value: 32, detents: 32, change: 1
1586789274.4336 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]

and so on, so the encoder is working and sbpd is reading it, but it doesn't seem to be communicating with LMS - "mixer","volume","+1" sounds right...

chill
2020-04-13, 08:00
and so on, so the encoder is working and sbpd is reading it, but it doesn't seem to be communicating with LMS - "mixer","volume","+1" sounds right...

Is this running on the same device as squeezelite?

You can specify which player the commands should apply to:



sbpd -v -M <player mac address> e,23,24,VOLU

chill
2020-04-13, 08:03
...and do you have more than one instance of LMS running on your network? You can also specify the IP address (-A) and the port (-P) for the server, in case it's autodetecting the wrong one.

jemhayward
2020-04-13, 08:46
Only one LMS - it finds that OK, but I do have another squeezelite on the network (which is set to 100% volume fixed) - I'll try the mac address in my script.

That doesn't work... BUT if I SSH in, do a sudo su and pigs t - it shows that pigpiod is running
If I then do
sbpd -M 'my mac address' e,23,24,VOLU
It WORKS!
and so does
sbpd e,23,24,VOLU

so mac address is a red herring - it just doesn't work from the script :(

I think I may simplify my script to emulate exactly what I'm doing at the command line and see if that does it. I'm nearly there!

jemhayward
2020-04-13, 09:01
I decided to simplify things completely - it would appear that the script is not starting pigpiod.

Manually starting pigpiod only, from the shell as root results in the music slowing down, so it's done something to the clock - I recall reading about this somewhere. I think I need to fix this problem before I do anything else.

Later: - sudo su
pigs t shows that pigpiod is not being started by my script.
Manually starting pigpiod -t 0 gets me music at the right speed - progress
manually starting sbpd e,23,24,VOLU gets me volume control.

What's not working is doing this automatically at boot, but at least I know it's working.

Later:
A few more re-boots and I then gave up on scripting. I have three startup options so the first one is:
sudo pigpiod -t 0
The second one is:
sleep 10
I'm in no rush, so giving pigpiod time to get going is fine...
The third one is:
sbpd e,23,24,VOLU

It now works.

Many, many thanks to all the experts helping a noob get there - slowly. I now really love PiCorePlayer and I think I may build another one for my main system, as I'm currently using Volumio with Squeezelite - but I like the fact I can really get inside PiCorePlayer (and so break it completely!) - keep up the good work!

meq123
2020-06-29, 05:45
So I've just had an adventuresome weekend. Last year I built a custom-cased music player/streamer based around a Pi 3B and a Hifiberry DAC+ running pcp 4.x. With the new Topping E30 coming out, and the non-USB-limited Pi 4, I decided to update the internals to a Pi4, no hat, just USB out. I saw that, in the interim, we were now up to pcp 6.1, so of course went for that and followed my earlier notes to reinstall. All went fine (few changes, but easily navigated) until it came to sbpd. My buttons no longer worked :(

Obviously I searched the 'net and found out here about this new sbpd upgrade and install mechanism, and after a few false starts, everything is working again! Yay! Thanks to all who contributed!

So now, just a couple of questions...

1) The script that @Chill has shown, does not run sbpd with the "-d" (deamonize) parameter. Should it? Or is this no longer required?

2) With the new flexibility, I want to reassign my buttons. Does anyone know how to make a button show the "Now Playing" screen - i.e. do the same thing as the 'music note' icon in the top right of the touch display?

Thanks again!

meq123
2020-06-29, 18:03
OK, I've answered one of my own questions... while I was browsing the forum threads, I came across this link to the various Key 'code's: https://github.com/ralph-irving/tcz-lirc/blob/master/jivekeys.csv

AHA! I see a "KEY_LEFTBRACE" there that corresponds to NowPlaying. Sure enough, I configure it to a button and it works like a champ!

But I still would like to know if -d should be added to the sbpd line?

paul-
2020-06-29, 18:09
Once your done debugging, then yes, add -d.

Jursi
2020-07-28, 03:24
Hello,

Can a volume button be setup in a way that it increases volume as long as I press it or is it just +1 volume per button press?

Thanks!

sakos
2020-08-02, 08:04
Thank you very much, everything is working now.

Finally I have a player in my bathroom/sauna with physical control. Physical controls are important because it is hard to use touch screen with wet hands when I am in sauna/shower or in a hot tube. And the cheap touch screen is almost unusable anyways.

Here is a picture of my "prototype" player. It is not the prettiest but it sure gets the job done! https://imgur.com/a/bG1HApc
Sad that there is no 3.5 inch display with bezel/frame like there is in the official 7inch display. It hard to cut a proper hole with a dremel:D

Hi,

I have a similar radio in kitchen with an 5'' display but the physical control is important due to the same reasons. Following the instructions found here I managed to configure two rotary encoders and buttons. The only missing thing is the LCD backlight control. I would like to drive the LCD backlight control GPIO port to switch off the backlight when the player is stopped.

With sbpd b,13,POWR command the top row of jivelite shows "Off" when the button is pressed. I expected it would control the Poweroff GPIO configured in Poweroff/Shutdown Overlays section of piCorePlayer configuration page, however it does not fly, the configured GPIO pin does nothing.

Could you please recommend a solution to configure a simulated power on/off behavior with stopping/starting player and LCD backlight control?

paul-
2020-08-02, 13:17
I would run sbpd in debug mode and make sure commands are being sent as planned. If the commands are getting executed, then we can figure out if the commands are right.

sakos
2020-08-03, 11:02
Is the latest version of source code public? The version running on my device is 3.0.1, however the github version is 2.1 only.

sakos
2020-08-06, 12:43
Hi,

I have a similar radio in kitchen with an 5'' display but the physical control is important due to the same reasons. Following the instructions found here I managed to configure two rotary encoders and buttons. The only missing thing is the LCD backlight control. I would like to drive the LCD backlight control GPIO port to switch off the backlight when the player is stopped.

With sbpd b,13,POWR command the top row of jivelite shows "Off" when the button is pressed. I expected it would control the Poweroff GPIO configured in Poweroff/Shutdown Overlays section of piCorePlayer configuration page, however it does not fly, the configured GPIO pin does nothing.

Could you please recommend a solution to configure a simulated power on/off behavior with stopping/starting player and LCD backlight control?

Meanwhile I realized that there is a similar configuration option in "Squeezelite settings" page. It is called "Power On/Off GPIO".
Squeezelite will toggle this GPIO when the Power On/Off button is pressed.

This is exactly what I was looking for. After configuring, it started to work. But it works only until I start playing a webradio. After that, it applies only a momentary impulse on the GPIO pin. What a pity...
I am convinced it is a SW bug. Going to open a ticket.

paul-
2020-08-06, 13:37
Power on/off in the spbd/lms context is just turning off the "Player Power" Just like hitting the power button on the LMS interface. Most would use it to control a relay that powers an amplifier on/off.

To shutdown the complete pi, you could script it here with spbd, but other ways are easier.

sakos
2020-08-06, 23:28
Power on/off in the spbd/lms context is just turning off the "Player Power" Just like hitting the power button on the LMS interface. Most would use it to control a relay that powers an amplifier on/off.

To shutdown the complete pi, you could script it here with spbd, but other ways are easier.

Yes, I understand that this is only a "soft" power off. And this is exactly what I need. But it has an issue (https://github.com/ralph-irving/squeezelite/issues/96).

blackbird
2020-08-20, 18:13
My configuration:

RPi 2B
PCP 6.1.0
pcp-sbpd
jivelite (Waveshare 3.5")

/home/tc/sbpd-script.sh
================================================== ===========================
#!/bin/sh

# start pigpiod daemon
pigpiod

# give the daemon a moment to start up before issuing the sbpd command
sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd e,6,12,KEY:KEY_UP-KEY_DOWN,2 b,5,KEY:KEY_RIGHT,2,0,KEY:KEY_LEFT,500
================================================== ============================

31336

Rotary encoder working...key up and down, and button also working.
BUT. when key up, down..jump 2 step down or up.
I have to rotate very slowly to move 1 step. :(

Does any options are available to fix this problem ?

paul-
2020-08-20, 19:47
Check the optional mode setting for encoders.



For rotary encoders (one, volume only):
e,pin1,pin2,CMD[,edge]
"e" for "Encoder"
p1, p2: GPIO PIN numbers in BCM-notation
CMD: Command. one of. \n\
VOLU for Volume\n\
TRAC for Prev/Next track\n\
KEY:<Positive key_name>-<Negative key_name>
mode: Optional. one of\n\
1 - Step mode (default)\n\
2-9 - Detent mode - Assumes 1 dial click is x steps.

blackbird
2020-08-20, 20:50
Check the optional mode setting for encoders.



For rotary encoders (one, volume only):
e,pin1,pin2,CMD[,edge]
"e" for "Encoder"
p1, p2: GPIO PIN numbers in BCM-notation
CMD: Command. one of. \n\
VOLU for Volume\n\
TRAC for Prev/Next track\n\
KEY:<Positive key_name>-<Negative key_name>
mode: Optional. one of\n\
1 - Step mode (default)\n\
2-9 - Detent mode - Assumes 1 dial click is x steps.


It works after changing dent mode setting from 2 to 4.
Thank you.

sakos
2020-09-17, 02:33
Yes, I understand that this is only a "soft" power off. And this is exactly what I need. But it has an issue (https://github.com/ralph-irving/squeezelite/issues/96).

The above issue is solved by LMS update to latest. Now I have a working solution to control GPIO when the player is in "power off" status. :)

klothi
2020-10-04, 09:42
Hi,
I'm using a PiCorePlayer v6.1 setup with HDMI output. LMS is running on Synology NAS in the LAN.
I installed the sbpd as explained on the first site of this thread.
Then I tried several hours a bunch of different User commands in the tweaks menu to get my rotary encounter running. It's a model KY-040 encounter.

First I tried to use VOLM but read later on that it got replaced by VOLU.
My last version I tried was:


/usr/local/sbin/sbpd -d -s e,23,24,VOLU,1 b,25,POWR,1

This and all the versions before didn't work.
Last thing i did was to connect via SSH and to exec:


sbpd -v e,23,24,VOLU,1

The result was:
1601829442.7315 6 GPIO.c,219:Initializing GPIO
wiringPiISR: Can't find gpio program
wiringPiISR: unable to open /sys/class/gpio/gpio23/value: No such file or directory

I assume there is a piece of software missing to use the gpio but have no clue how to solve it.

Got anybody the KY-040 running and can help me? :confused:

meq123
2020-10-04, 09:46
Do you have the gpio library loaded? (pigpio.tcz on the Extensions tab)

klothi
2020-10-04, 11:15
These were not not installed. I installed all 3 now. pigpio.tcz, pigpio-dev.tcz and pigpio-doc.tcz.
After a reboot nothing changed.
The error message is still the same. :-(

Paul Webster
2020-10-04, 11:31
From the error message I guess that you need wiringpi.tcz

klothi
2020-10-04, 11:57
From the error message I guess that you need wiringpi.tcz

I checked this and got for wiringpi.tcz the same funny thing:

Wiringpi.tcz was not listed in the "Installed" tab of extension section.
After selection of wiringpi.tcz from piCorePlayer repository in the "Available" tab and click on the "Load" button I got the message:
wiringpi.tcz is already got alread downloaded.
I clicked "Load again but it's only downloaded.
Then I installed wiringpi-dev.tcz. This worked successfully and was not downlaoded before.
When I try to install wiringpi.tcz again the procedure claims that it's now installed.
Furthermore I can see now in the "onboot.lst" tab that wiringpi.tcz seems to be below wiringpi-dev.tcz in the hierarchy.



I noticed the same issue already for the pigpio.tcz.
Anyway. This was the problem! It works now! Thank you very much for your help to bring my Sunday evening to an happy ending!:cool: :D :o

Aki7
2020-10-04, 12:53
the way i got it running with PCP 6.1:

install: pigpio.tcz
Install: pcp_sbpd.tcz

Tweaks-autostart with internal sound:
sudo pigpiod -t 1;sleep 0.1;sbpd -d -s b,5,POWR
Tweaks-autostart with DAC-board:
sudo pigpiod -t 0;sleep 0.1;sbpd -d -s b,5,POWR

my user command in tweaks:

sudo pigpiod -t 0;sleep 0.1; sbpd -d -s e,24,23,VOLU,2 b,25,POWR,2,0,PLAY,300 b,5,NEXT,2,0 b,12,PREV,2,0

rotary encoder is volume, short press rotary encoder is soft off/on, long press rotary encoder is play/pause
two buttons for next and previous track

spt58
2020-11-21, 10:13
This a great plugin thanks to all involved!

Is there any way it could be tweaked to allow for double press / triple press on buttons in a future update perhaps? Opens up a few more options for those with a limited number buttons e.g. single press (play pause), double press (next track), triple press (prev track)

Many thanks

billtsig
2020-12-19, 12:48
Hello everybody

i am using rpi4 2gb ram with picore player and LMS for a system that i build now, so today i decited to try to control the player with phisical buttons

as a newbie i read many threads for how can i do that and i try the method from post number 5 in this thread

i connect to my rasberry pi over ssh and i run this commands


pcp bu # save pcp config

cd /mnt/mmcblk0p2/tce/optional

wget http://downloads.sourceforge.net/project/picoreplayer/beta/sbpd.tcz.md5.txt

wget http://downloads.sourceforge.net/project/picoreplayer/beta/sbpd.tcz

md5sum sbpd.tcz # make sure the file downloaded correctly
f0157164d10b86325b38fee0cb8d709e sbpd.tcz

cat sbpd.tcz.md5.txt # does it match the line above?
f0157164d10b86325b38fee0cb8d709e sbpd.tcz

echo "sbpd.tcz" >> /mnt/mmcblk0p2/tce/onboot.lst

pcp rb # you must reboot!

everything seems to be ok, so lets make the first button for the "play , pause" action

i open again the ssh and i run this command
sbpd b,26,PLAY,1

i press the enter button and yeah an error occured ;)

wiringPiISR: Can't find gpio program
wiringPiISR: unable to open /sys/class/gpio/gpio26/value: No such file or directory




does anyone have an idea for how can i solve this problem? , i spent manu hours in front of the screen without result

thank you
Vasilios

jeroen2
2020-12-19, 15:24
does anyone have an idea for how can i solve this problem? , i spent manu hours in front of the screen without result


I was having a hard time getting that to work as well.. Ended up up adding the following to config.txt and that works fine..

dtoverlay=gpio-key,gpio=5,keycode=16 # KEY_q power
dtoverlay=gpio-key,gpio=6,keycode=57 # KEY_SPACE play-pause
dtoverlay=gpio-key,gpio=16,keycode=48 # KEY_b jump-forward

meq123
2020-12-20, 07:49
i press the enter button and yeah an error occured ;)

wiringPiISR: Can't find gpio program
wiringPiISR: unable to open /sys/class/gpio/gpio26/value: No such file or directory



Did you load the gpio extension?

1) On the Main Page tab, scroll down to and click "Extensions"
2) For "Current repository", select 'piCorePlayer main repository' (if not already selected) and click 'Set'
3) For "Available Extensions" select 'pcp-sbpd.tcz' and click 'Load' then wait for extension
to load. Similarly select 'pigpio.tcz' and click 'Load' then wait for extension to load.
(Latter may already be installed)

paul-
2020-12-20, 08:06
The version on sourceforge is quite old. The current version is on the pCP repo. And no longer uses wiringPI, it uses pigpiod. As wiringPI is depreciated.

jd68
2020-12-20, 08:31
as a newbie i read many threads for how can i do that and i try the method from post number 5 in this thread


Just a note: there have been several improvements for SBP since post 5, e.g. it is better to use the SBP from the repository of piCorePlayer. The same is valid for examples of scripts, i.e. take the latest ones and read the the thread completely. ;-)

billtsig
2020-12-20, 09:16
I was having a hard time getting that to work as well.. Ended up up adding the following to config.txt and that works fine..

dtoverlay=gpio-key,gpio=5,keycode=16 # KEY_q power
dtoverlay=gpio-key,gpio=6,keycode=57 # KEY_SPACE play-pause
dtoverlay=gpio-key,gpio=16,keycode=48 # KEY_b jump-forward

hi jeroen2 this works preety well and easy without downloading anything simple and awesome!!!

thank you verry much!!

i also try to make it work with a rotary encoder (as gpiokey) that emulates the arrow keys of a keyboard without success (and its very logical since a rotary encoader gives pulse A and B even if you turn it clockwise or anti clockwise

so with a reaserch i found this
Name: rotary-encoder
Info: Overlay for GPIO connected rotary encoder.
Load: dtoverlay=rotary-encoder,<param>=<val>
Params: pin_a GPIO connected to rotary encoder channel A
(default 4).
pin_b GPIO connected to rotary encoder channel B
(default 17).
relative_axis register a relative axis rather than an
absolute one. Relative axis will only
generate +1/-1 events on the input device,
hence no steps need to be passed.
linux_axis the input subsystem axis to map to this
rotary encoder. Defaults to 0 (ABS_X / REL_X)
rollover Automatic rollover when the rotary value
becomes greater than the specified steps or
smaller than 0. For absolute axis only.
steps-per-period Number of steps (stable states) per period.
The values have the following meaning:
1: Full-period mode (default)
2: Half-period mode
4: Quarter-period mode
steps Number of steps in a full turnaround of the
encoder. Only relevant for absolute axis.
Defaults to 24 which is a typical value for
such devices.
wakeup Boolean, rotary encoder can wake up the
system.
encoding String, the method used to encode steps.
Supported are "gray" (the default and more
common) and "binary".


i try this comand

dtoverlay=rotary-encoder,rotary0_2_a=keycode=103

but it does not work , i would be gratefull if anyone tell me how to make the encoder emulates the up-down arrows of the keyboard

thank you again vasilios

billtsig
2020-12-20, 09:29
Did you load the gpio extension?

1) On the Main Page tab, scroll down to and click "Extensions"
2) For "Current repository", select 'piCorePlayer main repository' (if not already selected) and click 'Set'
3) For "Available Extensions" select 'pcp-sbpd.tcz' and click 'Load' then wait for extension
to load. Similarly select 'pigpio.tcz' and click 'Load' then wait for extension to load.
(Latter may already be installed)


Thank you verry much i didn,t know about the repository!

now seems to be ok , can i attach an encoder emulating the up-down keys of a keyboard?

paul-
2020-12-20, 09:30
Thank you verry much i didn,t know about the repository!

now seems to be ok , can i attach an encoder emulating the up-down keys of a keyboard?

Sure can. The current git repo is here. https://github.com/paul-1/SqueezeButtonPi-Daemon

billtsig
2020-12-20, 09:48
Just a note: there have been several improvements for SBP since post 5, e.g. it is better to use the SBP from the repository of piCorePlayer. The same is valid for examples of scripts, i.e. take the latest ones and read the the thread completely. ;-)

Thank you verry much! i try to learn about sb couse im a new user of it

billtsig
2020-12-20, 12:09
Hi there again with your asistance i make it work! i'm pretty happy with that

i enter this code in the ssh and the encoder worlks really well



$ sudo pigpiod
$ sudo modprobe uinput
$ sudo sbpd e,2,3,KEY:KEY_UP-KEY_DOWN,4 b,4,KEY:KEY_RIGHT


but when i do a reboot my "script" stops working and needs a run from ssh , probably i must mount this to a folder that runs on boot or in the config.txt , i try this at this moment , thanks everyone again

Bill0t
2020-12-20, 12:44
Hi there again with your asistance i make it work! i'm pretty happy with that

i enter this code in the ssh and the encoder worlks really well



$ sudo pigpiod
$ sudo modprobe uinput
$ sudo sbpd e,2,3,KEY:KEY_UP-KEY_DOWN,4 b,4,KEY:KEY_RIGHT


but when i do a reboot my "script" stops working and needs a run from ssh , probably i must mount this to a folder that runs on boot or in the config.txt , i try this at this moment , thanks everyone again

You can use user command, in the tweak tab. the command I use :

sudo pigpiod -t 0;sleep 0.1; sbpd -d -s e,17,20,VOLU,2 b,13,PLAY b,23,NEXT,2,0 b,12,PREV,2,0

billtsig
2020-12-20, 13:28
You can use user command, in the tweak tab. the command I use :

sudo pigpiod -t 0;sleep 0.1; sbpd -d -s e,17,20,VOLU,2 b,13,PLAY b,23,NEXT,2,0 b,12,PREV,2,0


thank you very much my friend this works fine!!!

billtsig
2020-12-21, 12:07
hello every one i am having bad news.... the encoder workd with the above comand but the system (juvelite) freezes when i am rebooting it and needs to replug the power,

with some research i find that the sudo pigpiod comand makes the system freezes on every reboot but without it nothing works

i am 100% sure with many tests that the comand make the system to chrush i test it multiple time with or without them

i try making a file in /home/tc/sbpd.sh that includes all the comands and then i call this path in tweaks user comand (i write /home/tc/sbpd.sh ) but this way nothing worked

so how can i make a script that run's at the begining of every boot?

what else i can do to make the code working?

thank you again and sorry if i am annoing

paul-
2020-12-21, 14:32
pigpiod requires an clock signal from the rpi. Reference the -t option here: http://abyz.me.uk/rpi/pigpio/pigpiod.html

If you are using the onboard rpi audio, that uses clock 0, so you need to tell pigpiod to use clock 1.
If you are using an i2s DAC Hat, then that uses clock 1, so you need to tell pigpiod to use clock 0.
If you are using USB audio, then it does not matter.

To launch your script at boot, put it in the user commands on the bottom of the tweaks page.

billtsig
2020-12-21, 14:54
pigpiod requires an clock signal from the rpi. Reference the -t option here: http://abyz.me.uk/rpi/pigpio/pigpiod.html

If you are using the onboard rpi audio, that uses clock 0, so you need to tell pigpiod to use clock 1.
If you are using an i2s DAC Hat, then that uses clock 1, so you need to tell pigpiod to use clock 0.
If you are using USB audio, then it does not matter.

To launch your script at boot, put it in the user commands on the bottom of the tweaks page.


Hello paul and thank you for another time for trying to help me i have all ready put the commands in the tweaks page this way and they work but the system freezes if i go to main page and click the reboot button , this does not happend if i remove the command from the tweaks

also everything is good if o open the ssh and manualy write my commands

i have read in the topic about the clock -t so i try with 0 and 1 with the same results , i try putting some of the commands in the tweaks (to find the problematic) and maybe the pigpiod is this one

the piCore runs on a raspberry pi 4 2gb with 64gb sd card and ethernet cable

32617

paul-
2020-12-21, 15:07
You do not need sudo on the User commands, that process already runs with root permissions.

So if you are using -t 0 when launching pigpiod, have you disabled the onboard audio?

billtsig
2020-12-21, 15:32
paul you are the best!! i have done many reboots and everythink works very well , the problem was the sudo maybe?
:confused::confused:

who knows i hope to still works as it's working right now

thank you again for your time and assistance

Greetings from greece Vasilios

armaster
2021-01-15, 03:08
Hi,

I loaded extension pcp-sbpd.tct and set rotary encoder to works. This is my command:
sbpd -v e,27,17,KEY:KEY_VOLUMEUP-KEY_VOLUMEDOWN,1 b,22,KEY:KEY_POWER,2

But it seems that rotary encoder mode (Detent mode) does not work. I can change values from 1 to 9 but the same result.

I found two different repositories from git:
1. github.com/coolio107/SqueezeButtonPi-Daemon
2. github.com/paul-1/SqueezeButtonPi-Daemon

What I'm doing wrong here? Do I have right extension which supports detent mode or is repository #2 as different extension?

paul-
2021-01-15, 06:52
Where did you get the extension from? If you downloaded from our repo (With either pCP 6 or pCP 7) then it's the correct version. My repo is the version that I use for pCP.

armaster
2021-01-15, 14:13
I loaded pcp-sbpd.tcz from piCorePlayer main repository via web interface of pCP 7. This is the extension info:

Title: pcp-sbpd.tcz
Description: SqueezeButtonPi
Version: 3.0.1
Authors: Joerg Schwieder
Original-site: https://github.com/coolio107/SqueezeButtonPi-Daemon
Copying-policy: GPLv3
Size: 20k
Extension_by: piCorePlayer team: https://sites.google.com/site/picoreplayer
Compiled for piCore 10.x

This seems to be wrong one?
I checked also piCorePlayer mirror repository and Official piCore repository but didn't find github.com/paul-1/SqueezeButtonPi-Daemon.

How can I load github.com/paul-1/SqueezeButtonPi-Daemon extension from pCP web interface?

paul-
2021-01-15, 16:33
The extension is right, I used to push all of my changes to The main branch.....I should update the info file.

3.0.1 is the latest version.

Start with debUg output and then turn your encoder. Post the output.

jeroen2
2021-01-17, 03:46
Struggling with SqueezebuttonPi now..

Added this to the startup commands:

pigpiod -t 0; sbpd b,25,PLAY
(-t 0, because I am using a HifiBerry DAC)

But this doesn't work. When I manually start it in a shell, it does work though..:

tc@piCorePlayer:~$ sbpd b,25,PLAY

So I'm a little puzzled and I don't seem to find anything in the log files.. Any suggestions? :confused:

jeroen2
2021-01-17, 09:08
Solved it. Simply adding a pause between starting pigpiod and spbd made it work.

Added these lines to my startup.sh:

#start squeezebuttonpideamon
/usr/local/bin/pigpiod -t 0
sleep 1
/usr/local/sbin/sbpd -d b,25,PLAY


Thanks to Aki7 in this posting (https://forums.slimdevices.com/showthread.php?107001-ANNOUNCE-SqueezeButtonPi-Tool-to-use-buttons-and-rotary-encoders-on-a-RPi&p=990487&viewfull=1#post990487).

jd68
2021-01-17, 11:05
Sometime ago the following script was posted to start sbpd and pigpiod which is a bit more elaborated compared to Aki7's code:



#!/bin/sh

# start pigpiod daemon
pigpiod -t 0 -f -l -s 10

# wait for pigpiod to initialize - indicated by 'pigs t' exit code of zero
count=10 # approx time limit in seconds
while ! pigs t >/dev/null 2>&1 ; do
if [ $((count--)) -le 0 ]; then
printf "\npigpiod failed to initialize within time limit\n"
exit 1 # or however you want to deal with failure
fi
# printf "\nWaiting for pigpiod to initialize\n"
sleep 1
done
printf "\npigpiod is running\n"

# load uinput module - required to be able to send keystrokes
# then set the permission to group writable, so you don't need to run sbpd with root permissions
sudo modprobe uinput
sudo chmod g+w /dev/uinput

# issue the sbpd command
sbpd -z -d -f /home/tc/sbpd/sbpd_commands.cfg b,17,FAV1 b,27,FAV2 b,22,FAV3 b,18,FAV4 b,23,FAV5 b,24,FAV6


It is working fine in my case with Hifiberry HAT.

jeroen2
2021-01-17, 14:28
Sometime ago the following script was posted to start sbpd and pigpiod which is a bit more elaborated compared to Aki7's code:
[..]
It is working fine in my case with Hifiberry HAT.

Thanks, I might try that later.

(I installed this while also doing an upgrade in hardware and upgrading to pCP7 and LMS8, which was leading to all kind of frustrating issues. For now decided to roll back all, and will try again in smaller steps.. But bookmarking this one)

armaster
2021-01-19, 04:09
The extension is right, I used to push all of my changes to The main branch.....I should update the info file.

3.0.1 is the latest version.

Start with debUg output and then turn your encoder. Post the output.

Here is my output:


sbpd -v e,27,17,KEY:KEY_VOLUMEUP-KEY_VOLUMEDOWN,5 b,22,KEY:KEY_
POWER,2
1611054355.5329 6 sbpd.c,316: Options parsing: Set verbose mode
1611054355.5331 6 sbpd.c,505: Using builtin button configuration
1611054355.5332 6 control.c,108: Adding Command PLAY: Fragment ["pause"]
1611054355.5332 6 control.c,108: Adding Command VOL+: Fragment ["button","volup"]
1611054355.5333 6 control.c,108: Adding Command VOL-: Fragment ["button","voldown"]
1611054355.5333 6 control.c,108: Adding Command PREV: Fragment ["button","rew"]
1611054355.5334 6 control.c,108: Adding Command NEXT: Fragment ["button","fwd"]
1611054355.5334 6 control.c,108: Adding Command POWR: Fragment ["button","power"]
1611054355.5335 6 GPIO.c,312: Initializing GPIO
1611054355.5390 6 control.c,411: Rotary encoder defined: Pin 27, 17, Mode: Detent, Type: Keyboard, Pos: KEY_VOLUMEUP, Neg: KEY_VOLUMEDOWN
1611054355.5391 6 control.c,195: Key KEY_POWER:116
1611054355.5401 6 control.c,262: Button defined: Pin 22, BCM Resistor: up, Short Type: Keyboard, Short Fragment: KEY_POWER , Long Type: unused, Long Fragment: (null), Long Press Time: 3000
1611054355.5404 6 discovery.c,385: MAC address found: b8:27:eb:d0:91:8b
1611054355.5404 6 sbpd.c,249: Starting Keyboard Device
1611054355.5446 6 servercomm.c,176: Initializing CURL
1611054355.5543 6 sbpd.c,264: Starting main loop polling
1611054355.5550 6 discovery.c,238: Found server 6601A8C0. A new address
1611054355.6560 6 discovery.c,349: discovery packet: port: 9000, name: pCRoom, uuid: 1f9a2dd5-5036-4348-a159-0e696a099f13
1611054355.6561 6 discovery.c,130: Squeezebox control port found: 9000
1611054355.6562 6 discovery.c,149: Server address found: 192.168.1.102
1611054368.9730 6 control.c,466: Encoder on GPIO 27, 17 - value: -5, detents: -1, change: -1
1611054368.9731 6 control.c,76: Sending key: 114, 1 times



I'm using detent value 5 but does not work. Shouldn't detent value change volume for 5 steps?

bobcoupee
2021-02-01, 07:57
Hi

So I am trying to get my pHAT BEAT working with SqueezeButtonPi. I can get the buttons working by using the script here, https://forums.slimdevices.com/showthread.php?107001-ANNOUNCE-SqueezeButtonPi-Tool-to-use-buttons-and-rotary-encoders-on-a-RPi&p=1004820&viewfull=1#post1004820.

However my problem is trying to use the onboard LEDs at the same time.

I am using this code:

import phatbeat

phatbeat.set_clear_on_exit(False)

for channel in (0,1):
phatbeat.set_pixel(0, 255, 0, 0, 0.1, channel=channel)

phatbeat.show()

After running it the buttons seem to no longer working. Re-running the sbpd script (i.e. calling pigpid and then sbpd and assigning functions to gpios) fixes the problem.

Is the issue that phatbeat.py has the line Import Rpi.GPIO as GPIO?

Thanks in advance.

paul-
2021-02-01, 08:19
That's how python is interfacing with the GPIO. The import alone should not do it. The phatbeat python code is resetting all of the board GPIO when you start it.

https://github.com/pimoroni/phat-beat/blob/master/library/phatbeat/__init__.py

You will need to make you own version of the the phatbeat library, remove all of the references to the inputs.

wtnh
2021-02-16, 07:58
I had success getting an encoder to work. Thanks to others in this thread for ideas! Hopefully, this will help anyone trying to get this working. This is on piCorePlayer 6.1.
My main goal was jivelite navigation (not volume). I used one of these generic encoders:
https://www.amazon.com/gp/product/B06XQTHDRR/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1

I wired it to the following GPIO pins, similar to what was noted in a previous thread:


SW to GPIO26 (physical pin 37)
DT to GPIO20 (physical pin 38)
CLK to GPIO21 (physical pin 40)
+ to 3V3 (physical pin 1)
GND to Ground (physical pin 6)

I then downloaded pcp-sbpd.tcz and pigpio.tcz from the repo. I used this script (thank you @chill) and placed it in the tc user home directory:


#!/bin/sh

# start pigpiod daemon

pigpiod

# give the daemon a moment to start up before issuing the sbpd command

sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions

sudo modprobe uinput

sudo chmod g+w /dev/uinput

# issue the sbpd command

# This command will cause encoder to move selection right or left; Press=Enter; long press=down

sbpd e,20,21,KEY:KEY_LEFT-KEY_RIGHT,4 b,26,KEY:KEY_ENTER,4,0,KEY:KEY_DOWN,500

and this for the User Commands in Tweaks:

/home/tc/sbpd-script.sh

EDIT - Forgot to add that you need to set permissions on the script in the tc home directory to allow it to run:

chmod 755 sbpd-script.sh

Note that I am using KEY_LEFT and KEY_RIGHT for the rotation, and KEY_ENTER for the button press. I also bumped the detent count to 4 because it seemed too sensitive. This allows me to scroll through, e.g. album covers, then select one by pressing the encoder button. I am using a long press to simulate KEY_DOWN, allowing me to scroll down a list (as in tracks as they are displayed in jivelite). This is a little awkward but does the job with a single encoder and no extra buttons.

Also, paul's github repo readme entry is very helpful for understanding the sbpd paramteters: https://github.com/paul-1/SqueezeButtonPi-Daemon

Thanks to @pippin and @paul- for enabling this!

LiFePO4
2021-02-18, 20:02
Disregard post. Cancelled portable use case project.

jedisha
2021-02-21, 07:04
I had success getting an encoder to work. Thanks to others in this thread for ideas! Hopefully, this will help anyone trying to get this working. This is on piCorePlayer 6.1.
My main goal was jivelite navigation (not volume). I used one of these generic encoders:
https://www.amazon.com/gp/product/B06XQTHDRR/ref=ppx_yo_dt_b_asin_title_o05_s00?ie=UTF8&psc=1

I wired it to the following GPIO pins, similar to what was noted in a previous thread:


SW to GPIO26 (physical pin 37)
DT to GPIO20 (physical pin 38)
CLK to GPIO21 (physical pin 40)
+ to 3V3 (physical pin 1)
GND to Ground (physical pin 6)

I then downloaded pcp-sbpd.tcz and pigpio.tcz from the repo. I used this script (thank you @chill) and placed it in the tc user home directory:


#!/bin/sh

# start pigpiod daemon

pigpiod

# give the daemon a moment to start up before issuing the sbpd command

sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run sbpd with root permissions

sudo modprobe uinput

sudo chmod g+w /dev/uinput

# issue the sbpd command

# This command will cause encoder to move selection right or left; Press=Enter; long press=down

sbpd e,20,21,KEY:KEY_LEFT-KEY_RIGHT,4 b,26,KEY:KEY_ENTER,4,0,KEY:KEY_DOWN,500

and this for the User Commands in Tweaks:

/home/tc/sbpd-script.sh

Note that I am using KEY_LEFT and KEY_RIGHT for the rotation, and KEY_ENTER for the button press. I also bumped the detent count to 4 because it seemed too sensitive. This allows me to scroll through, e.g. album covers, then select one by pressing the encoder button. I am using a long press to simulate KEY_DOWN, allowing me to scroll down a list (as in tracks as they are displayed in jivelite). This is a little awkward but does the job with a single encoder and no extra buttons.

Also, paul's github repo readme entry is very helpful for understanding the sbpd paramteters: https://github.com/paul-1/SqueezeButtonPi-Daemon

Thanks to @pippin and @paul- for enabling this!

Hey @wtnh - did you have to change the permissions on the shell script which you created? I can't get this to work and am thinking it may be beacuse of file permissions?

-----EDIT - I have indeed now changed the ownership & permissions of the script (to 755 as per the other shell scripts which are in the /home/tc/ location)

below is the sbpd command that I'm trying to run (copied from Page 1 of this thread: GPIO pins 23 and 24 running rotary encoder and 25 for a play/pause button) HOWEVER, when I execute it I lose sound!

sbpd -d -s e,23,24,VOLM,0 b,25,PLAY,1

any ideas where I'm going wrong? (apoloigies in advance: I'm a bit of a noob!)


thanks,
Paul

LiFePO4
2021-02-21, 22:58
^^

My experience with this tool has only been a few hours total, so noob.

But maybe try passing the -t 1 or -t 0 parameters to pigpiod. I believe there's a conflict with your HAT.

Just search in the thread for the posts...


pigpiod -t 0 or pigpiod -t 1

I forget which one applies to HATs. I believe one applies to onboard audio, one to HAT.

So even if you follow the steps to a tee, everyone's audio requirements differ.

GL

jedisha
2021-02-22, 15:36
Dear all,

I've been trying somewhat in vain over the last few days to try and get SqueezeButtonPi daemon working on my PiZeroW (and iQaudio PiDIGI AMP+).

The aim is nothing crazy - just a rotary encoder with one push-button to give volume dial + play/pause button controls to pcp.

I've installed pcp-sbpd.tcz on pcp 7.0.0 and have created sbpd-script.sh (as per a previous post from @chill).

I'm trying to get the following commands to function:


sbpd -d -s e,23,24,VOLU,0 b,5,PLAY,1


However when sbpd-script.sh is executed the audio cuts out entirely and I can't seem to get anything out of it unless I reboot (the Pi doesn't crash or anything) Please see below for the script:


#!/bin/sh

# start pigpiod daemon

pigpiod

# give the daemon a moment to start up before issuing the sbpd command

sleep 1

# load uinput module, then set the permission to group writable, so you don't need to run s>

sudo modprobe uinput

sudo chmod g+w /dev/uinput

# issue the sbpd command

# This command will cause encoder to move selection right or left; Press=Enter; long press=>

sbpd -d -s e,23,24,VOLU,0 b,5,PLAY,1


When I created sbpd-script.sh I changed ownership to user 'tc' and changed it's permissions to 755 (to mirror the other shell scripts within the /home/tc/ location)

33520

Also, please see screengrab below for my Squeezelite settings (I believe I've correctly switched volume control to '-V Digital' so as to control the Alsa volume settings with a rotary encoder... or could this be one issue?)

33519

This evening I've noticed that it's when the
pigpiod command is called that the audio cuts out. Do I need to configure pigpio ?

I'm clearly out of my depth, but would love to get this working, so any help HUGELY appreciated, and if there's any further info which may help solve this then do let me know and I'll supply!


thanks so much guys!
Paul

jedisha
2021-02-22, 15:40
^^

My experience with this tool has only been a few hours total, so noob.

But maybe try passing the -t 1 or -t 0 parameters to pigpiod. I believe there's a conflict with your HAT.

Just search in the thread for the posts...


pigpiod -t 0 or pigpiod -t 1

I forget which one applies to HATs. I believe one applies to onboard audio, one to HAT.

So even if you follow the steps to a tee, everyone's audio requirements differ.

GL


@LiFePO4 - so sorry, I just added a post and completely missed your reply to my earlier post - I'll look into this right now! Thanks so much for the reply!

Paul

Paul Webster
2021-02-22, 21:49
Which physical pins have you connected wires to?
I ask because there is always the chance of confusion with pin numbers.
See https://pinout.xyz/

armaster
2021-03-05, 10:09
Hi,

I'm using RPI 3B+, HiFiBerry AMP2 HA. I'v only installed pcp-sbpd.tct with no settings and not running any command. I get sound from AMP2. But if I run sudo pigpiod, no sound comes from AMP2.

Some help please...

jd68
2021-03-05, 10:20
@armaster,

post #385 might be useful in your case.

armaster
2021-03-05, 12:24
@jd68,

Thanks for the hint. I replaced sudo pigpiod with sudo pigpiod -t 0 -f -l -s 10 and it works now with HifiBerry AMP2 HAT. Many thanks!

wtnh
2021-03-07, 08:05
Hey @wtnh - did you have to change the permissions on the shell script which you created? I can't get this to work and am thinking it may be beacuse of file permissions?

-----EDIT - I have indeed now changed the ownership & permissions of the script (to 755 as per the other shell scripts which are in the /home/tc/ location)

below is the sbpd command that I'm trying to run (copied from Page 1 of this thread: GPIO pins 23 and 24 running rotary encoder and 25 for a play/pause button) HOWEVER, when I execute it I lose sound!

sbpd -d -s e,23,24,VOLM,0 b,25,PLAY,1

any ideas where I'm going wrong? (apoloigies in advance: I'm a bit of a noob!)


thanks,
Paul

Sorry I did not see this sooner - yes, you need to:

chmod 755 sbpd-script.sh

but it looks like you figured it out anyway. Posting this so others can see it.

skywalker
2021-04-13, 14:04
Hi,

i have this rotary encoder AZDelivery KY-040(https://www.amazon.de/gp/product/B079H3C98M/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1) and i conneted
GND to PIN 25
+ to PIN 1
SW to PIN 29 (GPIO 5)
DT to PIN 37 (GPIO 26)

I startet the Raspberry and then on the command line

sudo pigpiod ;sleep 0.1; sbpd -v e,5,6,VOLU

I did not understand the output.

This is from 360 degrees clockwise


1618346983.1665 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618346983.1666 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618346983.2913 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618346983.2914 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618346986.5124 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618346986.5125 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618346986.6295 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618346986.6296 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618346988.9477 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618346988.9478 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618346989.0702 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618346989.0703 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618346989.7868 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618346989.7869 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618346989.9057 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618346989.9058 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618346992.5239 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618346992.5240 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618346992.6579 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618346992.6580 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]


This is from 360 degrees counterclockwise


1618347228.6224 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347228.6225 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347228.8504 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347228.8505 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347230.7757 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347230.7758 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347231.0925 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347231.0926 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347231.6107 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347231.6107 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347231.7284 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347231.7285 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347232.2450 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347232.2451 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347232.3634 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347232.3635 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347232.7802 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347232.7803 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347232.8961 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347232.8961 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347234.6137 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347234.6138 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347234.7321 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347234.7322 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347235.0551 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347235.0552 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347235.1712 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347235.1713 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347236.3872 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347236.3873 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347236.5050 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347236.5051 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347236.9231 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347236.9232 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347237.0396 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347237.0397 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347237.4572 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347237.4573 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347237.5723 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347237.5724 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347237.9889 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347237.9890 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347238.1056 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347238.1057 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347239.0229 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347239.0230 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347239.1391 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347239.1392 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347239.4549 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347239.4550 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347239.5706 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347239.5707 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347239.8868 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347239.8869 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347239.9989 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347239.9990 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347240.9172 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347240.9173 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347241.0346 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347241.0346 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]
1618347241.5519 6 control.c,466: Encoder on GPIO 26, 5 - value: -2, detents: -2, change: -1
1618347241.5520 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","-1"]
1618347241.6681 6 control.c,466: Encoder on GPIO 26, 5 - value: -1, detents: -1, change: 1
1618347241.6682 6 servercomm.c,74: Send Command:0, Fragment:["mixer","volume","+1"]


First: clockwise are 20 lines, counterclockwise are 64 lines
Second: The command changes by every Signal one time +1 and one time -1 what results in no change of Volume

It is equal if i use pigpiod -t 0 or -t 1

Does anyone have an idea whats wrong
Thanks,
sky

paul-
2021-04-13, 19:14
Unhook the + terminal and try it. I've only ever used 3 pin encoders. Gnd, and 2 gpio's.