[TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Here is all the tutorials, FAQ and support for RaspiBoy Kit
Post Reply
Vilikt
Posts: 15
Joined: Mon 15 Jan 2018 11:13

[TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by Vilikt »

Hello,

I worked on a Python script to make possible to map the Battery Indicator Button (BIB) to ESC Keyboard key.
It could be useful if you manage to play ports like SORR or Solarus games for example, as you can't propely exit theses games without a keyboard connected to your Raspiboy.

This doesn't need retrogame app, but only Python uinput module.

First, download the last module version (0.11.2) here

Connect to your Raspiboy in SFTP (only if you are using Raspberry Pi Zero W).
If you have only Raspberry Pi Zero, you may open your Raspiboy and read your µSD on a Linux distribution to access to all partitions (you could use virtual machine as well).

Unzip python-uinput-0.11.2.tar.gz to /home/pi/, so you will have /home/pi/python-uinput-0.11.2

Open a SSH session to your raspiboy (if you only have Raspberry Pi Zero, you may connect a USB Keyborad and press F4).

type theses commands :

Code: Select all

cd python-uinput-0.11.2/
sudo python setup.py build
sudo python setup.py install
At this point uinput is installed on your Raspiboy.

Now let's write a python script that will map the BIB. The file escbutton.zip is attached below
escbutton.zip
Don't forget to unzip the file !!!
(843 Bytes) Downloaded 403 times


Unzip it and put it in /home/pi/ by using your favorite SFTP client (Like WinSCP or FileZilla). So you will have /home/pi/escbutton.py.

Last but not least, let's make the script autorun during the boot process.

You will need a root access to your Raspiboy, so please watch this video if you don't know how.

Once your connect in SFTP with root acces, edit the file /etc/rc.local that's should looks like this :

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

exit 0
So just add theses lines just before the exit 0 :

Code: Select all

(sleep 10;python /home/pi/escbutton.py) &
printf "Power Status Button is mapped"
The first line just run the python script we add before on background.
You can keep the second if you want but it's not necessary.

Now you can reboot your console, that's all !

Note that if you have problem you should always connect to your Raspiboy in SFTP on root access, edit the rc.local file and delete or comment the lines.

uinput seems to be a powerful module, able to makes intersting things.
I'll look forward to try to make more things with the back buttons :D

I hope you enjoy this tutorial and that it will be useful ;)

See you
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by roostaar »

Great post. I tried this as well as the soft shutdown post viewtopic.php?f=2&t=1616
but neither are working for me. I will try these on my Pi3 hopefully tomorrow. If that works then maybe I have a faulty PCB?
Vilikt
Posts: 15
Joined: Mon 15 Jan 2018 11:13

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by Vilikt »

No faulty PCB here to my mind :geek:

Try to execute the script via SSH connection and see if you have any error.
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by roostaar »

Vilikt wrote:No faulty PCB here to my mind :geek:

Try to execute the script via SSH connection and see if you have any error.
Have tested exhaustively with Pierre’s assistance and it appears the PCB is indeed not responding as planned.

New one on the way! Pierre is a top lad.
Vilikt
Posts: 15
Joined: Mon 15 Jan 2018 11:13

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by Vilikt »

Ok ! Nice to hear that :)

Let me know if you have trouble with the script ;)
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by roostaar »

Vilikt wrote:Ok ! Nice to hear that :)

Let me know if you have trouble with the script ;)
Thanks mate. No issues with the script, works a treat on my RPi3. Rigged up a mini arcade button to pin 5 and boom!
Attachments
91DC1CBE-2851-4A0D-BC8D-14FA6CE049DF.jpeg
91DC1CBE-2851-4A0D-BC8D-14FA6CE049DF.jpeg (24.06 KiB) Viewed 7712 times
E51B0E60-5384-4B96-A895-0BA6E7B22189.jpeg
E51B0E60-5384-4B96-A895-0BA6E7B22189.jpeg (34.81 KiB) Viewed 7712 times
Vilikt
Posts: 15
Joined: Mon 15 Jan 2018 11:13

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by Vilikt »

Niiice :)

Did you made the case yourself ?
roostaar
Posts: 31
Joined: Tue 2 Jan 2018 00:39

Re: [TUTO] Mapping Battry Indicator Button as ESC Keyboard (or other if you want)

Post by roostaar »

Cheers!

It was about £5 from eBay. Had to modify quite a bit to fit this button in but works an absolute treat.

:)
Post Reply