Adding XPT2046 ( ADS7846 ) Touchscreen Support to Beaglebone Black

I have been playing around with the Beaglebone Black, mainly due to the fact that in addition to being powerful, the hardware designs for it are open source, unlike the Raspberry Pi, which means that if you need to design your own system using this as a platform, it is a lot easier to get hardware documentation and support to do so.

As a part of my experiments, I was trying to integrate a Waveshare 5 inch HDMI LCD with the BBB. The LCD itself looks good, and is packaged well but it was designed to work with a Raspberry Pi. The product is good, but the Waveshare folks are not very cooperative when it comes to sharing additional documentation or source code for the Linux drivers. As a result, the screen displayed stuff straight out of the box over HDMI (although Green shows up as blue, that remains an issue to be fixed), but the touch panel was another matter altogether.

Waveshare BeagleBone Black 5 inch HDMI LCD

The back of the screen says that the screen is based on the XPT2046 touch screen controller. A quick search reveals that the controller will work with the same drivers as the ADS7846 chip made by TI. That unfortunately was the only quick part. The controller worked over SPI, and we had decided to use SPI0 (since SPI1 on the BBB is shared with HDMI), but there were not too many useful (and relevant, not outdated) examples that showed how to enable SPI0 for use.

NOTE : This post assumes you are using Kernel version 4.1.0-rc5-bone3 , armhf architecture. If not, a lot of what I am talking about may not apply.

After three days of attacking the problem, I conceded that we needed help, and decided to reach out to Robert Nelson, who is quite an active maintainer of many BBB repositories. Turns out, we were messing around with the wrong Linux Kernel version. The “cape manager” which is the abstraction that lets you use the pins on the BBB, was stuck in “rewrite hell”, as RCN told me, and that pursuing anything between 3.8 and 4.1 was practically futile. I tried out 4.1.0-rc5-bone3 on his suggestion, and at least got the cape manager back. Following tutorials after that did not help much either, since a lot of things had changed.

Finally after one more day of battle, I was able to get the touch panel to work. Turns out, the 4.1.0 kernel already includes support for the ADS7846, which means you don’t have to compile the kernel module for it. The BBB uses something known as a Device Tree that lets it abstract away the physical hardware from the multiple functions it can perform, and lets you enable and disable it just using config files. The Device Tree Overlay is, as the name suggests, an overlay. It is not hardwired, but can easily by enabled or disabled at runtime based on your needs.

For the sake of simplicity, I have posted the code (or rather the device tree source or dts file) on Github here:

It has comments wherever I can explain what’s going on.

The file will need to compiled with the latest version of the device tree compiler, otherwise you’ll get an error later on when you are trying to load the overlay. You can follow the steps in the Readme here : BBB Overlays

The physical connections are below :

Screen <———> Beagle Bone Black
MOSI <———> SPI0_D0
MISO <———> SPI0_D1
CE1 <———> SPI0_CS0
P6 <———> Pin 23