pimoroni / hyperpixel4

Driver for the Pimoroni HyperPixel 4.0" Touchscreen Display
https://shop.pimoroni.com/products/hyperpixel-4?variant=12569485443155
329 stars 46 forks source link

PSA: HyperPixel 4 (Square & Rectangular) on Raspberry Pi OS 64bit 2022-04-04 #177

Open Gadgetoid opened 2 years ago

Gadgetoid commented 2 years ago

:information_source: See this comment for rotation in Raspberry Pi Desktop screen configuration - https://github.com/pimoroni/hyperpixel4/issues/177#issuecomment-1786957639

:warning: PSA: Make sure you disable i2c, SPI and any other interfaces since these will cause a conflict in device-tree with HyperPixel :warning:

:warning: A fresh image is recommended, but otherwise make sure you also disable the hyperpixel4-init system service! :warning:

Pi 3B and Pi 4 users running the latest and greatest Raspberry Pi OS should forego our installer and use the instructions below.

:information_source: If you're tied to an older OS and you want to install the legacy drivers, use: curl -sSL get.pimoroni.com/hyperpixel4-legacy | bash

This new OS can currently be found in Raspberry Pi Imager under "Raspberry Pi OS (Other)"

image

Once installed you need only one line in /boot/config.txt:

You can rotate these in config.txt by adding the rotate= parameter, like so:

dtoverlay=vc4-kms-dpi-hyperpixel4sq,rotate=90

This supports rotation in console, too, for all you CyberDeck builders!

HyperPixel 4 Rectangular Rotations

Ensure rotation is set to "Normal" in "Display Configuration"

And that the dtoverlay is in /boot/config.txt:

dtoverlay=vc4-kms-dpi-hyperpixel4

Finally use one of the following dtparam lines immediately underneath to set the parameters:

HyperPixel 4 Square Rotations

HyperPixel 4 Square does not correctly swap or invert touch input, so you may want to use the Xorg config method below.

Ensure rotation is set to "Normal" in "Display Configuration"

And that the dtoverlay is in /boot/config.txt:

dtoverlay=vc4-kms-dpi-hyperpixel4sq

Finally use one of the following dtparam lines immediately underneath to set the parameters:

:warning: The touchscreen-swapped-x-y parameter does not seem to work with Square. You may need to use the script below for Raspberry Pi OS with Desktop.

On the fly rotation

Rotating the display via "Screen Configuration" ("arandr") results in inverted touch input and other weirdness- use the dtoverlay params.

If you want to rotate on the fly you can use the below bash script to rotate either display and persist settings into Xorg configuration files.

:warning: Note: You must remove the rotate= argument from /boot/config.txt for these to make sense.

You can remove the rotation config by deleting the /usr/share/X11/xorg.conf.d/88-hyperpixel4-touch.conf and /usr/share/X11/xorg.conf.d/88-dsi-1-rotate.conf files.

#!/bin/bash

UTILITY="hyperpixel4-rotate (Rectangular)"
XORG_TOUCH_CONF_FILE="/usr/share/X11/xorg.conf.d/88-hyperpixel4-touch.conf"
XORG_CONF_FILE="/usr/share/X11/xorg.conf.d/88-dsi-1-rotate.conf"

OVERLAY_S="vc4-kms-dpi-hyperpixel4sq"
OVERLAY_R="vc4-kms-dpi-hyperpixel4"

function success() {
    echo -e "$(tput setaf 2)$1$(tput sgr0)"
}

function inform() {
    echo -e "$(tput setaf 6)$1$(tput sgr0)"
}

function warning() {
    echo -e "$(tput setaf 1)$1$(tput sgr0)"
}

function set_xorg_conf {
    if [ "$DISPLAY" == "" ]; then
        inform "No DISPLAY variable set, trying :0.0"
        export DISPLAY=:0.0
    fi

    inform "Rotating display $1";
    xrandr --output DPI-1 --rotate $1

    MATRIX="$2 $3 $4 $5 $6 $7 $8 $9 ${10}"

    inform "Setting libinput Calibration Matrix: 1 0 0 0 1 0";
    xinput set-prop "pointer:$DEVICE" "libinput Calibration Matrix" 1 0 0 0 1 0 0 0 1

    inform "Setting Coordinate Transformation Matrix: $MATRIX";
    xinput set-prop "pointer:$DEVICE" "Coordinate Transformation Matrix" $MATRIX

    inform "Saving xorg touch config to $XORG_TOUCH_CONF_FILE";
    sudo tee $XORG_TOUCH_CONF_FILE > /dev/null <<EOF
# Auto generated by $UTILITY, edit with care!

Section "InputClass"
    Identifier "HyperPixel4 $DEVICE"
    MatchProduct "$DEVICE"
    Option "CalibrationMatrix" "1 0 0 0 1 0 0 0 1"
    Option "TransformationMatrix" "$MATRIX"
EndSection
EOF

    inform "Saving xorg rotate config to $XORG_CONF_FILE";
    sudo tee $XORG_CONF_FILE > /dev/null <<EOF
# Auto generated by $UTILITY, edit with care!

Section "Monitor"
    Identifier "DPI-1"
    Option "Rotate" "$1"
EndSection
EOF
}

printf "HyperPixel 4: Display & Touch Rotation\n"
printf "This utility requires the Raspberry Pi OS desktop or an *Xorg-based* alternative.\n\n"

ORIENTATION=$1

grep -e "^dtoverlay=$OVERLAY_S.*" /boot/config.txt > /dev/null
if [ $? -ne 0 ]; then
    grep -e "^dtoverlay=$OVERLAY_R.*" /boot/config.txt > /dev/null
    if [ $? -ne 0 ]; then
        warning "Rotation requires hardware support on the Pi 4 or Pi 400"
        warning "Ensure your HyperPixel4 is enabled in /boot/config.txt"
    printf "\nSquare:      dtoverlay=$OVERLAY_S\n"
    printf "Rectangular: dtoverlay=$OVERLAY_R\n\n"
        exit 1
    else
        inform "Detected HyperPixel 4 Rectangular (found \"$OVERLAY_R\" in config.txt)"
        DEVICE="Goodix Capacitive TouchScreen"
    fi
else
    inform "Detected HyperPixel 4 Square (found \"$OVERLAY_S\" in config.txt)"
    DEVICE="EP0110M09"
fi

case $ORIENTATION in
    "right")
        set_xorg_conf $ORIENTATION 0 1 0 -1 0 1 0 0 1
        ;;
    "left")
        set_xorg_conf $ORIENTATION 0 -1 1 1 0 0 0 0 1
        ;;
    "inverted")
        set_xorg_conf $ORIENTATION -1 0 1 0 -1 1 0 0 1
        ;;
    "normal")
        set_xorg_conf $ORIENTATION 1 0 0 0 1 0 0 0 1
        ;;
    *)
        printf "Unsupported orientation: $ORIENTATION\n\n";
        printf "Usage:\n"
        printf "    $0 <orientation>\n\n"
        printf "Where orientation is one of: left, right, normal, inverted.\n"
        exit 1
esac
sesquipedality commented 2 years ago

I am not using X so the screen rotation solutions provided here have not worked for me. However, I have been able to get touchscreen rotation on the Pi 4 with a 2021 Hyperpixel 4.0 Square to work as follows.

In /boot/config.txt

dtoverlay=vc4-kms-v3d
dtoverlay=vc4-kms-dpi-hyperpixel4sq,rotate=180,touchscreen-swapped-x-y

In /etc/udev/rules.d/98-touchscreen.rules

ATTRS{name}=="generic ft5x06 (00)", ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 -1 1"
ATTRS{name}=="EP0110M09", ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 -1 1"

This is a bit of a black box to me, as I am not a udev or libinput expert, but as I understand it if the matrix is "a b 1 c d 1" then the touchscreen co-ordinates are multiplied by the matrix

(a b)
(c d)

to transform the co-ordinates. Hope this helps someone.

Of course it would be much neater if the rotation parameters worked in /boot/config.txt so hopefully that will get fixed soon.

jeffcolabs1 commented 1 year ago

Pi Zero 2 running a freshly installed/updated Bullseye 64bit - The new instructions aren't working for me fully for a new rectangular screen. It installs and displays, and the touchscreen works no problem in portrait and 180 rotated portrait - but 90 and 270 landscape rotations don't work. The boot screen(s) are correct, but the OS GUI remains in portrait. @Gadgetoid FYI as I thought I saw somewhere that you wanted some feedback on a Zero 2.

I ran the legacy installer for a Pi 4 rectangular and the landscape display worked after some tweaks (well technically I ran it for a Pi 3 first, then when that didn't work I ran for a Pi 4). I had to change in /boot/config.txt:

  • Comment out existing line dtoverlay=vc4-kms-v3d (I believe this disables hardware acceleration or something?)
  • Add display_lcd_rotate=1 to rotate the display
  • Add dtparam=touchscreen-swapped-x-y,touchscreen-inverted-y to rotate the touch input to match the display

This gives you landscape with header at the bottom, will need other combinations for other orientations. I needed both new settings - adding rotate=270, to the beginning of the dtparam didn't work by itself.

Hopefully this helps a few people struggling with this

EDIT: when I booted the pi again the next day the screen was blank - journalctl -u hyperpixel4-init.service showed an error of ImportError: No module named RPi.GPIO, editing sudo nano /usr/bin/hyperpixel4-init to have #!/usr/bin/env python3 instead of #!/usr/bin/env python fixed it. Just saying in case it helps someone

@ChrisZ32 Thank you for this. This worked perfectly for me also. New HyperPixel4, Zero 2W. Landscape mode works perfectly in either rotation. There is obviously an issue with the vc4-kms-v3d drivers and rotation. Reverting back to the old drivers and with your settings worked perfectly.

r-colvin commented 1 year ago

@jeffcolabs1 / @ChrisZ32 - adding my vote on this answer; brand new Pi Zero 2 WH with latest Raspberry OS (full - 32 bit - 2023-02-04)

i had the same symptoms as you, with the "new" default instructions, the screen works (and its gorgeous!) the startup and shutdown screens (white square with a raspberry pi logo) are in the right orientation, however the OS (desktop etc) are in portrait mode and no amount of messing about will fix it. I tried everything in this thread and the following (from your excellent work!) is what fixed it.

Hardware: Raspberry Pi Zero 2 WH, purchased a week ago OS: Raspberry OS 32-Bit Full from 2023-02-04 (latest as of writing) imaged with Raspberry Pi Imager HyperPixel 4 Rectangular, puchased around 6 months ago

My Setup has the GPIO Header along the top-edge; SD card on the left edge; USB ports on the bottom edge, Camera connector on the right edge

curl -sSL get.pimoroni.com/hyperpixel4-legacy | bash : Select "0" (Raspberry Pi 4; Rectangular)

before rebooting, edit /boot/config.txt : comment out the line that says dtoverlay=vc4-kms-v3d : add the following to the bottom of /boot/config.txt display_lcd_rotate=3 dtparam=touchscreen-inverted-x dtparam=touchscreen-swapped-x-y

reboot... happy days!

UPDATE: this appears to break VNC - VNC was working before, however after the above procedure, VNC logs show X connection to :0 broken (explicit kill or server shutdown). when trying to connect remotely - has anyone else seen this?

Ruhel786 commented 1 year ago

I have had my Pi 4 4GB and my 2023 Rectangle working with no issues until I had an issue with PINN and wiped the whole card and started again. Now no matter what I do the touchscreen will not rotate to match the screen orientation. I'm sorry I can't seem to find the OP who posted this so I can't credit it, but the below method had a 100% success rate for me until today and I don't know why it won't work anymore on my installs.

cd /boot

sudo nano config.txt

Comment the line below: #dtoverlay=vc4-fkms-v3d add the line below display_lcd_rotate=3

Save and Exit the Config file.

Save and reboot and the screen will now be orientated with the USB C port at the bottom.

The TOUCH function will still be incorrect, but to correct this: cd /usr/share/X11/xorg.conf.d

sudo nano 40-libinput.conf

Edit the section for the touchscreen - it is normally the second last section - by adding this line:

Section "InputClass"
        Identifier "libinput touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
>>>>>  Option "TransformationMatrix" "0 -1 1 1 0 0 0 0 1"  <<<<<<<
EndSection

This was working with no issues and now on my Pi OS 64bit it just rotates the display only, not the touchscreen. Any advice would be appreciated. Ruhel™

alucryd commented 1 year ago

Doesn't seem to work on Arch Linux ARM (armv7, pi zero 2 w) with the new overlay. It was working fine with the old hyperpixel 4 overlay until my last system update, which led me to this page. Touchscreen is working but I have no picture, I am able to interact with klipperscreen but I don't see what I'm clicking on :/

Here's my full config.txt:

# See /boot/overlays/README for all available options

dtoverlay=vc4-kms-dpi-hyperpixel4
#dtoverlay=hyperpixel4
dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y
initramfs initramfs-linux.img followkernel

# Automatically load overlays for detected DSI displays
#display_auto_detect=1

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Automatically load overlays for detected cameras
#camera_auto_detect=1

# Uncomment to enable bluetooth
#dtparam=krnbt=on

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[pi4]
# Run as fast as firmware / board allows
arm_boost=1

gpu_mem=96
start_file=start_x.elf
fixup_file=fixup_x.dat
disable_camera_led=1

#overscan_left=0
#overscan_right=0
#overscan_top=0
#overscan_bottom=0
#enable_dpi_lcd=1
#display_default_lcd=1
#display_lcd_rotate=1
#dpi_group=2
#dpi_mode=87
#dpi_output_format=0x7f216
#dpi_timings=480 0 10 16 59 800 0 15 113 15 0 0 0 60 0 32000000 6

Running the hyperpixel4-init service doesn't help either, although I understand it's no longer needed.

djammy commented 1 year ago

Hi all!

Newbie here. Apologies if my question is not meant for this thread.

I just got my raspberry pi 4 connected with the Hyperpixel 4.0 Square and I followed the instructions as above and the display is working fine. However, I would like to control the individual pixels on the Hyperpixel 4.0 display: for instance I would like to display the entire screen being green only or red, or white etc... Is there a way to do this using Python? If so, which library should I use?

Thanks.

Ruhel786 commented 1 year ago

Can I ask what it's for? Are you testing the pixels on the screen? If so just install the desktop OS and use a full screen image of wash colour.

sesquipedality commented 1 year ago

Depends quite what you're trying to do.

djammy commented 1 year ago

So I would like to be able to control the entire screen pixels to display just one colour (255,0,0)/(0,255,0)/(0,0,255) and any combination in between. It is for a photonics experiment. Not for testing the pixels.

I was thinking if I should just use Pillow and display a coloured image.

sesquipedality commented 1 year ago

I would use pygame or pyqt for that. Probably pygame as the learning curve is a little less steep. With a little research you could probably go a little more lightweight and just write the relevant number of raw pixels direct to /dev/fb0, but it's not a very expandable approach if you want to do more later.

djammy commented 1 year ago

Brilliant! Thank you @sesquipedality

Gordon999 commented 1 year ago

with a fresh install of raspiOS 64bit after much trying using the instructions I finally got the hyperpixel4 to work on a Pi3B and rotated with. add dtoverlay=vc4-kms-dpi-hyperpixel4 to /boot/config.txt, leave dtoverlay=vc4-kms-v3d there then on the Pi 3B >> Preferences >> Screen Configuration >> DPI >> rotate option to suit, reboot

nmatsuda commented 1 year ago

Should this work with the 2020-and-earlier version of the hyperpixel4sq on a Pi3b+? I tried both the 64bit and 32bit builds of Bullseye, released 2022-04-04. I get what appears to be vertical stripes in both cases. It doesn't seem to matter if hdmi is connected or not. If hdmi is connected, then I get a very low resolution desktop on hdmi. Both installs are fresh, plain installs, and the only change I made was to add "dtoverlay=vc4-kms-dpi-hyperpixel4sq" to the end of /boot/config.txt

Youch- that's a good question, to which the answer is: no. They require - iirc - very different configurations and bringup. That's something I'm going to have to look into. I had forgotten there were two flavours of Square 😬

Any update on this?

npimig commented 1 year ago

So oddly some how I arrived at a somewhat working display that could not rotate to landscape orientation (header on bottom). I used the latest of Bullseye 5/4/2023 image, at first no luck with the dtoverlay=vc4-kms-dpi-hyperpixel4 then I launched raspi-config and enabled GL drivers after reboot a screen turned on. Then trial error I then found to get the touch oriented correctly i had to insert the dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y stuff between the two dtoverlays (2nd one created after raspi-config dtoverlay=vc4-kms-v3d) in the /boot/config.txt as well as relying on the command DISPLAY=:0 xrandr --output DPI-1 --rotate right once desktop was finally loaded manually at first to orient the display and touchscreen in landscape mode.

To polish I asked ChatGPT (shame), who said to put that command in ~/.xsessionsrc that needed to be created but loads after the primary boot process/around the initial display rendering time and (viola it works). Takes a while to boot and appears to lock out touch inputs until the "ole-gd-its-broke" period of it and then all is good, presto.

I'm running on the Pi Zero 2 W with OpenGL 2 drivers enabled with the Hyperpixel 4" (Rectangular Display) with the Raspbian - Bullseye (Release 2023-05-03).

Prior i was running Buster from 2021 with issues in the legacy driver for this display not allowing me to enable OpenGL features.

Just thought I'd share...

brucediesel commented 1 year ago

Hi, is there a timeline as to when the Hyperpixel will be able to work with other interfaces enabled? I have a project which uses a camera through the CSI interface, and a lidar on i2c but even just the camera and the Hyperpixel do not work together. I am moving over to new libcamera, so I don't want to go back to older OS.

rudiprinsloo commented 1 year ago

I have been using my HyperPixel Square without issue with the legacy drivers, old Raspbian OS on a Pi Zero W.

Then after upgrading to the latest Raspberry Pi OS (Bullseye) I was initially happy to find that I didnt have to install any drivers, and just needed to add the following line to my /boot/config.txt file:

dtoverlay=vc4-kms-dpi-hyperpixel4sq

After rebooting the screen would just show a bunch of lines running across the display and these would jump around when I touch it.

20230812_173320~2

I2C and SPI are disabled.

I have read all the comments here but I have not been able to resolve the issue.

Any help would be much appreciated.

omarandlorraine commented 1 year ago

Hi, is there a timeline as to when the Hyperpixel will be able to work with other interfaces enabled? I have a project which uses a camera through the CSI interface, and a lidar on i2c but even just the camera and the Hyperpixel do not work together. I am moving over to new libcamera, so I don't want to go back to older OS.

My understanding is it's not going to happen; the hyperpixel4 actually takes over the spi/i2c hardware and corresponding GPIO pins, which is the reason they must be disabled.

Gadgetoid commented 1 year ago

@rudiprinsloo there are two versions of HyperPixel Square. One which luckily requires no initialization and which Just Works with the new blessed way of doing things, and the other which needs init and will never work with the new way of doing things. It looks like you must have the latter, which IIRC is the earlier pre 2021 version. They also use different display timings, which is why you're seeing a garbled mess.

@brucediesel as @omarandlorraine suggests- never. The DPI display requires all the pins. That said, the Camera interface should work, but that's presumably an OS issue and not something we can fix or change.

Bodges

I know nobody wants to hear this- least of all me- but some older hardware can be fixed with bodges. I managed to hook a regular Pico up to my HyperPixel 4 Square (post 2021) in order to shut down the LCD when there are no vsync/hsync signals, solving the display corruption issue. To do this in the field would need some fine soldering skills, a micro of some sort (with at least 3 IO pins) and bodge wires for power, ground, vsync, hsync and LCD shutdown. I'm thinking of putting together a guide for anyone who wants to try this. Normally you'd just tie shutdown to a pin on the Pi but, uh, DPI makes sure there aren't any left.

Similarly, while pre 2021 HyperPixel 4 Square is currently not supported by Raspberry Pi OS, it might be possible to at least get a driver running for the DPI signals and then figure out the rest from there, possibly with a similar bodge to fire over the display init before the OS can boot and start touch comms.

I've long been a proponent for putting a micro on our display boards to handle some of this stuff, but revising our designs doesn't really help anyone with an old board. The long and short of it here, though, is that the software has moved on and made changes beyond what we could have expected, so supporting older (yes I know 2021 isn't that long ago) boards is getting more and more difficult.

Bookworm

As of Bookworm OS on a Pi 4/Pi 400 - which supports post 2021 HyperPixel 4 Square and HyperPixel 4 Rectangular -a device tree conflict between interfaces will result in the graphics stack crashing and booting to a black screen- even on HDMI. Some good news, however, is that the display config utility in Raspberry Pi OS will finally support associating a touchscreen with a display so that rotation - at least if you're running a full RPi OS - is less of a chore.

Diudid commented 1 year ago

Hello i did a litlte update to the rotate script to allow it to rotate the screen clockwise, no need of keyboard

#!/bin/bash

UTILITY="hyperpixel4-rotate (Rectangular)"
XORG_TOUCH_CONF_FILE="/usr/share/X11/xorg.conf.d/88-hyperpixel4-touch.conf"
XORG_CONF_FILE="/usr/share/X11/xorg.conf.d/88-dsi-1-rotate.conf"

OVERLAY_S="vc4-kms-dpi-hyperpixel4sq"
OVERLAY_R="vc4-kms-dpi-hyperpixel4"

function success() {
    echo -e "$(tput setaf 2)$1$(tput sgr0)"
}

function inform() {
    echo -e "$(tput setaf 6)$1$(tput sgr0)"
}

function warning() {
    echo -e "$(tput setaf 1)$1$(tput sgr0)"
}

function set_xorg_conf {
    if [ "$DISPLAY" == "" ]; then
        inform "No DISPLAY variable set, trying :0.0"
        export DISPLAY=:0.0
    fi

    inform "Rotating display $1";
    xrandr --output DPI-1 --rotate $1

    MATRIX="$2 $3 $4 $5 $6 $7 $8 $9 ${10}"

    inform "Setting libinput Calibration Matrix: 1 0 0 0 1 0";
    xinput set-prop "pointer:$DEVICE" "libinput Calibration Matrix" 1 0 0 0 1 0 0 0 1

    inform "Setting Coordinate Transformation Matrix: $MATRIX";
    xinput set-prop "pointer:$DEVICE" "Coordinate Transformation Matrix" $MATRIX

    inform "Saving xorg touch config to $XORG_TOUCH_CONF_FILE";
    sudo tee $XORG_TOUCH_CONF_FILE > /dev/null <<EOF
# Auto generated by $UTILITY, edit with care!

Section "InputClass"
    Identifier "HyperPixel4 $DEVICE"
    MatchProduct "$DEVICE"
    Option "CalibrationMatrix" "1 0 0 0 1 0 0 0 1"
    Option "TransformationMatrix" "$MATRIX"
EndSection
EOF

    inform "Saving xorg rotate config to $XORG_CONF_FILE";
    sudo tee $XORG_CONF_FILE > /dev/null <<EOF
# Auto generated by $UTILITY, edit with care!

Section "Monitor"
    Identifier "DPI-1"
    Option "Rotate" "$1"
EndSection
EOF
}

printf "HyperPixel 4: Display & Touch Rotation\n"
printf "This utility requires the Raspberry Pi OS desktop or an *Xorg-based* alternative.\n\n"

FILE=/tmp/HPStep
if [[ -f "$FILE" ]]; then
    STEP=$(cat $FILE)
    (( STEP+=1 ))
    if [[ $STEP == 5 ]]; then
        STEP=1
    fi
else
    STEP=1
fi

grep -e "^dtoverlay=$OVERLAY_S.*" /boot/config.txt > /dev/null
if [ $? -ne 0 ]; then
    grep -e "^dtoverlay=$OVERLAY_R.*" /boot/config.txt > /dev/null
    if [ $? -ne 0 ]; then
        warning "Rotation requires hardware support on the Pi 4 or Pi 400"
        warning "Ensure your HyperPixel4 is enabled in /boot/config.txt"
    printf "\nSquare:      dtoverlay=$OVERLAY_S\n"
    printf "Rectangular: dtoverlay=$OVERLAY_R\n\n"
        exit 1
    else
        inform "Detected HyperPixel 4 Rectangular (found \"$OVERLAY_R\" in config.txt)"
        DEVICE="Goodix Capacitive TouchScreen"
    fi
else
    inform "Detected HyperPixel 4 Square (found \"$OVERLAY_S\" in config.txt)"
    DEVICE="EP0110M09"
fi

case $STEP in
    "1")
        set_xorg_conf "right" 0 1 0 -1 0 1 0 0 1
        ;;
    "2")
        set_xorg_conf "inverted" -1 0 1 0 -1 1 0 0 1
        ;;
    "3")
        set_xorg_conf "left" 0 -1 1 1 0 0 0 0 1
        ;;
    "4")
        set_xorg_conf "normal" 1 0 0 0 1 0 0 0 1
        ;;
    *)
        printf "Unsupported orientation: $ORIENTATION\n\n";
        printf "Usage:\n"
        printf "    $0 <orientation>\n\n"
        printf "Where orientation is one of: left, right, normal, inverted.\n"
        exit 1
esac
echo $STEP > $FILE
MonkeyDavid commented 1 year ago

So is there any way to get a pre-2021 Square touch screen to work with a PI 4? I've tried it with Buster, and get a black screen, but I'm not sure I'm installing the correct drivers (I did the legacy install with "weirdly square," but I'm not sure what that means).

@Gadgetoid

addohm commented 11 months ago

Hi, is there a timeline as to when the Hyperpixel will be able to work with other interfaces enabled? I have a project which uses a camera through the CSI interface, and a lidar on i2c but even just the camera and the Hyperpixel do not work together. I am moving over to new libcamera, so I don't want to go back to older OS.

Never. https://pinout.xyz/pinout/hyperpixel4#

benlk commented 11 months ago

@Gadgetoid Can you tell us more about the Bookworm issues?

As of Bookworm OS on a Pi 4/Pi 400 - which supports post 2021 HyperPixel 4 Square and HyperPixel 4 Rectangular -a device tree conflict between interfaces will result in the graphics stack crashing and booting to a black screen- even on HDMI. Some good news, however, is that the display config utility in Raspberry Pi OS will finally support associating a touchscreen with a display so that rotation - at least if you're running a full RPi OS - is less of a chore.

I've experienced this issue myself, with a CM4 and a Hyperpixel 4 Square Touch and an HDMI monitor.

Do you have a link or any additional information about this device tree conflict? Even a link to the upstream bug tracker would be helpful, so that I can check for the fix and then update my images.

andywarburton commented 11 months ago

I just had a hell of a time getting my Hyperpixel rectangle working rotated on a Pi3b+ running latest 32bit Raspberry Pi OS. The splash screen would show the correct orientation but the actual desktop would be wrong. To fix this you must go into preferences > screen configuration. Then RIGHT CLICK on the box labelled DPI-1 and change the orientation.

IMG_2393

FYI left is "headers on top", right is "headers on bottom"

@Gadgetoid you may want to consider adding this to the top post, because I didn't even know this was possible until scrolling through many many comments on this post where it was casually mentioned as a side-note on another issue :D

bboybattlemage commented 11 months ago

My turn to comment!! Not sure if this will help, but this is what got it working for me, using Raspberry Pi 2 Zero with Hyperpixel 4 (Rectanuglar) and the raspbain installer that included mainsail (as my application was for Klipperscreen interface for a 3d printer). Initially, the screen would flash the console would booting, then blkank screen. The below rectified the issue and made the touch function work.

1) I added the following lines to the /boot/config.txt: dtoverlay=vc4-kms-dpi-hyperpixel4 dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y

2) The screen would show, albeit would remain in portrait mode, and the touch would not be aligned with the display. Scrolling all the way to the bottom of the /boot/config.txt file, in the [alI] section, I changed: _displayrotate=3 (which was originally 0).

Rebooting the system, the screen works, is in landscape and touch controls function perfectly.

Posting here in the event I wind up back here looking for information in the future!

stuartm commented 11 months ago

@rudiprinsloo there are two versions of HyperPixel Square. One which luckily requires no initialisation and which Just Works with the new blessed way of doing things, and the other which needs init and will never work with the new way of doing things. It looks like you must have the latter, which IIRC is the earlier pre 2021 version. They also use different display timings, which is why you're seeing a garbled mess.

Could this information be put into the original post, and maybe the guide on the main site? Having dug out my pre-2021 square hyperpixel from a drawer and doing a fresh install I really thought my display was dead and was about to bin it!!

stuartm commented 11 months ago

@rudiprinsloo there are two versions of HyperPixel Square. One which luckily requires no initialisation and which Just Works with the new blessed way of doing things, and the other which needs init and will never work with the new way of doing things. It looks like you must have the latter, which IIRC is the earlier pre 2021 version. They also use different display timings, which is why you're seeing a garbled mess.

Could this information be put into the original post, and maybe the guide on the main site? Having dug out my pre-2021 square hyperpixel from a drawer and doing a fresh install I really thought my display was dead and was about to bin it!!

Further to the above, it seems the current version of the legacy script doesn't install the init script, despite it apparently being required. The code to install it has been commented out. Since I had tried the new approach before I realised this wasn't going to work, I had accidentally left the new overlay (vc4-kms-dpi-hyperpixel4sq) in the config and it seems this combination along with the old overlay (hyperpixel4) is required to get things working without the init script ... sometimes. After another fresh install I couldn't get this combo working reliably so maybe that was just a fluke. Altogether the current instructions on getting the original* Hyperpixel 4 Square working under bullseye are incomplete if not entirely missing.

Mine was ordered the week the original square launched, so I guess the very first batch, I hope us early adopters aren't going to get completely abandoned. :)

mwestera commented 11 months ago

I went with a variant of @npimig (thanks!), after having gone through various permutations of other suggestions. With Hyperpixel 4.0 on Raspbian Bookworm. I put this at the top of /boot/config.txt to make the touch-screen landscape mode:

dtoverlay=vc4-kms-dpi-hyperpixel4
dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y

The rotate=90 doesn't seem to do anything (though rotate=180 works), but perhaps that will be fixed at some point, and it doesn't hurt, so I'm leaving it in there. (I also left the existing dtoverlay=... lower in the file unchanged, I think that was essential.)

Then to actually rotate the display I put this in (possibly initially empty) ~./xsessionrc:

DISPLAY=:0 xrandr --output DPI-1 --rotate right

Reboot et voila.

mislav commented 10 months ago

Thanks everyone for sharing what worked for you, particularly @npimig @mwestera. For reasons I initially did not understand, these instructions only had some effect for me (the boot screen was rotated, touchscreen coordinates have changed), but after the desktop session had loaded, the orientation would still be unchanged (portrait), no matter what I put in any of these files: ~/.xsessionrc, /usr/share/X11/...

Furthermore, any attempt to use xrandr command would error out with output DPI-1 not found or would produce no output but have no effect either.

Finally, I found myself unable to use the “Preferences” → “Screen configuration” GUI because I didn't have a physical mouse nor keyboard plugged in. (I was editing files via an SSH session.) Using the touchscreen I was able to access the GUI, but after rotating the display, the GUI would ask me to confirm the new display setting. Tapping on the confirmation button did not work because even though the display was visually rotated, the touchscreen coordinates did not rotate accordingly. Ultimately, I also wanted to avoid having to use any GUI in favor of editing configuration files so that I can easily recreate a fresh system from scratch using scripts.


Here is how I solved it:

My environment is a fresh Debian 12 (Bookworm), the default operating system when flashing an SD card using Raspberry Pi Imager. The only changes to the system I've done were apt-get update and apt-get dist-upgrade. My board is a Raspberry Pi 4. My display is HyperPixel 4 rectangular.

Apparently, in October 2023 the Raspberry Pi Debian image was updated to Bookworm and switched from X Window System (X11) to Wayland display server protocol, with Wayfire 0.7.5 being its concrete implementation at the time of writing. This was the reason why ~/.xsessionrc, /usr/share/X11/..., and xrandr did not have any effect anymore: X11 wasn't running at all!

The default configuration file can be discovered using echo $WAYFIRE_CONFIG_FILE from a terminal running as part of the desktop session. The default location for this is ~/.config/wayfire.ini. To rotate the HyperPixel display, I found that appending this to the config file fixed the desktop rotation:

## ~/.config/wayfire.ini
[output:DPI-1]
mode = 480x800@60061
position = 0,0
transform = 270

To rotate the boot screen and touchscreen coordinates, suggestions from earlier in this thread for editing /boot/firmware/config.txt (the new location of /boot/config.txt) are still valid. These lines should be prepended to the file, with the rest of the original file (particularly the original dtoverlay=vc4-kms-v3d line) remaining intact:

## /boot/firmware/config.txt 
dtoverlay=vc4-kms-dpi-hyperpixel4
dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y

Hope this helps!

metanav commented 10 months ago

Thanks, @mislav! I can confirm it works on a Raspberry Pi 5 (Bookworm 64-bit). Now I am running ROS2 RViz on it! https://twitter.com/knaveen/status/1731264586652029414

raygeeknyc commented 9 months ago

Hi Working in console but not in X

I have a Raspberry Pi 400 with a new stock image and am using an AdaFruit Cyberdeck HAT to attach a HyperPixel 4", Rectangular, no touch

I boot to a console which rotates properly but when I enter X using startx the rotate setting seems to be ignored

I've added these to my config.txt

dtoverlay=vc4-kms-dpi-hyperpixel4
dtparam=rotate=270

the script below looks like it may be the solution, but also mentions removing the rotate dtparam which would break my console.

How can I have both the console and X desktop rotated?

Thanks very much

joostit commented 9 months ago

Installer Script for latest versions of Raspberry Pi OS

Using tips and tricks from others in this thread, I created a simple installer script. You can run it from the terminal using:

curl -L "https://raw.githubusercontent.com/DevOats/raspi-tools/main/install-hyperpixel40rect.sh" | bash

Notes:

Many thanks to others who contributed by posting information to this thread!

JohnAMallick commented 9 months ago

I've been struggling to get my new Hyperpixel 4.0 (rectangular) working with my Pi 3B. I've got the latest Raspian bistro (Bullseye 32 bit) loaded and have added "dtoverlay=vc4-kms-dpi-hyperpixel4" to the config.txt file in the boot directory on the sd card as per the instructions above. Pi boots up fine but all I get on the Hyperpixel display is a backlight...no text or desktop or anything. I'm beginning to suspect that the display is defective...

Any ideas out there? I've tried a bunch of things, even loading the legacy drivers but nothing....just a backlight. Suggestions welcome.

rrslssr commented 8 months ago

I also purchased a HyperPixel 4.0 (rectangular) for my new Pi 4 model B 4Gb, running a fresh install of the Raspberry pi os: revision c03115, 6.1.0-rpi7-rpi-v8, onto a new micro SD card. I too am only getting backlight on the display. I have verified that i2c and SPI are disabled. I have not resorted to using the legacy drivers, and really do not want to follow that path. It should work as advertised. I would appreciate any help or direction.

JohnAMallick commented 8 months ago

I also purchased a HyperPixel 4.0 (rectangular) for my new Pi 4 model B 4Gb, running a fresh install of the Raspberry pi os: revision c03115, 6.1.0-rpi7-rpi-v8, onto a new micro SD card. I too am only getting backlight on the display. I have verified that i2c and SPI are disabled. I have not resorted to using the legacy drivers, and really do not want to follow that path. It should work as advertised. I would appreciate any help or direction.

I worked with the vendor that sold me the Hyperpixel 4.0. We went through a bunch of different tests with the Pi, and the vendor finally contacted Pimoroni. They suggested some further tests; when those failed, the vendor issued an RMA and i returned the display. They tested it, found it to be defective, and sent me a new one (which worked out of the box). So I suggest contacting your vendor to see if they will replace a defective display.

JohnAMallick commented 8 months ago

To add to my comment above, the Hyperpixel 4.0 works fine on the Buster version of PiOS using the legacy drivers and install, but i still get a blank display if I use the Bullseye version of PiOS with the new install instructions from Pimoroni. So I'm still sorta stuck in that i can't get it to run on a Pi 3B with the latest version of the OS.

Any ideas?

jchitpin commented 8 months ago

After reading various suggestions above, the following instructions worked for me on a Raspberry Pi Zero 2W with a rectangular HyperPixel 4.0 (with touch) display and a fresh install of Raspbian Bullseye. Note: my display orientation is landscape with the mini HDMI and microUSB ports facing down.

  1. Installed Raspbian Bullseye via rpi-imager (64-bit version released on 2023-12-05 with security updates and desktop environment) on a separate machine.
  2. Added the following lines to the top of /boot/config.txt.
    • dtoverlay=vc4-kms-dpi-hyperpixel4
    • dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-x
  3. Booted into the Pi with the Hyperpixel 4.0 display working (albeit in portrait mode with inverted touchscreen controls).
  4. Ran sudo apt update && sudo apt upgrade (Not sure if this was necessary given the display worked in step 3 but probably a good thing to do.)
  5. Rebooted the Pi.
  6. Ran the Pi Screen Configuration application in the drop down menu and changed the screen orientation.
    • Right clicked on the display and set orientation to left (in my case).

After step 6, the display was correctly oriented in landscape mode with no touchscreen issues. 1000003550

rrslssr commented 7 months ago

I received a replacement HyperPixel, followed the instructions written above by @jchitpin, and it works as advertised. The only change I made to the instructions was to set the rotation in /boot/config.txt by using a slightly different entry: dtparam=rotate=270,touchscreen-swapped-x-y,touchscreen-inverted-x This allowed me to completely skip step 6. I am going to let it run for a day or two, just to be sure...

Mextill commented 7 months ago

Yo guys i just started to get into Hyperpixel and with the guide from @jchitpin it worked to get it running but the layout is not correcet i have like half a CM of Blackscreen beneath the "desktop" its working fine beside that

Edit without a extern Hdmi Display i dont get apicture at all Eidt 2 I dont have the Hyperpxel with Touch I have the one without Touchscreen

beejay41 commented 6 months ago

Not mentioned here, but adding video=DSI-1:480x800 fbcon=rotate:1 to cmdline.txt rotates the console in Bookworm and Buster (probably others).

Tor-Einar commented 5 months ago

I can rotate the screen so it is in landscape, but the touch screen always rotates to a portrait view.

I have a brand new install of OctoPi 1.0.0 (not running 64bit) and Octoprint 1.9.3 (no other drivers)

When I install OctoDash, it rotates

This is what I have in the config file: dtoverlay=vc4-kms-dpi-hyperpixel4,rotate=90 dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y

Any suggestions would be appretiated.

I managed to get it to work. Happy man :)

Used this tutorial Youtube

Used option 3, but since the Octopi with Octoprint is newer and with higher kernel, I just did the regular install, including Octodash, and then I ran the commands needed in the video.

SOLVED

bchschaefer commented 5 months ago

Not mentioned here, but adding video=DSI-1:480x800 fbcon=rotate:1 to cmdline.txt rotates the console in Bookworm and Buster (probably others).

Exactly what I was searching for half a day now...thx @beejay41 for this important (for me, at least) bit of information.

I had to adjust it to video=DSI-1:480x800 fbcon=rotate:3, because my "HyperPixel 4.0 (rectangle, touch)" sits on the "Adafruit CYBERDECK HAT for Raspberry Pi 400" connected to my Pi400. So the GPIO connector is at the top edge in my setup.

steveiliop56 commented 5 months ago

I noticed a small issue with the display. If you look really close you can see something like flickering. Its definitely a software bug as I tested 2 brand new displays and they have the same problem. Any idea on what could be wrong?

coollx commented 5 months ago

I noticed a small issue with the display. If you look really close you can see something like flickering. Its definitely a software bug as I tested 2 brand new displays and they have the same problem. Any idea on what could be wrong?

Yes, I have the same issue with the Hyperpixel 4.0 rectangle installed on a Raspberry Pi Zero 2w (bookworm), have no idea how to solve it yet.

steveiliop56 commented 5 months ago

I thought it was a screen problem and got a replacement but this is bad because no one else reported it. I guess it has to do with the backlight?

coollx commented 5 months ago

Yes, it may be a backlight issue. Did the problem still exist after you got the replacement?

d3k4-k3rb3r0s commented 5 months ago

I noticed a small issue with the display. If you look really close you can see something like flickering. Its definitely a software bug as I tested 2 brand new displays and they have the same problem. Any idea on what could be wrong?

I hve this same isue and its gotten worse over time with all 3 of my hyperpixels.

the absolute hell it took to get a straight answer from pimoroni the first time I dealt with the though.. not even gonna bother complaining directly. just hoping something better comes along.

steveiliop56 commented 5 months ago

Yeah agreed. It's also bad for resellers who don't know about it and will think the screen is broken. I will try sending a custom pwm signal to the pin 19 (controlling the backlight) and see if it fixes the issue.

travmilne commented 4 months ago

I can rotate the screen so it is in landscape, but the touch screen always rotates to a portrait view.

I have a brand new install of OctoPi 1.0.0 (not running 64bit) and Octoprint 1.9.3 (no other drivers)

When I install OctoDash, it rotates

This is what I have in the config file: dtoverlay=vc4-kms-dpi-hyperpixel4,rotate=90 dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y

Any suggestions would be appretiated.

I managed to get it to work. Happy man :)

Used this tutorial

Used option 3, but since the Octopi with Octoprint is newer and with higher kernel, I just did the regular install, including Octodash, and then I ran the commands needed in the video.

SOLVED

The link you tried to share didn't post so we can see the tutorial you're talking about. Can you reply or edit with the link?

Tor-Einar commented 4 months ago

I can rotate the screen so it is in landscape, but the touch screen always rotates to a portrait view. I have a brand new install of OctoPi 1.0.0 (not running 64bit) and Octoprint 1.9.3 (no other drivers) When I install OctoDash, it rotates This is what I have in the config file: dtoverlay=vc4-kms-dpi-hyperpixel4,rotate=90 dtparam=rotate=90,touchscreen-swapped-x-y,touchscreen-inverted-y Any suggestions would be appretiated. I managed to get it to work. Happy man :) Used this tutorial Used option 3, but since the Octopi with Octoprint is newer and with higher kernel, I just did the regular install, including Octodash, and then I ran the commands needed in the video. SOLVED

The link you tried to share didn't post so we can see the tutorial you're talking about. Can you reply or edit with the link?

Have updated the original post with the link

MarvInt64 commented 4 months ago

Can't get it to work. No matter what dtoverlay settings I try, nothing changes. I know how to rotate the console and I know that I can rotate a desktop in X11. But I want to run own programs (e.g. python with cv2) or let's say even chocolate-doom. They are in protrait mode instead of landscape because the damn framebuffer of the screen is 480x800 instead of 800x480 and I cant find a way to change that.