Rotate scenic app on RPI 5" Touch Display 2

Hi everyone, ive been trying to get my scenic app working on a rpi4 w/ a rpi 5” touch display 2 however I cant get it working how I would like. The issue comes from how the touch display 2 by default is a portrait screen, so if I run the app as it is it displays in a rotation I do not want, I want to be able to use the app and screen in a landscape orientation. I don’t necessarily need to flip everything on the screen its fine if just the app is rotated. From what I understand I need the following in my config:

  opts: [
    rotate: (3 * :math.pi()) / 2,
    pin: {0, 0},
    translate: {0, 0}
  ],

However that doesn’t work the app just never appears on the display.
When I try and do:

  opts: [
    rotate: (3 * :math.pi()) / 2,
    pin: {0, 0},
    translate: {500, 500}
  ],

I can see the app in the correct orientation and it does look to be about 500 down and 500 to the right (considering the 1280 x 720 resolution) so to me it looks like I should just set the translation to 0, 0. But like I said above the app just disappears. I am using scenic & scenic_driver_local v0.12.0-rc.0 (if thats important) because I have to use cairo-fb as drm doesnt work.

I worked through this same issue recently. My solution is a mix of things but all in the config.txt

dtoverlay=rpi-ft5406,touchscreen-swapped-x-y=1,touchscreen-inverted-x=1
display_rotate=1

These are specific for the Waveshare display I am using with the rpi3 so the dtoverlay may be different. You will need to do all the rotating as one is for the display and one is for the touchscreen which is rotated independently.

Hope that helps!

Ive tried this before however it didn’t work. I believe the rpi4 uses something else that prevents me from rotating it with display_rotate=1. There’s another way listed on the rpi docs but under the method they mention “any applications that write directly to DRM (such as cvlc or the libcamera apps) won’t be rotated, and will instead need to use their own rotation options (if available).“ Which makes me believe I need to do this through scenic.

Managed to get some progress! I was able to figure out the issue with rotating using opts in the config and now its properly rotated. However now it seems like the touch isn’t working properly. The first time the app renders in it gets covered by the text of the logs partially (if there’s a fix for that too please let me know) and when I click on a button it seems to register the click as the button click effect ive added in gets displayed, however any subsequent click and nothing happens, as if the app just completely stopped working. Any ideas?

Can you show or link to the scene? That can happen when an input is captured but not released if you are manually doing such.

This is the entire scene. For the buttons im just using Scenic components with a theme I made, I guess I remember doing the click effect a different way but my memory is a little foggy with me focusing on it just getting working properly.

defmodule Procyon.Scene.Home do
  use Scenic.Scene
  require Logger

  alias Scenic.Graph
  alias Procyon.Theme

  import Scenic.Primitives

  @sw Theme.sw()
  @sh Theme.sh()
  @margin Theme.margin()
  @margin_top Theme.margin_top()
  @br Theme.br()
  @bw Theme.bw()
  @bh Theme.bh()
  @theme Theme.theme()

  @graph Graph.build(background: {6, 6, 6})
      |> Scenic.Components.button(
        "Scan", id: :scan, width: @bw, height: @bh, radius: @br,
        styles: [font: :geist_mono, font_size: 72], translate: {@margin, @margin_top}, theme: @theme
      )
      |> Scenic.Components.button(
        "Gauges", id: :gauges, width: @bw, height: @bh, radius: @br,
        styles: [font: :geist_mono, font_size: 72], translate: {@margin + @bw + @margin, @margin_top}, theme: @theme
      )
      |> Scenic.Components.button(
        "Lights", id: :lights, width: @bw, height: @bh, radius: @br,
        styles: [font: :geist_mono, font_size: 72], translate: {div(@sw - @bw, 2), @margin_top + @bh + @margin}, theme: @theme
      )
      |> text("VEHICLE DASHBOARD", fill: :white, text_align: :left, text_base: :middle, font_size: 32, font: :geist_mono, translate: {@margin, div(@margin_top, 2)})
      |> line({{0, 0}, {0, @sh}}, stroke: {2, :red})
      |> line({{@sw, 0}, {@sw, @sh}}, stroke: {2, :red})
      |> line({{0, 0}, {@sw, 0}}, stroke: {2, :red})
      |> line({{0, @sh}, {@sw, @sh}}, stroke: {2, :red})

  def init(scene, _param, _opts) do
    scene = push_graph(scene, @graph)

    {:ok, scene}
  end

  def handle_event({:click, scene_id}, _from, scene) do
    scene_mod = case scene_id do
      :scan -> Procyon.Scene.Scan
      :gauges -> Procyon.Scene.Gauges
      :lights -> Procyon.Scene.Lights
    end

    Scenic.ViewPort.set_root(scene.viewport, scene_mod)
    {:noreply, scene}
  end
end

When you click, does it change scenes to the new root? Scenic.ViewPort.set_root/2 will stop the current scene and it’s children.

When testing locally, on my computer with scenic it works as intended and switches scenes. However on the rpi with the touch display when I tap on a button the click effect gets rendered, but no scene switching happens it just stays on the same scene.

Anything in the logs when that happens?

I think with Scenic’s use of OTP a crash could make a button seem to do nothing?

Hmm that does make sense. Possibly the button is causing a crash since the click effect is happening just nothing after? Im not seeing anything in the logs although maybe im checking them incorrectly. Nothing pops up on the screen and if im sshed into the rpi aswell at the same time nothing shows up there either.

Try RingLogger.next / RingLogger.viewer on SSH after the problem. Or RingLogger.attach to see logs streaming.

Ahhh yup that revealed the issue! I had blindly updated the scenic stuff to the 0.12 rc and didnt realize I had to change some of my code. Unfortunately I am fighting a battle with nixos and getting scenic_driver_local to compile for the rpi4 might take a while. I got it to compile scenic locally and it showed the issue locally but now I just gotta get it to work for the rpi4

1 Like