New programmer, display writing is not showing horizontal

Hi

I am completely new to this :).

I have a Pico W with the Display pack. I have put together a code that displays the Balls and Rainbow program. The problem I have is that the display writing is showing vertical but not horizontal along the length. Is anyone able to help me turn the writing around please?

import time
import random

from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P8, PEN_RGB565
from pimoroni import RGBLED

display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB565)

led = RGBLED(6, 7, 8)
BLACK = display.create_pen(0, 0, 0)

display.set_backlight(1.0)

WIDTH, HEIGHT = display.get_bounds()

From CPython Lib/colorsys.py

def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h * 6.0)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))
i = i % 6
if i == 0:
return v, t, p
if i == 1:
return q, v, p
if i == 2:
return p, v, t
if i == 3:
return p, q, v
if i == 4:
return t, p, v
if i == 5:
return v, p, q

h = 0

class Ball:
def init(self, x, y, r, dx, dy, pen):
self.x = x
self.y = y
self.r = r
self.dx = dx
self.dy = dy
self.pen = pen

while True:

initialise shapes

balls = []
for i in range(0, 50):
    r = random.randint(0, 10) + 3
    balls.append(
        Ball(
            random.randint(r, r + (WIDTH - 2 * r)),
            random.randint(r, r + (HEIGHT - 2 * r)),
            r,
            (14 - r) / 2,
            (14 - r) / 2,
            display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
    )
)
    
BG = display.create_pen(40, 40, 40)

for i in range(0, 100): #set how long balls bounce for
    display.set_pen (BG) #background colour for balls
    display.clear()

    for ball in balls:
        ball.x += ball.dx
        ball.y += ball.dy

        xmax = WIDTH - ball.r
        xmin = ball.r
        ymax = HEIGHT - ball.r
        ymin = ball.r

        if ball.x < xmin or ball.x > xmax:
            ball.dx *= -1

        if ball.y < ymin or ball.y > ymax:
            ball.dy *= -1

        display.set_pen(ball.pen)
        display.circle(int(ball.x), int(ball.y), int(ball.r))

    display.update()
    time.sleep(0.01)

for i in range(0, 300): #set how long Baloo displays for
    h += 1
    r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)]  # rainbow magic
    led.set_rgb(r, g, b)  # Set LED to a converted HSV value
    RAINBOW = display.create_pen(r, g, b)  # Set pen to a converted HSV value
    display.set_pen(RAINBOW)
    display.clear()           # Fill the screen with the colour
    display.set_pen(BLACK)  # Set pen to black
    display.text("Not displaying horizontal", 10, 10, 240, 3)  # Add some text
    display.update()          # Update the display
    time.sleep(1 / 500)

initialise shapes

balls = []
for i in range(0, 50):
    r = random.randint(0, 10) + 3
    balls.append(
        Ball(
            random.randint(r, r + (WIDTH - 2 * r)),
            random.randint(r, r + (HEIGHT - 2 * r)),
            r,
            (14 - r) / 2,
            (14 - r) / 2,
            display.create_pen(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
    )
)

for i in range(0, 50): #set how long balls bounce for
    display.set_pen (BG) #background colour for balls
    display.clear()

    for ball in balls:
        ball.x += ball.dx
        ball.y += ball.dy

        xmax = WIDTH - ball.r
        xmin = ball.r
        ymax = HEIGHT - ball.r
        ymin = ball.r

        if ball.x < xmin or ball.x > xmax:
            ball.dx *= -1

        if ball.y < ymin or ball.y > ymax:
            ball.dy *= -1

        display.set_pen(ball.pen)
        display.circle(int(ball.x), int(ball.y), int(ball.r))

    display.update()
    time.sleep(0.01)
for i in range(0, 300): #set how long Baloo displays for
    h += 1
    r, g, b = [int(255 * c) for c in hsv_to_rgb(h / 360.0, 1.0, 1.0)]  # rainbow magic
    led.set_rgb(r, g, b)  # Set LED to a converted HSV value
    RAINBOW = display.create_pen(r, g, b)  # Set pen to a converted HSV value
    display.set_pen(RAINBOW)
    display.clear()           # Fill the screen with the colour
    display.set_pen(BLACK)  # Set pen to black
    display.text("how do I ", 10, 20, 240, 5)  # Add some text
    display.text("get it horizontal?", 10, 90, 240, 7)
    display.update()          # Update the display
    time.sleep(1 / 500)

Any advice gratefully recieved. Thank you in advance.

Vortigern

You can add a sneaky rotate=90 (or 180, or 270).to the line when you set up your display to rotate it:

display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_RGB565, rotate=90)

You could also rotate the text if you don’t want to rotate the whole display - details in the picographics docs!

Thank you very much. That was the command I needed.