Hyperpixel 3.5 Pimoroni

3.5 inch touch screen. Superseeded by Hyperpixel 4.0

Reasonable quality, touch is, though it i capacitive, not too easy to use. Resistive screens an be handled with pens, not this one.

With current Buster not a perfect pair.

Two experiments:

Raspberry Pi 2 B V1.2 success

1 imaged a SD with current Buster (feb 2020)
2 booted on a Pi 4 1 GB
3 did the usual raspi-config things and update/upgrade
4 checked out the system, works as expected
5 curl https://get.pimoroni.com/hyperpixel | bash
6. rebooted , installed Hyperpixel

Result is a working display, HDMI whosw rainbow screen, touch is wrong, cursor moves opposite directions, axes mixed up.
So not too bad, but touch not configured correctly.

Fixed with, in a console window, the command

$ hyperpixel-rotate normal

which changed the orientation of the screen to what is aleady was, and changed the touch matrix to a working touch.

So far so good.

Raspberry Pi 4 1 GB failure

To check out the Pi4, current Buster (feb 2020) and Hyperpixel 3.5 I did the following:

1 imaged a SD with current Buster (feb 2020)
2 booted on a Pi 4 1 GB
3 did the usual raspi-config things and update/upgrade
4 checked out the system, works as expected
5 curl https://get.pimoroni.com/hyperpixel | bash
6. rebooted , installed Hyperpixel

Result is not a working Hyperpixel display, but reverse image on HDMI, Hyperpixel dead.
Which is the same effect as booting from the working Raspberry Pi 2 SD.
Maybe the curl https://get.pimoroni.com/hyperpixel | bash gets the old hyperpixel install and not the Pi 4 version? Looks like it.

So back to

1 imaged a SD with current Buster (feb 2020)
2 booted on a Pi 4 1 GB
3 did the usual raspi-config things and update/upgrade
4 checked out the system, works as expected
5 downloaded the Hyperpixel Pi 4 git repository
6. rebooted , installed Hyperpixel with ./setup.h

Result is Hyperpixel noise banner, HDMI shows normal screen

So install fails with the curl or setup, and instructions clearly wrong.Issue opened at Pimoroni.

Adafruit PITFT 2.8 resistive

Image Raspbian full if you want a desktop, else lite is sufficient for CLI.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get remove piwiz

sudo raspi-config
 - password
 - Boot to console autologon, no splash screen
 - localization time zone
 - Interfacing  - SSH SPI I2C Serial
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
chmod +x adafruit-pitft.sh
sudo ./adafruit-pitft.sh

Choose 1 tft 2.8 resistive
Choose 1 90 degrees
Console on tft Yes

reboot and console on tft visible

sudo sed -i "s+/dev/fb0+/dev/fb1+" /usr/share/X11/xorg.conf.d/99-fbturbo.conf
y       cat /usr/share/X11/xorg.conf.d/99-fbturbo.conf

sudo nano /usr/share/X11/xorg.conf.d/40-libinput.conf
At section touchscreen, add the following line
     Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"

This matrix fits for the 90° turned display (see rotate=90 at /boot/config.txt). In case you have turned the display 270, the line must be
     Option "TransformationMatrix" "0 1 0 -1 0 1 0 0 1"

This design uses the hardware SPI pins (SCK, MOSI, MISO, CE0, CE1) as well as GPIO #25 and #24. All other GPIO are unused. Since we had a tiny bit of space, there's 4 spots for optional slim tactile switches wired to four GPIOs, that you can use if you want to make a basic user interface. For example, you can use one as a power on/off button.

We bring out GPIO #23, #22, #21, and #18 to the four switch locations!

The last known for-sure tested-and-working version is March 13, 2018 (https://downloads.raspberrypi.org/raspbian/images/raspbian-2018-03-14/) from https://downloads.raspberrypi.org/raspbian/images/

It works OK with recent Buster (Jan 2020), tested March 2020

Setting up the Touchscreen

Now that the screen is working nicely, we'll take care of the touchscreen. There's just a bit of calibration to do, but it isn't hard at all.

Before we start, we'll make a udev rule for the touchscreen. That's because the eventX name of the device will change a lot and its annoying to figure out what its called depending on whether you have a keyboard or other mouse installed.

Check if this already done

   sudo nano /etc/udev/rules.d/95-stmpe.rules

   to create a new udev file and copy & paste the following line in:
   SUBSYSTEM=="input", ATTRS{name}=="stmpe-ts", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen" 

   sudo rmmod stmpe_ts
   sudo modprobe stmpe_ts

Then type 
ls -l /dev/input/touchscreen

It should point to eventX where X is some number, that number will be different on different setups since other keyboards/mice/USB devices will take up an event slot

There are some tools we can use to calibrate & debug the touchscreen. Install the "event test" and "touchscreen library" packages with

sudo apt-get install evtest tslib libts-bin

Now you can use some tools such as

sudo evtest /dev/input/touchscreen

which will let you see touchscreen events in real time, press on the touchscreen to see the reports.

AutoMagic Calibration Script
If you rotate the display you need to recalibrate the touchscreen to work with the new screen orientation. You can manually run the calibration processes in the next section, or you can re-run the installer script and select a new rotation:

Try using this default calibration script to easily calibrate your touchscreen display. Note that the calibration values might not be exactly right for your display, but they should be close enough for most needs. If you need the most accurate touchscreen calibration, follow the steps in the next section to manually calibrate the touchscreen.
Manual Calibration
If the "automagic" calibration technique isn't working for you, or you have some other setup where you need to carefully calibrate you can do it 'manually'

You will want to calibrate the screen once but shouldn't have to do it more than that. We'll begin by calibrating on the command line by running

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate

follow the directions on the screen, touching each point. Using a stylus is suggested so you get a precise touch. Don't use something metal, plastic only!

Next you can run

sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test

which will let you draw-test the touch screen. Go back and re-calibrate if you feel the screen isn't precise enough!

X Calibration
You can also calibrate the X input system but you have to use a different program called xtcal (xinput_calibrator no longer works)

You can do this if the calibration on the screen isn't to your liking or any time you change the rotate=XX module settings for the screen. Since the screen and touch driver are completely separated, the touchscreen doesn't auto-rotate

Download and compile it with the following:

 Download: fileCopy Code
sudo apt-get install libxaw7-dev libxxf86vm-dev libxaw7-dev libxft-dev
git clone https://github.com/KurtJacobson/xtcal
cd xtcal
You must be running PIXEL (the GUI) while calibrating.

Before you start the calibrator you will need to 'reset' the old calibration data so run

DISPLAY=:0.0 xinput set-prop "stmpe-ts" 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1
Now you'll have to run the calibrator while also running X. You can do this by opening up the terminal program and running the the xtcal command (which is challenging to do on such a small screen) OR you can do what we do which is create an SSH/Terminal shell and then run the calibrator from the same shell, which requires the following command:

DISPLAY=:0.0 xtcal/xtcal -geometry 640x480
Note that the geometry may vary!

If you are using a 2.4"/2.8"/3.2" 320x240 display with landscape orientation, use 640x480. If you're in portrait, use 480x640.

If you are using a 3.5" display with landscape, use 720x480, portrait is 480x720

Follow the directions on screen

Once complete you'll get something like:
Run sudo nano /usr/share/X11/xorg.conf.d/20-calibration.conf and copy the 9 numbers into the TransformationMatrix option so it looks like:

 Download: fileCopy Code
Section "InputClass"
        Identifier "STMPE Touchscreen Calibration"
        MatchProduct "stmpe"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "TransformationMatrix" "-0.000087 1.094214 -0.028826 -1.091711 -0.004364 1.057821 0 0 1"
or whatever you got, into there.

You will want to reboot your Pi to verify you're do

Kedei 2 touch screen

Something I bought in 2015, 2 Kedei 2 lcd 3.5 inch touch screens. Worked, albeit slow.
With a Wheezy image, not to be updated due to the kernel doing its SPI thing to copy the framebuffer to the LCD screen via fbcopy.

March 2020, installed the Kedei screen on a Raspberry Pi V2 and inserted the archived SD card. It works!

Update? No, the official repository moved on. But there is a legacy repository!

Replace this line in /etc/apt/sources.list

deb http://legacy.raspbian.org/raspbian/ wheezy main contrib non-free rpi

and teh apt-get update works (be it with some warnings).

To test I installed MC and that went allright (be it with some warnings).

Screen quality is not too bad, screen refreshes are slow. In console mode it reminds me of the 9600 baud serial terminals!

Now I want autologon, no option in old raspiconfig!

From https://www.elinux.org/RPi_Debian_Auto_Login

sudo nano /etc/inittab
Scroll down to:

1:2345:respawn:/sbin/getty 115200 tty1
and change to

#1:2345:respawn:/sbin/getty 115200 tty1
Under that line add:

1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1

Auto StartX (Run LXDE)
In Terminal:

sudo nano /etc/rc.local
Scroll to the bottom and add the following above exit 0:

su -l pi -c startx

WD Pidrive


USB quirks


1. Finding the VID and PID of your USB SSD
Disconnect the USB SSD. In a terminal window, run the command sudo dmesg -C.
Now, plug in the SSD and run dmesg with no parameters.
You should get output that looks like this:

[ 4096.609817] usb 2-1: new SuperSpeed Gen 1 USB device number 4 using xhci_hcd
[ 4096.646369] usb 2-1: New USB device found, idVendor=2109, idProduct=0715, bcdDevice=a0.00
[ 4096.646385] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 4096.646397] usb 2-1: Product: SABRENT
[ 4096.646409] usb 2-1: Manufacturer: SABRENT
[ 4096.646421] usb 2-1: SerialNumber: 000000123AD2
[ 4096.655154] scsi host0: uas
[ 4096.669178] scsi 0:0:0:0: Direct-Access SABRENT 2210 PQ: 0 ANSI: 6
[ 4096.670993] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 4096.673710] sd 0:0:0:0: [sda] 234441648 512-byte logical blocks: (120 GB/112 GiB)
The idVendor and idProduct are the two hexadecimal numbers you need to take a note of.

1a. Multiple SSDs
If you have multiple USB SSD devices plugged into a single Pi 4, then for each device experiencing issues repeat Step 1 above and make a note of each idVendor and idProduct pair.

2. Add the quirks to /boot/cmdline.txt
Run a text editor as root – sudo nano /boot/cmdline.txt from the console or sudo leafpad /boot/cmdline.txt from the desktop.
At the start of the line of parameters, add the text usb-storage.quirks=aaaa:bbbb:u where aaaa is the idVendor for your device and bbbb is the idProduct. So, with the device above the string will be usb-storage.quirks=2109:0715:u.
cmdline.png (21.45 KiB) Viewed 46967 times
For multiple devices with different VID:PID pairs, expand the parameter with a comma between each vid:pid:u triplet like this: usb-storage.quirks=0123:4567:u,2109:0715:u.

Save the file and exit the editor.

3. Reboot.

4. Check that it worked
To check that the quirk has been applied successfully, run dmesg | grep usb-storage and check that the VID and PID is listed as having a quirk applied:

[ 2.495725] usb 2-1: UAS is blacklisted for this device, using usb-storage instead
[ 2.512739] usb 2-1: UAS is blacklisted for this device, using usb-storage instead
[ 2.531823] usb-storage 2-1:1.0: USB Mass Storage device detected
[ 2.549642] usb-storage 2-1:1.0: Quirks match for vid 2109 pid 0715: 800000
[ 2.566177] scsi host0: usb-storage 2-1:1.0

Re: STICKY: If you have a Raspberry Pi 4 and are getting bad speeds transferring data to/from USB3.0 SSDs, read this
Post by harrytv » 25 Jan 2020 13:42

I had a lot of issues with stuttering video playback using Libreelec 9.2.0. Media files (mkv, h264) were located on a very fast 1TB SSD connected via a USB3.0 adapter. I finally hit this post and it helped tremendously. Here is what I did for completeness.

* I logged in as user `root` using Putty SSH from a Windows machine, using default password.
* Disconnected USB drive and ran (since this is libreelec no need for `sudo`)

dmesh -c
* Reconnected the USB drive and ran:

[ 342.605668] usb 2-1: new SuperSpeed Gen 1 USB device number 3 using xhci_hcd
[ 342.626900] usb 2-1: New USB device found, idVendor=152d, idProduct=1561, bcd Device= 2.04
[ 342.626921] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 342.626938] usb 2-1: Product: SABRENT
[ 342.626953] usb 2-1: Manufacturer: SABRENT
[ 342.626968] usb 2-1: SerialNumber: DB9876543214E
[ 342.639515] scsi host0: uas
[ 342.640972] scsi 0:0:0:0: Direct-Access SABRENT 0204 PQ : 0 ANSI: 6
[ 345.935277] sd 0:0:0:0: [sda] 1953525168 512-byte logical blocks: (1.00 TB/93 2 GiB)
[ 345.935286] sd 0:0:0:0: [sda] 4096-byte physical blocks
[ 345.935531] sd 0:0:0:0: [sda] Write Protect is off
[ 345.935538] sd 0:0:0:0: [sda] Mode Sense: 53 00 00 08
[ 345.936048] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, does n’t support DPO or FUA
[ 345.936856] sd 0:0:0:0: [sda] Optimal transfer size 33553920 bytes not a mult iple of physical block size (4096 bytes)
[ 345.940078] sda: sda1
* As can be seen this is a USB3.0 SATA 3 adapter from Sabrent. Running in `uas` mode.
* To verify how poorly this was running I tested the speed using:

hdparm -t /dev/sda1
Timing buffered disk reads: 516 MB in 33.25 seconds = 15.52 MB/sec
* Which of course is extremely slow. I then checked the log again using `dmesg`:

[ 1247.365069] usb 2-1: reset SuperSpeed Gen 1 USB device number 3 using xhci_hcd
[ 1247.387663] scsi host0: uas_eh_device_reset_handler success
[ 1279.648929] sd 0:0:0:0: [sda] tag#3 uas_eh_abort_handler 0 uas-tag 4 inflight: CMD IN
[ 1279.648937] sd 0:0:0:0: [sda] tag#3 CDB: opcode=0x28 28 00 03 fa 64 50 00 01 00 00
[ 1279.649085] sd 0:0:0:0: [sda] tag#1 uas_eh_abort_handler 0 uas-tag 2 inflight: CMD IN
[ 1279.649091] sd 0:0:0:0: [sda] tag#1 CDB: opcode=0x28 28 00 00 00 10 00 00 04 00 00
[ 1279.649553] sd 0:0:0:0: [sda] tag#0 uas_eh_abort_handler 0 uas-tag 1 inflight: CMD IN
[ 1279.649559] sd 0:0:0:0: [sda] tag#0 CDB: opcode=0x28 28 00 00 00 0c 00 00 04 00 00
[ 1286.049165] sd 0:0:0:0: tag#4 uas_eh_abort_handler 0 uas-tag 5 inflight: CMD
[ 1286.049173] sd 0:0:0:0: tag#4 CDB: opcode=0x0 00 00 00 00 00 00
[ 1286.065838] scsi host0: uas_eh_device_reset_handler start
* Same issues as discussed in this post.
* Fixing this on libreelec was a bit different though, hence why I wrote this post.
* Navigate to root after logging in, ensure you can edit the `/flash/cmdline.txt` by remounting, then edit file.

cd ..
mount -o remount,rw /flash
nano /flash/cmdline.txt
* I simply adding the below to the beginning of the file and saved:

* And then rebooted:

* After rebooting I checked that the quirk was applied:

dmesg | grep usb-storage
[ 0.673330] usbcore: registered new interface driver usb-storage
[ 1.024033] usb 2-1: UAS is blacklisted for this device, using usb-storage in stead
[ 1.024147] usb 2-1: UAS is blacklisted for this device, using usb-storage in stead
[ 1.024163] usb-storage 2-1:1.0: USB Mass Storage device detected
[ 1.024576] usb-storage 2-1:1.0: Quirks match for vid 152d pid 1561: 800000
[ 1.024726] scsi host0: usb-storage 2-1:1.0
* Which it was, and I then retested the performance:

LibreELEC:~ # hdparm -t /dev/sda1

Timing buffered disk reads: 930 MB in 3.00 seconds = 309.71 MB/sec
* A 20x improvement and it runs so much better. So thank you for this sticky. 🙂

Mouse double click speed

Trouble like me with Mouse double click speed?

Google “lxde double click speed”, there is a hidden file named “.gtkrc-2.0” in your home directory. So if it does not exist, create it. If it does exit, read it before you proceed — it may advise you to use “.gtkrc-2.0.mine” instead.
Type these commands from the prompt, or inside LXTerminal.


rpi_hal from https://github.com/rudiratlos/rpi-hal is an incredible rich and uptodate unit for Freepascal to use the I/O of the Raspberry.

From Freepascal programs all works as expected when run as root. Otherwise accessing /dev/mem is causing real problems.

The unit can be used from Lazarus also (avoid the test procedures with writeln’ 😉 ) but also require root access and setting cthreads in the program heading.

For X apps  running as root is not possible with just sudo.
Seems I found a solution here: https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root

I applied method 2:

sudo nano /etc/profile

and added this line as last line

export XAUTHORITY=/home/pi/.Xauthority

Now i can do

$ sudo ./testinit (my simple test program with only the init line of rpi_hal)

and this worked without error, init succeeded.

If you want debugging the app in Lazarus, start Lazarus as root (and ignore all the warnings)

xhost +localhost
sudo /usr/bin/startlazarus

Original text from https://wiki.archlinux.org/index.php/Running_GUI_applications_as_root

Method 2: Globally in /etc/profile
Add the following line to /etc/profile:

export XAUTHORITY=/home/username/.Xauthority
This will permanently allow root to connect to a non-root user’s X server.

Or, merely specify a particular app:

XAUTHORITY=/home/username/.Xauthority appname
where appname is the name of the particular app. (e.g. kwrite

Arduino on Raspberry

Install Arduino on Buster

  1. Arduino 1.8.12 (or higher) from arduino.cc – Software – Arduino ARM 32 bits
  2. Download to e.g. Downloads
  3. cd /Downloads
  4. tar -x -f arduino-1.8.5-linuxarm.tar.xz
  5. cd arduino-1.8.12
  6. sudo ./install.sh
  7. and Arduino appears in Home – Programming desktop

Autostart program like minicom at console at boot

Install minicom

sudo apt-get install minicom

setup your system to auto ;login into a commandline session
[use sudo raspi-config]

then at the end of .bashrc put in

if [ $(tty) == /dev/tty1 ]; then
   minicom -s  ##change this to be the thing you want or even a script [full path to]

then reboot your rpi

RPI4 as USB gadget

Pi4 USB-C Gadget