Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

FBTFT shield image

notro edited this page Feb 4, 2014 · 17 revisions

This wiki page gives information about the custom Raspberry Pi image made to work with some LCD shields.

First boot

On first boot, the filesystem will be expanded to fill the entire SD-card. This triggers a reboot.

On the regular Rasbian release, raspi-config is started automatically on the console. This image has turned off that feature.
raspi-config is made for larger screens, so it doesn't fit these small LCD displays.
It's best to connect to the Pi with SSH, and run raspi-config from there (putty can be used on Windows).

When networked, the IP address is shown after boot:

My IP address is 192.168.1.100

Raspbian GNU/Linux 7 raspberrypi ttyAMA0

raspberrypi login:

Touchpanel calibration

The touchpanel needs calibration to be precise. On first start of LXDE, a calibration window will be shown.
Use a stylus to to touch the points shown.

# no need to specify FRAMEBUFFER
startx

Some applications like PyGame, uses tslib for touch support.

sudo ts_calibrate

Test tslib
This is best done from SSH, because the Quit button is off screen and Ctrl-C doesn't work from the console.

sudo ts_test

Q&A

  • How do I change the display rotation?
    In /boot/cmdline.txt change bcm2708.fbtft_rotate (0,90,180,270)
    If touchpanel with ads7846 is in use, and rotation is changed 90 degrees to the left or right, remember to flip the value of swap_xy (0/1) in /etc/modules. Recalibration is also needed.

  • Why does the backlight turn off after 30 minutes?
    It is console blanking (more)

  • How do I change the boot console font?
    In /boot/cmdline.txt change fbcon=font: (more)

  • How to I recalibrate the touchpanel for X windows?
    Delete /etc/pointercal.xinput, and then startx

  • How do I switch the console back to HDMI?
    con2fbmap 1 0 (more)
    Do it permanently: remove fbcon=map from /boot/cmdline.txt

  • How do I start X windows on the HDMI output?
    FRAMEBUFFER=/dev/fb0 startx
    Do it permanently: Delete /etc/profile.d/startx_fb1.sh

  • How do I enable FBTFT driver debug output?
    In /boot/cmdline.txt change fbtft.debug (more)
    Example: Want to see fps numbers which is bit 5, running echo $((1<<5)) gives fbtft.debug=32

  • How is this image made?
    See: FBTFT-shield-image build process

  • How do I disable the filesystem expansion?
    Before booting, remove the file expand_rootfs from the boot partition

  • How can I update the kernel?
    sudo rpi-update (the correct environment variables are already set: sudo env | egrep "REPO_URI|BRANCH")

fbcp - Framebuffer copy

By mirroring /dev/fb0 onto /dev/fb1, we can take advantage of the GPU for hardware accelrated video playback (more).

Start

# We need to switch the console to fb0 first
con2fbmap 1 0
sudo service fbcp start

Stop

sudo service fbcp stop

Play video on /dev/fb0, which will also show up on /dev/fb1

# Big Buck Bunny
wget http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi
omxplayer big_buck_bunny_480p_surround-fix.avi

Enable automatic startup

# remove from /boot/cmdline.txt: fbcon=map:10

sudo update-rc.d fbcp defaults

Disable automatic startup

sudo update-rc.d fbcp remove

To remove the border on fb1, add this to /boot/config.txt

disable_overscan=1

Adafruit Camera app

If you have the Pi camera, you can turn your Raspberry Pi into a simple point-and-shoot digital camera.

Enable camera

sudo raspi-config

Install picamera version 0.8

sudo pip install picamera==0.8

Install the Adafruit camera app

wget https://github.com/adafruit/adafruit-pi-cam/archive/master.zip
unzip master.zip

Run it

cd adafruit-pi-cam-master
sudo python cam.py

Links:

Backlight

Backlight is controlled by the backlight subsystem.
Since there is no PWM kernel driver for the Raspberry Pi, brightness can't be controlled the usual way.
For displays that control backligh with GPIO18, a work around is to use the gpio utility to set this pin in PWM mode.
Note: This will mess up audio

# set gpio18 pin in PWM mode
gpio -g mode 18 pwm

# values: 0-1023
gpio -g pwm 18 200

Trigger commands with switches

It's possible to execute commands on the Pi when switches connected to GPIO's are activated.
This is done with the help of the triggerhappy daemon and the gpio_keys module.

The RPi-Display has pads that can be used with a switch. It is connected to GPIO22.

gpio_keys

The gpio_keys module creates a keyboard that listens on GPIO's for keypresses.
Keypresses generates events that other processes can receive.
The driver is configured with the gpio_keys_device module.

Here is an example creating a keyboard with one key:

sudo modprobe gpio_keys

# KEY_POWER 116 /* SC System Power Down */
sudo modprobe gpio_keys_device active_low keys=22:116

Make it permanent by adding it to /etc/modules

gpio_keys
gpio_keys_device active_low keys=22:116

Note: If there is no external pullup/down resistor, the internal ones must be activated with the pullup or pullup argument to gpio_keys_device.

Test this "keyboard":

pi@raspberrypi:~$ evtest
No device specified, trying to scan all of /dev/input/event*
Not running as root, no devices may be available.
Available devices:
/dev/input/event0:      Microsoft Basic Optical Mouse
/dev/input/event1:      LITEON Technology USB Multimedia Keyboard
/dev/input/event2:      LITEON Technology USB Multimedia Keyboard
/dev/input/event3:      ADS7846 Touchscreen
/dev/input/event4:      gpio-keys
Select the device event number [0-4]: 4
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "gpio-keys"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 116 (KEY_POWER)
Properties:
Testing ... (interrupt to exit)
Event: time 1390964791.200396, type 1 (EV_KEY), code 116 (KEY_POWER), value 1
Event: time 1390964791.200396, -------------- SYN_REPORT ------------
Event: time 1390964791.260402, type 1 (EV_KEY), code 116 (KEY_POWER), value 0
Event: time 1390964791.260402, -------------- SYN_REPORT ------------

triggerhappy (thd)

The triggerhappy daemon listens for input events, and executes actions based on it's configuration files. In the default setup, the daemon is run as user nobody. This makes it difficult to execute priviliged commands. By changing the user to pi, we can use sudo for the priviliged commands.

sudo nano /etc/init.d/triggerhappy

change user from nobody to pi

DAEMON_ARGS="--daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile $PIDFILE --user pi /dev/input/event*"

Now we find the event for our key:

pi@raspberrypi:~$ thd --dump /dev/input/event* | grep ^#
# KEY_POWER     1       command
# KEY_POWER     0       command

Let's make a config file that poweroff the Pi when this key is pressed

sudo nano /etc/triggerhappy/triggers.d/poweroff.conf

content

KEY_POWER	1	sudo /sbin/poweroff

Restart triggerhappy

sudo service triggerhappy restart

If you get: Unable to parse trigger line:, remove trailing empty lines from the config file.

Pressing the switch should now poweroff the Pi.

Toggle backlight

by pressing Music key on USB keyboard

thd --dump /dev/input/event* | grep ^#
# KEY_CONFIG    1       command
# KEY_CONFIG    0       command

Make config file

sudo nano /etc/triggerhappy/triggers.d/backlight.conf

content

KEY_CONFIG    1       sudo /usr/local/bin/bl_toggle

Restart daemon

sudo service triggerhappy restart

Backlight toggle script

sudo nano /usr/local/bin/bl_toggle

content

#!/bin/sh

dev=$(echo /sys/class/backlight/*)
state=$(cat $dev/bl_power)

if [ $state -ne 0 ]; then
	sudo sh -c "echo 0 > $dev/bl_power"
else
	sudo sh -c "echo 1 > $dev/bl_power"
fi

Make it executable

sudo chmod +x /usr/local/bin/bl_toggle

spidev

Enable spidev for userspace SPI access. This can only be done on shields without a touch controller, as the Pi only has 2 available chip selects.

sudo modprobe spi-config devices=bus=0:cs=1:modalias=spidev:speed=500000

dmesg | tail
[ 7721.899378] spi_config_register: device description: bus=0:cs=1:modalias=spidev:speed=500000
[ 7721.899471]  spi_config_match_cs: SPI0: check CS=0 to be 1
[ 7721.903949] spi_config_register:spi0.1: registering modalias=spidev with max_speed_hz=500000 mode=0 and no interrupt

ls -l /dev/spi*
crw-rw---T 1 root spi 153, 0 Jan 27 20:43 /dev/spidev0.1

piwik

Clone this wiki locally