Tactile switch as power button

Its a good idea to safely turn off your Pi with a good sudo shutdown -h now but that often means pulling out a keyboard or connecting to the console. With our kernel we added a cool module that will let you turn any GPIO into a power button. Since there's a couple of tactile switches right there on the front, lets turn one into a power button. Press once to properly turn off the pi, press again to start it up. Isn't that nice?

We'll be using GPIO #23, the left-most button on a PiTFT 2.8", on the 2.4" HAT, #16 is a good choice since its on a tactile button. But, you can use any GPIO  you want, really!

You will have to grab a pack of slim tactile switches or otherwise solder in a button

Add rpi_power_switch to /etc/modules and save

Now create a new conf file or edit our existing one with
sudo nano /etc/modprobe.d/adafruit.conf
and enter in the line
options rpi_power_switch gpio_pin=23 mode=0
Of course, change the gpio_pin setting to some other # if you wish. mode=0 means its a pushbutton not a switch. If you happen to install an on/off switch, use mode=1
To make it active immediately run sudo modprobe rpi_power_switch

Making it easier to click icons in X

If you want to double-click on icons to launch something in X you may find it annoying to get it to work right. In LXDE you can simply set it up so that you only need to single click instead of double.
From LXDE launch the file manager (sorry these pix are grayscale, still figuring out how to screenshot the framebuffer!)
Then under the Edit menu, select Preferences
Then select Open files with single click and close the window (you'll need to drag it over to get to the X button

Boot to X Windows on PiTFT

To enable booting straight to X windows on the PiTFT follow the steps below.  First make sure a display configuration which would conflict is not present by executing in a terminal on the Pi:

sudo mv /usr/share/X11/xorg.conf.d/99-fbturbo.conf ~

Don't worry if the command fails with an error that the file doesn't exist.  This failure is normal and should happen on a good PiTFT install.  You can ignore it and move on.

Next run the command below to open the nano text editor as root and create the file /usr/share/X11/xorg.conf.d/99-pitft.conf:

sudo nano /usr/share/X11/xorg.conf.d/99-pitft.conf

When the editor loads to a blank file, copy in the text below:

Section "Device"
  Identifier "Adafruit PiTFT"
  Driver "fbdev"
  Option "fbdev" "/dev/fb1"

Then save the file by pressing Ctrl-O and then enter, and finally exit by pressing Ctrl-X.

The step above will create a configuration file which tells X windows that it should use the PiTFT framebuffer (located at /dev/fb1) by default when it runs.

At this point you can use the raspi-config tool to enable booting to desktop just like normal on the Pi.  Run the following command:

sudo raspi-config

Then pick the Enable Boot to Desktop/Scratch option and choose if you want to boot to the console, desktop, or scratch environment.  After exiting the tool and rebooting you should see the Pi load X windows on the PiTFT after (be patient it can take around 30 seconds to load).

If you want to disable booting to X, just use the raspi-config command again to choose the console boot option.

Right-click on a touchscreen

Obviously if you have a touchscreen, it cannot tell what finger you are pressing with. This means that all 'clicks' are left clicks. But if you want a right-click, you can do it.

Just add the following lines into your InputClass of /etc/X11/xorg.conf.d/99-calibration.conf after the calibration section

Option "EmulateThirdButton" "1"
Option "EmulateThirdButtonTimeout" "750"
Option "EmulateThirdButtonMoveThreshold" "30"

So for example your file will look like:

Section "InputClass"
   Identifier      "calibration"
   MatchProduct    "stmpe-ts"
   Option  "Calibration"   "3800 120 200 3900"
   Option  "SwapAxes"      "1"
   Option "EmulateThirdButton" "1"
   Option "EmulateThirdButtonTimeout" "750"
   Option "EmulateThirdButtonMoveThreshold" "30"

This makes a right mouse click emulated when holding down the stylus for 750 ms.

(Thx adamaddin!)

Last updated on 2017-09-22 at 01.23.38 PM Published on 2013-11-29 at 02.19.02 PM