Author Gravatar Image LADY ADA

Controlling the backlight

There's a 4-LED backlight on the TFT and it draws ~75mA at all times. There might be times you'd like to save some power and turn off the backlight. The screen and touchplate will still work, you just can't see anything. We designed the board with the STMPE610 touchscreen controller which has 2 extra GPIO and tied one of them to the transistor that controls the backlight. You can use the command line to control the backlight.

Start by getting access to the GPIO by making a device link

sudo sh -c "echo 508 > /sys/class/gpio/export"
ls -l /sys/class/gpio
Please note, previous versions of the PiTFT kernel had theSTMPE GPIO pin '252' not '508' so just substitue that number

Once you verify that you see GPIO #508, then you can set it to an output, this will turn off the display since it will output 0 by default

sudo sh -c "echo 'out' > /sys/class/gpio/gpio508/direction"

Then turn the display back on with

sudo sh -c "echo '1' > /sys/class/gpio/gpio508/value"

or back off

sudo sh -c "echo '0' > /sys/class/gpio/gpio508/value"

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. You can use any of them or other GPIO but #23's our favorite number anyways.

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:

Copy Code
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:

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

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

Copy Code
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:

Copy Code
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.

Last updated on 2015-03-26 at 10.26.58 PM Published on 2013-11-29 at 07.19.02 PM