-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bluetooth remote control via GPIO #101
base: master
Are you sure you want to change the base?
Add bluetooth remote control via GPIO #101
Conversation
@tmigone i have a problem. Are there any ways of communicating between the multi room devices. I had an idea: Pressing buttons on the client device is acting like pressing buttons on the server device itself. |
@AlexProgrammerDE great idea here! I think this is going to be an awesome addition to the project. |
9e70c4a
to
25d8fb6
Compare
This comment has been minimized.
This comment has been minimized.
@AlexProgrammerDE this looks awesome! Regarding your question, you can send messages between devices using the
You could do something like EDIT: Now that i think of it, to use this you would need to migrate your control code to node. So i think it's fine if you focus on one device and once that is resolved we can look into the whole fleet. |
a62c297
to
1b3d55e
Compare
@chrisys and @tmigone i had an idea. 🌟 What are buttons without an case? https://github.com/balenalabs/boombeastic/ has its own cases. Could anyone create some 3D models? Buttons integrated would be needed. |
d0d58a9
to
11798d1
Compare
Hey @AlexProgrammerDE do you think this would work with the Pimoroni Pirate Audio HATs? Check out @Fiqq90 comment in #111 |
Hi @chrisys |
@chrisys i just saw the docs. I will look into it. |
@chrisys |
@Fiqq90 can you test this on your Pirate audio HAT and let us know how if it works? |
By the way @chrisys does the code work? I had it only tested with my Android phone. Does it work with IPhones? |
@AlexProgrammerDE I haven't had a chance to test yet |
@chrisys @AlexProgrammerDE I would love to test it out, but unfortunately I am new to all this. Any guides to get me started on testing via PR? I assume that this latest update for the pimoroni has not been merged with the master that I can download? |
@Fiqq90 it is very easy to use my code. I made a fork of this repository on github. You can very easy download the zip file from there and push it like before. |
@Fiqq90 the url of my repository is: https://github.com/AlexProgrammerDE/balena-sound |
@AlexProgrammerDE Pushed the files from your repo. Unfortunately the buttons still do not work for the pirate audio HAT. Buttons still does nothing to control spotify via bluetooth. |
From the log screen, volume up is still GPIO17, bluetooth button -> GPIO27, volume down -> GPIO22. Could we set the inputs to play/pause -> GPIO5, vol down -> GPIO6, next -> GPIO16, vol up -> GPIO20? |
@Fiqq90 i did already think of that case. I implemented it already. |
@chrisys can you test it please and give me feedback? I am almost finished. |
c820307
to
24cd111
Compare
@AlexProgrammerDE I will test it but need to find the hardware to put some buttons on a Pi first |
@chrisys it works with jumper cables too. I put many information to the Readme. That should help you to work with it. |
Change-type: major
Change-type: major
Change-type: major
@balena-ci retest |
An error occurred whilst building your landr site preview:
|
@tmigone this PR is now open for about 4 months. Can we merge it soon? |
@balena-ci retest |
hey @AlexProgrammerDE sorry it took me so long, I'll work on testing this PR this week so we can have it in 2.x. |
# Set up + volume | ||
if [[ ! -d /sys/class/gpio/gpio$VOLUME_UP_GPIO ]]; then | ||
echo "$VOLUME_UP_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$VOLUME_UP_GPIO/direction | ||
|
||
# Set up bluetooth | ||
if [[ ! -d /sys/class/gpio/gpio$BLUETOOTH_GPIO ]]; then | ||
echo "$BLUETOOTH_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$BLUETOOTH_GPIO/direction | ||
|
||
# Set up - volume | ||
if [[ ! -d /sys/class/gpio/gpio$VOLUME_DOWN_GPIO ]]; then | ||
echo "$VOLUME_DOWN_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$VOLUME_DOWN_GPIO/direction | ||
|
||
# Set up next | ||
if [[ ! -d /sys/class/gpio/gpio$NEXT_GPIO ]]; then | ||
echo "$NEXT_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$NEXT_GPIO/direction | ||
|
||
# Set up previous | ||
if [[ ! -d /sys/class/gpio/gpio$PREVIOUS_GPIO ]]; then | ||
echo "$PREVIOUS_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$PREVIOUS_GPIO/direction | ||
|
||
# Set up utput gpio (there is one energy input missing) | ||
if [[ ! -d /sys/class/gpio/gpio$OUTPUT_GPIO ]]; then | ||
echo "$OUTPUT_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "out" > /sys/class/gpio/gpio$OUTPUT_GPIO/direction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could eliminate a lot of code using a function here. Haven't tested it, but this should be ok:
# Set up + volume | |
if [[ ! -d /sys/class/gpio/gpio$VOLUME_UP_GPIO ]]; then | |
echo "$VOLUME_UP_GPIO" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "in" > /sys/class/gpio/gpio$VOLUME_UP_GPIO/direction | |
# Set up bluetooth | |
if [[ ! -d /sys/class/gpio/gpio$BLUETOOTH_GPIO ]]; then | |
echo "$BLUETOOTH_GPIO" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "in" > /sys/class/gpio/gpio$BLUETOOTH_GPIO/direction | |
# Set up - volume | |
if [[ ! -d /sys/class/gpio/gpio$VOLUME_DOWN_GPIO ]]; then | |
echo "$VOLUME_DOWN_GPIO" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "in" > /sys/class/gpio/gpio$VOLUME_DOWN_GPIO/direction | |
# Set up next | |
if [[ ! -d /sys/class/gpio/gpio$NEXT_GPIO ]]; then | |
echo "$NEXT_GPIO" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "in" > /sys/class/gpio/gpio$NEXT_GPIO/direction | |
# Set up previous | |
if [[ ! -d /sys/class/gpio/gpio$PREVIOUS_GPIO ]]; then | |
echo "$PREVIOUS_GPIO" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "in" > /sys/class/gpio/gpio$PREVIOUS_GPIO/direction | |
# Set up utput gpio (there is one energy input missing) | |
if [[ ! -d /sys/class/gpio/gpio$OUTPUT_GPIO ]]; then | |
echo "$OUTPUT_GPIO" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "out" > /sys/class/gpio/gpio$OUTPUT_GPIO/direction | |
function configure_gpio() { | |
local GPIO_PIN="$1" | |
local DIRECTION="$2" | |
if [[ ! -d /sys/class/gpio/gpio$GPIO_PIN ]]; then | |
echo "$GPIO_PIN" > /sys/class/gpio/export | |
sleep 1 | |
fi | |
echo "$DIRECTION" > /sys/class/gpio/gpio$GPIO_PIN/direction | |
} | |
configure_gpio "$VOLUME_UP_GPIO" "in" | |
configure_gpio "$BLUETOOTH_GPIO" "in" | |
configure_gpio "$VOLUME_DOWN_GPIO" "in" | |
configure_gpio "$NEXT_GPIO" "in" | |
configure_gpio "$PREVIOUS_GPIO" "in" | |
configure_gpio "$OUTPUT_GPIO" "out" |
VOLUME_UP_GPIO=$(</usr/src/volume_up_gpio) | ||
|
||
BLUETOOTH_GPIO=$(</usr/src/bluetooth_gpio) | ||
|
||
VOLUME_DOWN_GPIO=$(</usr/src/volume_down_gpio) | ||
|
||
NEXT_GPIO=$(</usr/src/next_gpio) | ||
|
||
PREVIOUS_GPIO=$(</usr/src/previous_gpio) | ||
|
||
OUTPUT_GPIO=$(</usr/src/output_gpio) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, the other script writes the values into these files, and then this scripts reads the values.
Are the files used anywhere else? Can't we just have all done here and avoid the files alltogether?
while [[ "$(cat /sys/class/gpio/gpio$NEXT_GPIO/value)" == 1 ]]; do | ||
if [[ "$SKIP_STOP" == 0 ]]; then | ||
printf "Playing the next track. \n" | ||
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.bluez.MediaPlayer1.Next | ||
sleep 0.5 | ||
fi | ||
SKIP_STOP="1" | ||
done | ||
|
||
SKIP_STOP="0" | ||
|
||
# Previous track | ||
while [[ "$(cat /sys/class/gpio/gpio$PREVIOUS_GPIO/value)" == 1 ]]; do | ||
if [[ "$SKIP_STOP" == 0 ]]; then | ||
printf "Playing the previous track. \n" | ||
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.bluez.MediaPlayer1.Previous | ||
sleep 0.5 | ||
fi | ||
SKIP_STOP="1" | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before, if the code is nearly identical we should try and use functions to reduce code (also easier maintenance!)
Change-type: major
Hi everyone! With #83 becomes balena-sound to a multi speaker project. But i think a good speaker has its own on-board music and volume control buttons. Here is a example:
Roadmap: (At the top are the more important things. )
finished:
bugs:
@tmigone and @chrisys i will maybe need help from your side. If i run into some problems i will let you know in the comment section below.
Things i have to remember:
echo "$(amixer -D bluealsa scontrols)" | sed -n " s,[^']*'\([^']*\).*,\1,p "
VOLUME="$(amixer -D bluealsa get "$DEVICE" | awk '$0~/%/{print $5}' | tr -d '[]%')"
VOLUME_PARSED="$(echo "${VOLUME}" | head -1)"
https://askubuntu.com/questions/1113050/sending-pause-resume-playing-and-next-previous-track-bluetooth-commands
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED org.bluez.MediaControl1.Play > /dev/null