Raspberry PI with Waveshare Touchscreen
The Waveshare touchscreen shield is a nice extension for a Raspberry PI. It’s cheap and it converts your little Raspberry into a small, self contained device. I got one from Ebay, it costs about US$ 30 and it comes with a case and heat sinks. Not a bad deal.
UPDATE: See bottom
But configuration is everything but easy. Though the Waveshare screen comes with a CD containing a modified kernel, I didn’t want to sacrifice what I had already. Turns out: I didn’t have to. It’s actually not very complicated to get the screen and the touch working.
Step -1- ; Using the builtin FBTFT drivers:
pi@raspberrypi ~ $ sudo REPO_URI=https://github.com/notro/rpi-firmware BRANCH=builtin rpi-update
pi@raspberrypi ~ $ sudo reboot
Step -3- : Verify the SPI
pi@raspberrypi ~ $ dmesg | grep spi
Linux version 3.12.25+ (pi@raspi2) (gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) ) #1 PREEMPT Sat Aug 2 19:08:33 CEST 2014
bcm2708_spi bcm2708_spi.0: DMA channel 2 at address 0xf2007200 with irq 77
bcm2708_spi bcm2708_spi.0: DMA channel 4 at address 0xf2007400 with irq 20
bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
bcm2708_spi bcm2708_spi.0: SPI Controller running in dma mode
Step 4: Modifying the /etc/boot/cmdline.txt and add (on BIG line) :
fbtft_device.custom fbtft_device.name=fb_ili9340 fbtft_device.gpios=dc:22,reset:27 fbtft_device.bgr=1 fbtft_device.speed=48000000 fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo dma.dmachans=0x7f35 console=tty1 consoleblank=0 fbtft_device.fps=50 fbtft_device.rotate=270
This gave me a working console on my touchscreen. I rebooted the machine and noticed all the boot messages scrolling. Great. Moving on to the X server configuration:
Step 5: Modifying /usr/share/X11/xorg.conf.d/99-fbturbo.conf
Changed Option "fbdev" to "/dev/fb1"
This tells the X-Server to use the frame buffer -1-.
Step 6: Get touchscreen working.
This was a lot of tinkering. Added modules and config to /etc/modules
i2c-bcm2708
i2c-dev
ads7846_device cs=1 speed=1000000 model=7846 x_min=200 x_max=3840 y_min=200 y_max=3760 x_plate_ohms=60 pressure_max=255 gpio_pendown=17 keep_vref_on=1 swap_xy=1
Voila, the touchscreen is working. But not as expected, as x-axis and y-axis were flipped.
Step 7: Final adjustment
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 1
.. and the Waveshare touchscreen is ready to rumble. That little screen does not offer a lot of room to work with. I am using only the Chromium browser as a replacement for my graphical environment., Just start it in app mode without any menus or buttons and you can code your stuff in HTML or script. I created an .xinitrc and added
DISPLAY=:0 xinput --set-prop 'ADS7846 Touchscreen' 'Evdev Axis Inversion' 0 1 chromium --kiosk --incognito startpage.html
That’s it. I have a lot of fun with that US$ 30 screen. More info here and here.
UPDATE (Nov. 2017) : My waveshare didn’t work with the latest kernel 4.9.59+ anymore. So, I went to investigate. Turns out you will have to manually enable SPI and I2C in raspi-setup (or /boot/config.txt:
dtparam=i2c_arm=on dtparam=i2s=on dtparam=spi=on
You will also have to specify “spi_bcm2835” in your modules configuration. It also seems that this kernel does not have the “fbtft_device” driver built into the kernel. So you will have to specify it in your modules configuration as well. You can (and should) keep the configuration in your /boot/cmdline.txt . One last thing: This “fbtft_device” driver does not have any loadable fonts anymore. Configure your fonts via
sudo dpkg-reconfigure console-setup
and set to Terminus 6×12. You will need to install “kbd” to work with non 8-pixel wide fonts.
One thought on “Raspberry PI with Waveshare Touchscreen”