Friday, February 27, 2015

Waveshare SpotPear 3.2 inch TFT touchscreen for Raspberry Pi

A word of caution: setting up Waveshare touchscreen for Pi is not very straightforward. I spent a long on it. Get a better touchscreen if you can. 

Waveshare touchscreen may be shipped with a CD with a special factory image. With the factory image, all you need is to boot up with a microSD with the image. However, due to some issues that I could not fix, the factory image does not support EW-7811Un WiFi dongle. I tried for quite a while, such as rebuilding the kernel as some websites suggest, but I could not make it work.
Then I had to try to configure the touchscreen based on common Raspbian (Debian Wheezy, 2015-02-16). I followed the steps by Notro to install FBTFT drivers as loadable modules:

1. Modify /usr/share/X11/xorg.conf.d/99-fbturbo.conf: change fb0 (HDMI output) to fb1 (SPI output), so that the line will look like:

 Option          "fbdev" "/dev/fb1"

2. Make changes in /boot/config.txt so that it has the following:

# uncomment to force a console size. By default it will be display's size minus
# overscan.
framebuffer_width=800
framebuffer_height=600

dtparam=spi=on

3. Enable SPI using raspi-config.

4. Install Notro's kernel module:
sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update
Reboot.


5. To load the kernel module automatically at boot time, I modified /etc/modules and the following is what it is now: 

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-bcm2708
i2c-dev
fbtft_device name=waveshare32b debug=3 rotate=90 width=320 height=240
ads7846_device model=7846 cs=1 gpio_pendown=17  keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

w1-gpio
w1-therm

Alternatively, the module can be loaded if you type:
sudo modprobe fbtft_device name=waveshare32b
This seems not loading the touch, but the display should work fine now.
I did not change /boot/cmdline.txt.

6. To test:
Typing dmesg | grep tft should show that SPI devices registered.

   6-1: Add in /etc/rc.local before exit 0 if you wish to start GUI automatically on the touchscreen upon startup:
     su -l pi -c startx  
   6-2: Type the following to start xwindows:
          FRAMEBUFFER=/dev/fb1 startx
   6-3: Type the following to start the console on the touchscreen:
con2fbmap 1 1



See also the following websites for excellent tutorials: